[FIX] product: fix company_id assignment on pricelist version & items creation

Due to the following revision:
295b96c0b3

The company on the version and items was not assigned
when creating a new pricelist version on an existing
pricelist.

They were if you changed the company of the pricelist,
thanks to the triggers added in the above revision,
but not when they have just been created in the pricelist.

These new triggers repairs this regression. It also handle
changing the `pricelist_id` of a version (this is doable through
the "Sales > Configuration > Pricelists > Pricelist Versions" menu).

Fixes #14631
This commit is contained in:
Denis Ledoux 2016-12-07 16:21:59 +01:00
parent 86718d98bd
commit 36c6edf4bc
1 changed files with 10 additions and 0 deletions

View File

@ -403,6 +403,7 @@ class product_pricelist_version(osv.osv):
'company_id': fields.related('pricelist_id','company_id',type='many2one',
readonly=True, relation='res.company', string='Company', store={
'product.pricelist': (_get_product_pricelist, ['company_id'], 20),
'product.pricelist.version': (lambda self, cr, uid, ids, c=None: ids, ['pricelist_id'], 20),
})
}
_defaults = {
@ -504,6 +505,13 @@ class product_pricelist_item(osv.osv):
result.add(item_id.id)
return list(result)
def _get_product_pricelist_version(self, cr, uid, ids, context=None):
result = set()
for version in self.pool['product.pricelist.version'].browse(cr, uid, ids, context=context):
for item_id in version.items_id:
result.add(item_id.id)
return list(result)
_columns = {
'name': fields.char('Rule Name', help="Explicit rule name for this pricelist line."),
'price_version_id': fields.many2one('product.pricelist.version', 'Price List Version', required=True, select=True, ondelete='cascade'),
@ -535,6 +543,8 @@ class product_pricelist_item(osv.osv):
'company_id': fields.related('price_version_id','company_id',type='many2one',
readonly=True, relation='res.company', string='Company', store={
'product.pricelist': (_get_product_pricelist, ['company_id'], 30),
'product.pricelist.version': (_get_product_pricelist_version, ['pricelist_id'], 30),
'product.pricelist.item': (lambda self, cr, uid, ids, c=None: ids, ['price_version_id'], 30),
})
}