From e1e5ad9b36380d987f16452084a681db35ee74c0 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Wed, 18 Sep 2019 19:14:23 +0200 Subject: [PATCH] [IMP] possibility to overload product_pack --- product_pack/models/product_product.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/product_pack/models/product_product.py b/product_pack/models/product_product.py index 6cbabeee4683..5a430061db2e 100644 --- a/product_pack/models/product_product.py +++ b/product_pack/models/product_product.py @@ -20,6 +20,13 @@ class ProductProduct(models.Model): help='Packs where product is used.' ) + @api.multi + def get_pack_lines(self): + """Returns the content (lines) of the packs. + By default, return all the pack_line_ids, but that function + can be overloaded to introduce filtering function by date, etc...""" + return self.mapped('pack_line_ids') + @api.multi def split_pack_products(self): """Split products and the pack in 2 separate recordsets. @@ -37,7 +44,7 @@ def split_pack_products(self): packs |= self.filtered( lambda p: p.pack_ok and p.pack_type == 'components_price') - no_packs = (self | self.mapped('pack_line_ids.product_id')) - packs + no_packs = (self | self.get_pack_lines().mapped('product_id')) - packs return packs, no_packs @api.multi @@ -48,7 +55,7 @@ def price_compute(self, price_type, uom=False, currency=False, price_type, uom, currency, company) for product in packs.with_context(prefetch_fields=False): pack_price = 0.0 - for pack_line in product.pack_line_ids: + for pack_line in product.get_pack_lines(): product_line_price = pack_line.product_id.price pack_price += (product_line_price * pack_line.quantity) prices[product.id] = pack_price