Odoo 8:浏览在 install/upgrade 上运行的方法中的另一个模块
Odoo 8: Browse another module in method that runs on install/upgrade
我写了一个模块,它需要在 installed/upgraded 时进行初始数据填充。方法 (_initialize_history_prices
) 成功启动,但 current_price_records
似乎没有任何值,因此它什么也不做(table 有数千条记录)。当它是 运行 时,我没有看到任何错误。我做错了什么,或者在模块 install/upgrade 期间无法浏览其他模块,我应该求助于 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',
],
在_initialize_history_prices()方法中,在current_price_records中你会得到pricelist.partnerinfo的空记录集,因为没有id的browse()将return空记录集,所以当此方法将调用什么都不会发生
要获取所有记录,您可以使用 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
我写了一个模块,它需要在 installed/upgraded 时进行初始数据填充。方法 (_initialize_history_prices
) 成功启动,但 current_price_records
似乎没有任何值,因此它什么也不做(table 有数千条记录)。当它是 运行 时,我没有看到任何错误。我做错了什么,或者在模块 install/upgrade 期间无法浏览其他模块,我应该求助于 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',
],
在_initialize_history_prices()方法中,在current_price_records中你会得到pricelist.partnerinfo的空记录集,因为没有id的browse()将return空记录集,所以当此方法将调用什么都不会发生
要获取所有记录,您可以使用 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