diff --git a/beesdoo_product/__manifest__.py b/beesdoo_product/__manifest__.py index c98cf8ceb..971f14b65 100644 --- a/beesdoo_product/__manifest__.py +++ b/beesdoo_product/__manifest__.py @@ -2,6 +2,7 @@ # - Elouan Lebars # - Rémy Taymans # - Houssine BAKKALI +# - Manuel Claeys Bouuaert # - Elise Dupont # - Thibault François # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -13,7 +14,7 @@ "author": "Beescoop - Cellule IT, Coop IT Easy SCRLfs", "website": "https://github.com/beescoop/Obeesdoo", "category": "Sales", - "version": "12.0.1.0.0", + "version": "12.0.1.0.1", "depends": ["beesdoo_base", "product", "sale", "point_of_sale"], "data": [ "data/product_label.xml", @@ -21,6 +22,7 @@ "data/product_sequence.xml", "views/beesdoo_product.xml", "views/assets.xml", + "views/res_config_settings.xml", "wizard/views/label_printing_utils.xml", "security/ir.model.access.csv", ], diff --git a/beesdoo_product/models/__init__.py b/beesdoo_product/models/__init__.py index 0494b5ef9..b641813ab 100644 --- a/beesdoo_product/models/__init__.py +++ b/beesdoo_product/models/__init__.py @@ -1 +1,2 @@ from . import beesdoo_product +from . import res_config_settings diff --git a/beesdoo_product/models/beesdoo_product.py b/beesdoo_product/models/beesdoo_product.py index c8efda27b..4c467e330 100644 --- a/beesdoo_product/models/beesdoo_product.py +++ b/beesdoo_product/models/beesdoo_product.py @@ -12,6 +12,19 @@ _logger = logging.getLogger(__name__) +class ResPartner(models.Model): + _inherit = "res.partner" + + profit_margin = fields.Float(string="Product Margin [%]") + + @api.multi + @api.constrains("profit_margin") + def _check_margin(self): + for product in self: + if product.profit_margin < 0.0: + raise UserError(_("Percentages for Profit Margin must >= 0.")) + + class BeesdooProduct(models.Model): _inherit = "product.template" @@ -60,10 +73,15 @@ class BeesdooProduct(models.Model): note = fields.Text("Comments") - # S0023 : List_price = Price HTVA, so add a suggested price - list_price = fields.Float(string="exVAT Price") suggested_price = fields.Float( - string="Suggested exVAT Price", compute="_compute_cost", readOnly=True + string="Suggested Price", + compute="_compute_cost", + 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 + Margin' field in Product Categories (which has a default value). + """, ) deadline_for_sale = fields.Integer(string="Deadline for sale(days)") @@ -254,16 +272,45 @@ def _unit_same_category(self): ) @api.multi - @api.depends("seller_ids") + @api.depends("seller_ids", "supplier_taxes_id", "taxes_id") def _compute_cost(self): + suggested_price_reference = ( + self.env["ir.config_parameter"] + .sudo() + .get_param("beesdoo_product.suggested_price_reference") + ) for product in self: suppliers = product._get_main_supplier_info() if len(suppliers) > 0: + price = suppliers[0].price + supplier_taxes = product.supplier_taxes_id.filtered( + lambda t: t.amount_type == "percent" and t.price_include + ) + supplier_taxes_factor = 1 / ( + 1 + sum(supplier_taxes.mapped("amount")) / 100 + ) + sale_taxes = product.taxes_id.filtered( + lambda t: t.amount_type == "percent" and t.price_include + ) + sale_taxes_factor = 1 + sum(sale_taxes.mapped("amount")) / 100 + profit_margin_supplier = suppliers[0].name.profit_margin + profit_margin_product_category = suppliers[ + 0 + ].product_tmpl_id.categ_id.profit_margin + profit_margin = ( + profit_margin_supplier or profit_margin_product_category + ) + profit_margin_factor = ( + 1 / (1 - profit_margin / 100) + if suggested_price_reference == "sale_price" + else (1 + profit_margin / 100) + ) product.suggested_price = ( - suppliers[0].price * product.uom_po_id.factor - ) * ( - 1 - + suppliers[0].product_tmpl_id.categ_id.profit_margin / 100 + price + * product.uom_po_id.factor + * supplier_taxes_factor + * sale_taxes_factor + * profit_margin_factor ) @@ -310,13 +357,13 @@ class BeesdooProductCategory(models.Model): def _check_margin(self): for product in self: if product.profit_margin < 0.0: - raise UserError(_("Percentages for Profit Margin must > 0.")) + raise UserError(_("Percentages for Profit Margin must >= 0.")) class BeesdooProductSupplierInfo(models.Model): _inherit = "product.supplierinfo" - price = fields.Float("exVAT Price") + price = fields.Float("Price") class BeesdooUOMCateg(models.Model): diff --git a/beesdoo_product/models/res_config_settings.py b/beesdoo_product/models/res_config_settings.py new file mode 100644 index 000000000..3e3d38375 --- /dev/null +++ b/beesdoo_product/models/res_config_settings.py @@ -0,0 +1,41 @@ +# Copyright 2019-2020 Elouan Le Bars +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + suggested_price_reference = fields.Selection( + selection=[ + ("supplier_price", "On Supplier Price"), + ("sale_price", "On Sale Price"), + ], + string="Suggested price reference for margin", + help=""" + Price on which the margin is applied when computing the suggested sale price. + - Margin on Supplier Price : Suggested sale price = supplier price * (1 + margin / 100) (default) + - Margin on Sale Price: Suggested sale price = supplier price * (1 / (1 - margin / 100)) + """, + default="supplier_price", + ) + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + select_type = self.env["ir.config_parameter"].sudo() + suggested_price_reference = select_type.get_param( + "beesdoo_product.suggested_price_reference" + ) + res.update({"suggested_price_reference": suggested_price_reference}) + return res + + @api.multi + def set_values(self): + super(ResConfigSettings, self).set_values() + select_type = self.env["ir.config_parameter"].sudo() + select_type.set_param( + "beesdoo_product.suggested_price_reference", + self.suggested_price_reference, + ) diff --git a/beesdoo_product/readme/DESCRIPTION.rst b/beesdoo_product/readme/DESCRIPTION.rst index 7c3cfa84c..5ce16b25e 100644 --- a/beesdoo_product/readme/DESCRIPTION.rst +++ b/beesdoo_product/readme/DESCRIPTION.rst @@ -1,2 +1,8 @@ Modification of product module for the needs of beescoop -- SOOO5 - Ajout de label bio/ethique/provenance +- SOOO5 - Adds the label bio/ethique/provenance +- Add a 'Suggested Price' field on products, and a 'Product Margin' field on Partners (Vendors) and Product Categories. The first margin is used if set, otherwise the second margin (which has a default value) is used. +- The reference price on which this margin is applied (supplier price or sale price) can be selected in the general settings. +- Also, sale and supplier taxes that are of type 'percentage' and that are marked as 'included in price' are taken into account when computing the suggested price. + +Please note that this model makes assumptions when computing the suggested price: +- It supposes that each product has only one supplier and that products coming from multiple suppliers occure as duplicated products with one supplier each. diff --git a/beesdoo_product/views/beesdoo_product.xml b/beesdoo_product/views/beesdoo_product.xml index f862c1134..8083cb1a4 100644 --- a/beesdoo_product/views/beesdoo_product.xml +++ b/beesdoo_product/views/beesdoo_product.xml @@ -164,6 +164,17 @@ + + res.partner.form + res.partner + + + + + + + + beesdoo.scale.category.list beesdoo.scale.category diff --git a/beesdoo_product/views/res_config_settings.xml b/beesdoo_product/views/res_config_settings.xml new file mode 100644 index 000000000..b89fcd8b6 --- /dev/null +++ b/beesdoo_product/views/res_config_settings.xml @@ -0,0 +1,31 @@ + + + + + res.config.settings.form + res.config.settings + + + +
+
+
+
+
+
+
+
+
+ +