From 0f6732fae361e041898da3841232ca4d0a1245dd Mon Sep 17 00:00:00 2001 From: augusto-weiss Date: Thu, 10 Nov 2022 12:34:28 -0300 Subject: [PATCH] Revert "Merge PR #97 into 13.0" This reverts commit 79bb6e1d0447b59a391e8a567e1d933f1e4680cd, reversing changes made to e06dca7444caa59148876eb96dc7dee0eb180a72. --- product_pack/models/__init__.py | 1 - product_pack/models/product_pricelist.py | 29 ------------------------ product_pack/models/product_product.py | 19 +++++++++++++++- product_pack/models/product_template.py | 28 ----------------------- 4 files changed, 18 insertions(+), 59 deletions(-) delete mode 100644 product_pack/models/product_pricelist.py diff --git a/product_pack/models/__init__.py b/product_pack/models/__init__.py index de7efbe3..626eb1a8 100644 --- a/product_pack/models/__init__.py +++ b/product_pack/models/__init__.py @@ -1,6 +1,5 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import product_pack_line -from . import product_pricelist from . import product_product from . import product_template diff --git a/product_pack/models/product_pricelist.py b/product_pack/models/product_pricelist.py deleted file mode 100644 index ee72a6f9..00000000 --- a/product_pack/models/product_pricelist.py +++ /dev/null @@ -1,29 +0,0 @@ -# Copyright 2022 Tecnativa - Pedro M. Baeza -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import models - - -class ProductPricelist(models.Model): - _inherit = "product.pricelist" - - def _compute_price_rule(self, products_qty_partner, date=False, uom_id=False): - """Don't call super when dealing with detailed and non detailed packs, - as the computations done after calling `price_compute` modify the final returned - price, so we compute it directly in these cases. - """ - products_qty_partner_super = [ - (s[0], s[1], s[2]) - for s in products_qty_partner - if not s[0] in s[0].split_pack_products()[0] - ] - res = super()._compute_price_rule( - products_qty_partner_super, date=date, uom_id=uom_id - ) - for product, _, _ in products_qty_partner: - if product in product.split_pack_products()[0]: - res[product.id] = ( - product.price_compute("list_price")[product.id], - False, - ) - return res diff --git a/product_pack/models/product_product.py b/product_pack/models/product_product.py index 5e64ec9d..cd3f29a5 100644 --- a/product_pack/models/product_product.py +++ b/product_pack/models/product_product.py @@ -27,7 +27,24 @@ def get_pack_lines(self): return self.mapped("pack_line_ids") def split_pack_products(self): - packs = self.filtered(lambda p: p.product_tmpl_id._is_pack_to_be_handled()) + """Split products and the pack in 2 separate recordsets. + + :return: [packs, no_packs] + """ + packs = self.filtered( + lambda p: p.pack_ok + and ( + (p.pack_type == "detailed" and p.pack_component_price == "totalized") + or p.pack_type == "non_detailed" + ) + ) + # We could need to check the price of the whole pack (e.g.: e-commerce) + if self.env.context.get("whole_pack_price"): + packs |= self.filtered( + lambda p: p.pack_ok + and p.pack_type == "detailed" + and p.pack_component_price == "detailed" + ) return packs, (self - packs) def price_compute(self, price_type, uom=False, currency=False, company=False): diff --git a/product_pack/models/product_template.py b/product_pack/models/product_template.py index cc134d9f..5de6eec7 100644 --- a/product_pack/models/product_template.py +++ b/product_pack/models/product_template.py @@ -80,31 +80,3 @@ def write(self, vals): self.product_variant_ids.write({"pack_line_ids": vals.get("pack_line_ids")}) _vals.pop("pack_line_ids") return super().write(_vals) - - def _is_pack_to_be_handled(self): - """Method for getting if a template is a computable pack. - - :return: True or False. - """ - self.ensure_one() - is_pack = False - if self.env.context.get("whole_pack_price"): - # We could need to check the price of the whole pack (e.g.: e-commerce) - is_pack = ( - self.pack_ok - and self.pack_type == "detailed" - and self.pack_component_price == "detailed" - ) - is_pack |= self.pack_ok and ( - (self.pack_type == "detailed" and self.pack_component_price == "totalized") - or self.pack_type == "non_detailed" - ) - return is_pack - - def split_pack_products(self): - """Split products and the pack in 2 separate recordsets. - - :return: [packs, no_packs] - """ - packs = self.filtered(lambda p: p._is_pack_to_be_handled()) - return packs, (self - packs)