我编写了一个模块,在安装/升级时需要初始数据填充。方法(_initialize_history_prices
)成功启动,但current_price_records
似乎没有任何值,因此它什么都不做(该表有数千条记录)。我看到它运行时没有错误。我正在做什么错误,或者在模块安装/升级期间是否无法浏览其他模块,我应该使用SQL?
以下是为简洁而截断不相关部分的代码
class pricelist_partnerinfo_history(models.Model):
_name = 'pricelist.partnerinfo.history'
@api.model
def _initialize_history_prices(self):
'''Add missing current prices in historical records.'''
current_price_records = self.env['pricelist.partnerinfo'].browse()
for rec in current_price_records:
# Do stuff
pricelist_history_init.xml
<?xml version="1.0"?>
<openerp>
<data>
<!-- Initialize price list history records with current prices if they are missing in history -->
<function model="pricelist.partnerinfo.history" name="_initialize_history_prices"/>
</data>
</openerp>
__的OpenERP __。PY
'depends': ['product', 'purchase_automation'],
'data': [
'pricelist_history_init.xml',
'pricelist_view.xml',
],
答案 0 :(得分:1)
获取所有记录,您可以使用search()方法
@api.model
def _initialize_history_prices(self):
'''Add missing current prices in historical records.'''
current_price_records = self.env['pricelist.partnerinfo'].search([])
for rec in current_price_records:
# Do stuff