Reputation: 941
I have written a module, which requires initial data population when it is installed/upgraded. The method (_initialize_history_prices
) fires up successfully, but current_price_records
does not seem to have any values, so it does nothing (the table has thousands of records). I see no errors while it is running. Is there something wrong I'm doing, or is it not possible to browse other modules during module install/upgrade and I should resort to SQL?
Here's the code with irrelevant parts truncated for brevity
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',
],
Upvotes: 1
Views: 142
Reputation: 14746
in _initialize_history_prices() method, in current_price_records you will get empty records set of pricelist.partnerinfo because browse() without ids will return empty recordset, so when this method will call nothing will happen
to get all records you can use search() method
@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
Upvotes: 1