From 36c6edf4bc1aba8a829e91aed40fd21b3c48dc17 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Wed, 7 Dec 2016 16:21:59 +0100 Subject: [PATCH] [FIX] product: fix company_id assignment on pricelist version & items creation Due to the following revision: 295b96c0b39959d053c3b74edd515879c873c722 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 --- addons/product/pricelist.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/addons/product/pricelist.py b/addons/product/pricelist.py index 4646bb0e517..cb554d049dc 100644 --- a/addons/product/pricelist.py +++ b/addons/product/pricelist.py @@ -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), }) }