From 45d980a359ff4d1590ca24ba58c9d2ea23001eb7 Mon Sep 17 00:00:00 2001 From: hkpatel Date: Thu, 29 Jul 2021 11:49:53 +0530 Subject: [PATCH] [IMP] pos_fixed_discount: Migration to 14.0" --- pos_fixed_discount/__manifest__.py | 2 +- pos_fixed_discount/readme/CONTRIBUTORS.rst | 1 + pos_fixed_discount/static/src/js/discount.js | 78 +++++++++++-------- .../static/src/xml/discount_templates.xml | 24 +++--- 4 files changed, 62 insertions(+), 43 deletions(-) diff --git a/pos_fixed_discount/__manifest__.py b/pos_fixed_discount/__manifest__.py index f2b133fc6d..d338742d42 100644 --- a/pos_fixed_discount/__manifest__.py +++ b/pos_fixed_discount/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Point of Sale Fixed Discounts", "summary": "Allow to apply discounts with fixed amount", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "development_status": "Beta", "category": "Point of Sale", "website": "https://github.com/OCA/pos", diff --git a/pos_fixed_discount/readme/CONTRIBUTORS.rst b/pos_fixed_discount/readme/CONTRIBUTORS.rst index 67cbd0f014..0b753a94c6 100644 --- a/pos_fixed_discount/readme/CONTRIBUTORS.rst +++ b/pos_fixed_discount/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Lorenzo Battistini - https://takobi.online * Foram Shah + * Helly kapatel diff --git a/pos_fixed_discount/static/src/js/discount.js b/pos_fixed_discount/static/src/js/discount.js index 29e338c70e..663371b482 100644 --- a/pos_fixed_discount/static/src/js/discount.js +++ b/pos_fixed_discount/static/src/js/discount.js @@ -1,33 +1,38 @@ -odoo.define("pos_fixed_discount.pos_fixed_discount", function (require) { +odoo.define("pos_fixed_discount.FixedDiscountButton", function (require) { "use strict"; - var core = require("web.core"); - var screens = require("point_of_sale.screens"); + const PosComponent = require("point_of_sale.PosComponent"); + const ProductScreen = require("point_of_sale.ProductScreen"); + const {useListener} = require("web.custom_hooks"); + const Registries = require("point_of_sale.Registries"); - var _t = core._t; - - var FixedDiscountButton = screens.ActionButtonWidget.extend({ - template: "FixedDiscountButton", - button_click: function () { + class FixedDiscountButton extends PosComponent { + constructor() { + super(...arguments); + useListener("click", this.onClick); + } + async onClick() { var self = this; - this.gui.show_popup("number", { - title: _t("Discount Amount"), - value: 0, - confirm: function (val) { - self.apply_discount(val); - }, + const {confirmed, payload} = await this.showPopup("NumberPopup", { + title: this.env._t("Discount Amount"), + startingValue: 0, }); - }, - apply_discount: function (amount) { - var order = this.pos.get_order(); + if (confirmed) { + var val = Math.round(Math.max(0, Math.min(100, parseFloat(payload)))); + self.apply_discount(val); + } + } + + async apply_discount(amount) { + var order = this.env.pos.get_order(); var lines = order.get_orderlines(); - var product = this.pos.db.get_product_by_id( - this.pos.config.discount_product_id[0] + var product = this.env.pos.db.get_product_by_id( + this.env.pos.config.discount_product_id[0] ); if (product === undefined) { - this.gui.show_popup("error", { - title: _t("No discount product found"), - body: _t( + await this.showPopup("ErrorPopup", { + title: this.env._t("No discount product found"), + body: this.env._t( "The discount product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'." ), }); @@ -46,31 +51,38 @@ odoo.define("pos_fixed_discount.pos_fixed_discount", function (require) { // Add discount // We add the price as manually set to avoid recomputation when changing customer. - var discount = -amount.replace(",", "."); + if (product.taxes_id.length) { + var first_tax = this.env.pos.taxes_by_id[product.taxes_id[0]]; + if (first_tax.price_include) { + order.get_total_with_tax(); + } + } + var discount = -amount; if (discount < 0) { order.add_product(product, { price: discount, + lst_price: discount, extras: { price_manually_set: true, }, }); } - }, - }); + } + } + FixedDiscountButton.template = "FixedDiscountButton"; - screens.define_action_button({ - name: "fixed_discount", - widget: FixedDiscountButton, + ProductScreen.addControlButton({ + component: FixedDiscountButton, condition: function () { return ( - this.pos.config.module_pos_discount && - this.pos.config.discount_product_id + this.env.pos.config.module_pos_discount && + this.env.pos.config.discount_product_id ); }, }); - return { - FixedDiscountButton: FixedDiscountButton, - }; + Registries.Component.add(FixedDiscountButton); + + return FixedDiscountButton; }); diff --git a/pos_fixed_discount/static/src/xml/discount_templates.xml b/pos_fixed_discount/static/src/xml/discount_templates.xml index d29aa7700a..ebfb8984c5 100644 --- a/pos_fixed_discount/static/src/xml/discount_templates.xml +++ b/pos_fixed_discount/static/src/xml/discount_templates.xml @@ -1,15 +1,21 @@ - - -
- Discount (%) -
+ + + + + + Discount (%) + - -
- Discount (Amount) -
+ + + + + + Discount (Amount) + +