From 7ac5ffa8aa189d501f0c1be090b8eb7b923e58ab Mon Sep 17 00:00:00 2001 From: Thibault Libioulle Date: Fri, 4 Feb 2022 10:38:29 +0100 Subject: [PATCH] [IMP] product: factorize contextual price This commit factorizes contextual price in order to ease further inheritance. task-2382027 --- addons/product/models/product_product.py | 10 +--------- addons/product/models/product_template.py | 4 ++-- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/addons/product/models/product_product.py b/addons/product/models/product_product.py index e179d64188b..029017f2d75 100644 --- a/addons/product/models/product_product.py +++ b/addons/product/models/product_product.py @@ -704,12 +704,4 @@ class ProductProduct(models.Model): def _get_contextual_price(self): self.ensure_one() - # YTI TODO: During website_sale cleaning, we should get rid of those crappy context thing - pricelist = self.product_tmpl_id._get_contextual_pricelist() - if not pricelist: - return 0.0 - - quantity = self.env.context.get('quantity', 1.0) - uom = self.env['uom.uom'].browse(self.env.context.get('uom')) - date = self.env.context.get('date') - return pricelist._get_product_price(self, quantity, uom=uom, date=date) + return self.product_tmpl_id._get_contextual_price(self) diff --git a/addons/product/models/product_template.py b/addons/product/models/product_template.py index 1d1678548dd..4ef3e88ee30 100644 --- a/addons/product/models/product_template.py +++ b/addons/product/models/product_template.py @@ -1273,7 +1273,7 @@ class ProductTemplate(models.Model): 'template': '/product/static/xls/product_template.xls' }] - def _get_contextual_price(self): + def _get_contextual_price(self, product=None): self.ensure_one() # YTI TODO: During website_sale cleaning, we should get rid of those crappy context thing pricelist = self._get_contextual_pricelist() @@ -1283,7 +1283,7 @@ class ProductTemplate(models.Model): quantity = self.env.context.get('quantity', 1.0) uom = self.env['uom.uom'].browse(self.env.context.get('uom')) date = self.env.context.get('date') - return pricelist._get_product_price(self, quantity, uom=uom, date=date) + return pricelist._get_product_price(product or self, quantity, uom=uom, date=date) def _get_contextual_pricelist(self): """ Get the contextual pricelist