From 3b50358ba1982dab0ae52873fd7adf2817225156 Mon Sep 17 00:00:00 2001 From: nicomacr Date: Thu, 28 Jun 2018 11:23:59 -0300 Subject: [PATCH] [IMP] Adds funcionaly "by margin" that has the product_sale_price_by_margin module --- product_planned_price/README.rst | 8 +++- product_planned_price/__manifest__.py | 2 +- .../demo/product_product_demo.xml | 11 +++++ .../models/product_template.py | 41 +++++++++++++++---- .../views/product_template_views.xml | 6 +++ 5 files changed, 58 insertions(+), 10 deletions(-) diff --git a/product_planned_price/README.rst b/product_planned_price/README.rst index 0a6c96501..7f14c9b79 100644 --- a/product_planned_price/README.rst +++ b/product_planned_price/README.rst @@ -14,7 +14,10 @@ Product Planned Price ===================== -This module add a new field "Planned Price" to products that can be extended by other modules to calculte this prices based in different conditions. It also add a wizard to update "List Price" using "Planned Price" value. Optionally, you can activate a cron to run this update auomatically. +This module add a new field "Planned Price" to products that can be extended by other modules to calculte this prices based in different conditions. + +#. It also add a wizard to update "List Price" using "Planned Price" value. Optionally, you can activate a cron to run this update auomatically. +#. Also Extends Planned Price and allow to set prices based on Replenishment Cost with a fixed and/or percentage margin. Installation ============ @@ -29,13 +32,14 @@ Configuration To configure this module, you need to: #. Go to Pricelist/Pricelist Items/ config "Base" to "Computed List Price". +#. Go to any product template and define the method to compute the Planned Price. Usage ===== To use this module, you need to: -#. Go to Product Template and set the planned price +#. Go to Product Template and set the planned price "based on" to set by different methods to compute this price. .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot diff --git a/product_planned_price/__manifest__.py b/product_planned_price/__manifest__.py index 9cab450e8..90fd5aa75 100644 --- a/product_planned_price/__manifest__.py +++ b/product_planned_price/__manifest__.py @@ -28,7 +28,7 @@ 'images': [ ], 'depends': [ - 'product', + 'product_replenishment_cost', ], 'data': [ 'views/product_template_views.xml', diff --git a/product_planned_price/demo/product_product_demo.xml b/product_planned_price/demo/product_product_demo.xml index e47252d7c..da5f61948 100644 --- a/product_planned_price/demo/product_product_demo.xml +++ b/product_planned_price/demo/product_product_demo.xml @@ -8,4 +8,15 @@ manual service + + Computed by Margin Product + + 50 + + 60 + 50 + 10 + by_margin + service + diff --git a/product_planned_price/models/product_template.py b/product_planned_price/models/product_template.py index bdd8079e4..6b4e98a6f 100644 --- a/product_planned_price/models/product_template.py +++ b/product_planned_price/models/product_template.py @@ -24,11 +24,29 @@ class ProductTemplate(models.Model): 'other parameters.', ) list_price_type = fields.Selection([ - ('manual', 'Fixed value')], + ('manual', 'Fixed value'), + ('by_margin', 'By Margin') + ], string='Planned Price Type', # we make it optional # required=True, default='manual', + help="If the 'Fixed value' type is chosen, a fixed planned" + " price is defined. \n If the 'By margin' type is chosen, " + "the following formula will be taken into account for " + "the planned price: Replenishment cost * (1 + margin(%)) + surcharge.", + ) + sale_margin = fields.Float( + 'Planned Price Sale margin %', + digits=dp.get_precision('Discount'), + ) + sale_surcharge = fields.Float( + 'Planned Price Sale surcharge', + digits=dp.get_precision('Product Price') + ) + replenishment_cost_copy = fields.Float( + related='replenishment_cost' + # related='product_variant_ids.replenishment_cost' ) @api.model @@ -89,16 +107,25 @@ def _update_prices_from_planned(self): return True @api.depends( + 'sale_margin', + 'sale_surcharge', + 'replenishment_cost', 'list_price_type', 'computed_list_price_manual', ) def _compute_computed_list_price(self): - manual_recs = self.filtered( - lambda x: x.list_price_type == 'manual') - _logger.info('Get computed_list_price for %s "manual" products' % ( - len(manual_recs))) - for rec in manual_recs: - rec.update({'computed_list_price': rec.computed_list_price_manual}) + recs = self.filtered( + lambda x: x.list_price_type in ['manual', 'by_margin']) + _logger.info('Get computed_list_price for %s "manual" and "by_margin"' + ' products' % (len(recs))) + for rec in recs: + computed_list_price = rec.computed_list_price_manual\ + if rec.list_price_type == 'manual'\ + else rec.replenishment_cost * \ + (1 + rec.sale_margin / 100.0) + rec.sale_surcharge + rec.update({ + 'computed_list_price': computed_list_price, + }) @api.model def _price_get(self, products, ptype='list_price'): diff --git a/product_planned_price/views/product_template_views.xml b/product_planned_price/views/product_template_views.xml index e32ce1332..f229fa476 100644 --- a/product_planned_price/views/product_template_views.xml +++ b/product_planned_price/views/product_template_views.xml @@ -23,6 +23,12 @@ +