From ed6a31c371e28b201381e207b65c8e918872d72a Mon Sep 17 00:00:00 2001 From: Victor Champonnois Date: Tue, 20 Sep 2022 14:26:23 +0200 Subject: [PATCH] [REF] search product_code -> product_main_seller --- beesdoo_product/models/beesdoo_product.py | 27 ------------------- .../models/product_template.py | 16 ++++++++--- product_main_supplier/readme/DESCRIPTION.rst | 5 +++- product_main_supplier/readme/ROADMAP.rst | 1 + product_main_supplier/tests/__init__.py | 1 + .../test_search_main_seller_product_code.py | 0 .../views/product_template_views.xml | 18 +++++++++++++ .../models/product_template.py | 4 +-- sale_suggested_price/tests/__init__.py | 1 - 9 files changed, 38 insertions(+), 35 deletions(-) create mode 100644 product_main_supplier/readme/ROADMAP.rst create mode 100644 product_main_supplier/tests/__init__.py rename {sale_suggested_price => product_main_supplier}/tests/test_search_main_seller_product_code.py (100%) create mode 100644 product_main_supplier/views/product_template_views.xml diff --git a/beesdoo_product/models/beesdoo_product.py b/beesdoo_product/models/beesdoo_product.py index 0925ce245..4cb227d07 100644 --- a/beesdoo_product/models/beesdoo_product.py +++ b/beesdoo_product/models/beesdoo_product.py @@ -49,21 +49,6 @@ class BeesdooProduct(models.Model): translate=True, ) - top_supplierinfo_id = fields.Many2one( - comodel_name="product.supplierinfo", - compute="_compute_main_seller_id", - store=True, - ) - main_seller_id = fields.Many2one( - string="Main Seller", - comodel_name="res.partner", - related="top_supplierinfo_id.name", - ) - main_seller_id_product_code = fields.Char( - string="Main Seller Product Code", - related="top_supplierinfo_id.product_code", - ) - display_unit = fields.Many2one("uom.uom") default_reference_unit = fields.Many2one("uom.uom") display_weight = fields.Float( @@ -164,18 +149,6 @@ def generate_barcode(self): _logger.info("barcode :", bc) self.barcode = bc - @api.multi - @api.depends("seller_ids", "seller_ids.date_start") - def _compute_main_seller_id(self): - for product in self: - # todo english code Calcule le vendeur associé qui a la date de - # début la plus récente et plus petite qu’aujourd’hui fixme - # could product.main_seller_id be used instead? it seems that - # “seller” and “supplier” are used interchangeably in this - # class. is this on purpose? - sellers_ids = product._get_main_supplier_info() - product.top_supplierinfo_id = sellers_ids and sellers_ids[0] or False - @api.multi @api.depends( "taxes_id", diff --git a/product_main_supplier/models/product_template.py b/product_main_supplier/models/product_template.py index 680a0242f..9f3158529 100644 --- a/product_main_supplier/models/product_template.py +++ b/product_main_supplier/models/product_template.py @@ -8,12 +8,20 @@ class ProductTemplate(models.Model): _inherit = "product.template" - main_seller_id = fields.Many2one( - "res.partner", - string="Main Seller", + top_supplierinfo_id = fields.Many2one( + comodel_name="product.supplierinfo", compute="_compute_main_seller_id", store=True, ) + main_seller_id = fields.Many2one( + string="Main Seller", + comodel_name="res.partner", + related="top_supplierinfo_id.name", + ) + main_seller_id_product_code = fields.Char( + string="Main Seller Product Code", + related="top_supplierinfo_id.product_code", + ) @api.multi @api.depends("seller_ids", "seller_ids.date_start") @@ -25,7 +33,7 @@ def _compute_main_seller_id(self): # “seller” and “supplier” are used interchangeably in this # class. is this on purpose? sellers_ids = product._get_main_supplier_info() - product.main_seller_id = sellers_ids and sellers_ids[0].name or False + product.top_supplierinfo_id = sellers_ids and sellers_ids[0] or False def _get_main_supplier_info(self): # fixme this function either returns a supplier or a collection. diff --git a/product_main_supplier/readme/DESCRIPTION.rst b/product_main_supplier/readme/DESCRIPTION.rst index a505d4775..470e0e253 100644 --- a/product_main_supplier/readme/DESCRIPTION.rst +++ b/product_main_supplier/readme/DESCRIPTION.rst @@ -1 +1,4 @@ -Add a main supplier +- Add a main supplier +- Allow searching a product given the product reference of the main + supplier (also known as the `product_code` of the `product.supplierinfo` + object). diff --git a/product_main_supplier/readme/ROADMAP.rst b/product_main_supplier/readme/ROADMAP.rst new file mode 100644 index 000000000..991d6f6b1 --- /dev/null +++ b/product_main_supplier/readme/ROADMAP.rst @@ -0,0 +1 @@ +Use either "seller" or "supplier", not both. diff --git a/product_main_supplier/tests/__init__.py b/product_main_supplier/tests/__init__.py new file mode 100644 index 000000000..e998abc32 --- /dev/null +++ b/product_main_supplier/tests/__init__.py @@ -0,0 +1 @@ +from . import test_search_main_seller_product_code diff --git a/sale_suggested_price/tests/test_search_main_seller_product_code.py b/product_main_supplier/tests/test_search_main_seller_product_code.py similarity index 100% rename from sale_suggested_price/tests/test_search_main_seller_product_code.py rename to product_main_supplier/tests/test_search_main_seller_product_code.py diff --git a/product_main_supplier/views/product_template_views.xml b/product_main_supplier/views/product_template_views.xml new file mode 100644 index 000000000..1abd75d32 --- /dev/null +++ b/product_main_supplier/views/product_template_views.xml @@ -0,0 +1,18 @@ + + + + product.template.main.seller.search + product.template + + + + + + + + + + diff --git a/sale_suggested_price/models/product_template.py b/sale_suggested_price/models/product_template.py index ca8110797..adfe01a01 100644 --- a/sale_suggested_price/models/product_template.py +++ b/sale_suggested_price/models/product_template.py @@ -13,7 +13,7 @@ class ProductTemplate(models.Model): suggested_price = fields.Float( string="Suggested Price", compute="_compute_suggested_price", - readOnly=True, + readonly=True, help=""" This field computes a suggested price based on the 'Product Margin' field on Partners (Vendors), if it's set, or otherwise on the 'Product @@ -43,7 +43,7 @@ def calculate_suggested_price(self, price=None): suggested_price_reference = ( self.env["ir.config_parameter"] .sudo() - .get_param("beesdoo_product.suggested_price_reference") + .get_param("sale_suggested_price.suggested_price_reference") ) supplier = self._get_main_supplier_info() if not supplier: diff --git a/sale_suggested_price/tests/__init__.py b/sale_suggested_price/tests/__init__.py index edea4ba9c..3b67f665b 100644 --- a/sale_suggested_price/tests/__init__.py +++ b/sale_suggested_price/tests/__init__.py @@ -1,2 +1 @@ -from . import test_search_main_seller_product_code from . import test_suggested_price