From 52b87b694833dcfffb75b736f5d75c445e26880c Mon Sep 17 00:00:00 2001 From: Kamesh Patel Date: Wed, 23 Dec 2020 10:25:59 +0000 Subject: [PATCH] [IMP] product: Improve pricelist item form view Purpose of the task is to Improve the current pricelist line form view for clarity. SPECIFICATIONS: - Move the price computation on top and apply on at bottom. - Improve the formula view and calculate dynamic tips based on formula value. closes odoo/odoo#63733 Taskid: 2373068 Signed-off-by: Victor Feyens (vfe) --- addons/product/models/product_pricelist.py | 40 ++++- .../product/views/product_pricelist_views.xml | 148 +++++++++--------- 2 files changed, 110 insertions(+), 78 deletions(-) diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index d81dc058024..fdc6f5498fd 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -20,7 +20,7 @@ class Pricelist(models.Model): name = fields.Char('Pricelist Name', required=True, translate=True) active = fields.Boolean('Active', default=True, help="If unchecked, it will allow you to hide the pricelist without removing it.") item_ids = fields.One2many( - 'product.pricelist.item', 'pricelist_id', 'Pricelist Items', + 'product.pricelist.item', 'pricelist_id', 'Pricelist Rules', copy=True) currency_id = fields.Many2one('res.currency', 'Currency', default=_get_default_currency_id, required=True) company_id = fields.Many2one('res.company', 'Company') @@ -403,7 +403,9 @@ class PricelistItem(models.Model): price_surcharge = fields.Float( 'Price Surcharge', digits='Product Price', help='Specify the fixed amount to add or substract(if negative) to the amount calculated with the discount.') - price_discount = fields.Float('Price Discount', default=0, digits=(16, 2)) + price_discount = fields.Float( + 'Price Discount', default=0, digits=(16, 2), + help="You can apply a mark-up by setting a negative discount.") price_round = fields.Float( 'Price Rounding', digits='Product Price', help="Sets the price so that it is a multiple of this value.\n" @@ -429,10 +431,12 @@ class PricelistItem(models.Model): "The displayed value depends on the timezone set in your preferences.") compute_price = fields.Selection([ ('fixed', 'Fixed Price'), - ('percentage', 'Percentage (discount)'), + ('percentage', 'Discount'), ('formula', 'Formula')], index=True, default='fixed', required=True) fixed_price = fields.Float('Fixed Price', digits='Product Price') - percent_price = fields.Float('Percentage Price') + percent_price = fields.Float( + 'Percentage Price', + help="You can apply a mark-up by setting a negative discount.") # functional fields used for usability purposes name = fields.Char( 'Name', compute='_get_pricelist_item_name_price', @@ -440,6 +444,7 @@ class PricelistItem(models.Model): price = fields.Char( 'Price', compute='_get_pricelist_item_name_price', help="Explicit rule name for this pricelist line.") + rule_tip = fields.Char(compute='_compute_rule_tip') @api.constrains('base_pricelist_id', 'pricelist_id', 'base') def _check_recursion(self): @@ -497,6 +502,33 @@ class PricelistItem(models.Model): else: item.price = _("%(percentage)s %% discount and %(price)s surcharge", percentage=item.price_discount, price=item.price_surcharge) + @api.depends_context('lang') + @api.depends('compute_price', 'price_discount', 'price_surcharge', 'base', 'price_round') + def _compute_rule_tip(self): + base_selection_vals = {elem[0]: elem[1] for elem in self._fields['base']._description_selection(self.env)} + self.rule_tip = False + for item in self: + if item.compute_price != 'formula': + continue + base_amount = 100 + discount_factor = (100 - item.price_discount) / 100 + discounted_price = base_amount * discount_factor + if item.price_round: + discounted_price = tools.float_round(discounted_price, precision_rounding=item.price_round) + surcharge = tools.format_amount(item.env, item.price_surcharge, item.currency_id) + item.rule_tip = _( + "%(base)s with a %(discount)s %% discount and %(surcharge)s extra fee\n" + "Example: %(amount)s * %(discount_charge)s + %(price_surcharge)s → %(total_amount)s", + base=base_selection_vals[item.base], + discount=item.price_discount, + surcharge=surcharge, + amount=tools.format_amount(item.env, 100, item.currency_id), + discount_charge=discount_factor, + price_surcharge=surcharge, + total_amount=tools.format_amount( + item.env, discounted_price + item.price_surcharge, item.currency_id), + ) + @api.onchange('compute_price') def _onchange_compute_price(self): if self.compute_price != 'fixed': diff --git a/addons/product/views/product_pricelist_views.xml b/addons/product/views/product_pricelist_views.xml index b19577ef475..8af68f3125e 100644 --- a/addons/product/views/product_pricelist_views.xml +++ b/addons/product/views/product_pricelist_views.xml @@ -54,7 +54,7 @@ product.pricelist.item 100 - + @@ -91,79 +91,79 @@ product.pricelist.item.form product.pricelist.item -
+ -

- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

The computed price is expressed in the default Unit of Measure of the product.

-
- - + + + + + + + + + + + + + + + +
@@ -238,7 +238,7 @@ - + - +