From 088044811d636d39b80bc709214b9b11e7f9bbeb Mon Sep 17 00:00:00 2001 From: lejeune quentin Date: Fri, 27 Jul 2018 13:06:54 +0200 Subject: [PATCH] [IMP] point of sale : Show discount when option enabled on pricelist Many users are confused when using pricelists on the PoS : When they tick the box "Show discount" on the pricelist, it has no impact when the pricelist is applied on the PoS. They often report a ticket thinking it's a bug. It can be useful to show the discount on the PoS when applying a pricelist, when users benefit from a preferred price, the vendor often wants to show it to the customer. --- addons/point_of_sale/static/src/js/models.js | 15 ++++++++++++-- addons/point_of_sale/static/src/xml/pos.xml | 21 +++++++++++++++++++- addons/product/models/product_pricelist.py | 5 +++++ addons/sale/models/__init__.py | 1 - addons/sale/models/product_pricelist.py | 13 ------------ 5 files changed, 38 insertions(+), 17 deletions(-) delete mode 100644 addons/sale/models/product_pricelist.py diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 161d9d37df2..b79e7d17fd1 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -294,7 +294,7 @@ exports.PosModel = Backbone.Model.extend({ loaded: function(self, locations){ self.shop = locations[0]; }, },{ model: 'product.pricelist', - fields: ['name', 'display_name'], + fields: ['name', 'display_name', 'discount_policy'], domain: function(self) { return [['id', 'in', self.config.available_pricelist_ids]]; }, loaded: function(self, pricelists){ _.map(pricelists, function (pricelist) { pricelist.items = []; }); @@ -1306,6 +1306,9 @@ exports.Product = Backbone.Model.extend({ // because it would cause inconsistencies with the backend for // pricelist that have base == 'pricelist'. return price; + }, + get_discount_policy: function(pricelist){ + return pricelist.discount_policy; }, }); @@ -1780,6 +1783,12 @@ exports.Orderline = Backbone.Model.extend({ "taxDetails": taxdetail, }; }, + display_discount_policy: function(){ + return this.product.get_discount_policy(this.order.pricelist); + }, + get_list_price: function(){ + return this.product.list_price; + }, }); var OrderlineCollection = Backbone.Collection.extend({ @@ -2450,7 +2459,9 @@ exports.Order = Backbone.Model.extend({ }, get_total_discount: function() { return round_pr(this.orderlines.reduce((function(sum, orderLine) { - return sum + (orderLine.get_unit_price() * (orderLine.get_discount()/100) * orderLine.get_quantity()); + sum += (orderLine.get_unit_price() * (orderLine.get_discount()/100) * orderLine.get_quantity()); + sum += ((orderLine.get_list_price() - orderLine.get_unit_price()) * orderLine.get_quantity()); + return sum }), 0), this.pos.currency.rounding); }, get_total_tax: function() { diff --git a/addons/point_of_sale/static/src/xml/pos.xml b/addons/point_of_sale/static/src/xml/pos.xml index ff16cdfb60b..639aec299c5 100644 --- a/addons/point_of_sale/static/src/xml/pos.xml +++ b/addons/point_of_sale/static/src/xml/pos.xml @@ -1284,7 +1284,16 @@ at - + + + + + + + + + / @@ -1472,6 +1481,16 @@ + +
+ + + + -> + +
+
With a % discount diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py index 958d5823c50..345279708cc 100644 --- a/addons/product/models/product_pricelist.py +++ b/addons/product/models/product_pricelist.py @@ -37,6 +37,11 @@ class Pricelist(models.Model): country_group_ids = fields.Many2many('res.country.group', 'res_country_group_pricelist_rel', 'pricelist_id', 'res_country_group_id', string='Country Groups') + discount_policy = fields.Selection([ + ('with_discount', 'Discount included in the price'), + ('without_discount', 'Show public price & discount to the customer')], + default='with_discount') + @api.multi def name_get(self): return [(pricelist.id, '%s (%s)' % (pricelist.name, pricelist.currency_id.name)) for pricelist in self] diff --git a/addons/sale/models/__init__.py b/addons/sale/models/__init__.py index 1f6f027cba3..e2e2d1b5c66 100644 --- a/addons/sale/models/__init__.py +++ b/addons/sale/models/__init__.py @@ -3,7 +3,6 @@ from . import analytic from . import account_invoice -from . import product_pricelist from . import product_product from . import product_template from . import res_company diff --git a/addons/sale/models/product_pricelist.py b/addons/sale/models/product_pricelist.py deleted file mode 100644 index 36e84ba0fbd..00000000000 --- a/addons/sale/models/product_pricelist.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import fields, models - - -class ProductPricelist(models.Model): - _inherit = 'product.pricelist' - - discount_policy = fields.Selection([ - ('with_discount', 'Discount included in the price'), - ('without_discount', 'Show public price & discount to the customer')], - default='with_discount')