diff --git a/pos_discount_all/README.rst b/pos_discount_all/README.rst index 247157c4a4..9298fae57c 100644 --- a/pos_discount_all/README.rst +++ b/pos_discount_all/README.rst @@ -127,6 +127,9 @@ Contributors ------------ - Sylvain LE GAL (https://twitter.com/legalsylvain) +- `APSL-Nagarro `__: + + - Antoni Marroig Other credits ------------- diff --git a/pos_discount_all/__manifest__.py b/pos_discount_all/__manifest__.py index 1885dabf5e..55abecd1b6 100644 --- a/pos_discount_all/__manifest__.py +++ b/pos_discount_all/__manifest__.py @@ -6,7 +6,7 @@ "name": "Point of Sale - Display All Discounts", "summary": "Display discount amount on PoS cashier screen and print it on ticket" "calculated from the difference between a sale with default pricelist", - "version": "16.0.1.0.1", + "version": "17.0.1.0.0", "category": "Point of Sale", "maintainers": ["legalsylvain"], "author": "GRAP,Odoo Community Association (OCA)", @@ -17,13 +17,12 @@ "views/view_product_template.xml", ], "assets": { - "point_of_sale.assets": [ - "pos_discount_all/static/src/js/models.js", - "pos_discount_all/static/src/xml/OrderSummary.xml", + "point_of_sale._assets_pos": [ + "pos_discount_all/static/src/**/*", ], - "web.assets_tests": [ + "web.assets_backend": [ "pos_discount_all/tests/tours/PosDiscountAllTour.tour.js", - ], + ] }, "demo": [ "demo/product_product.xml", diff --git a/pos_discount_all/readme/CONTRIBUTORS.md b/pos_discount_all/readme/CONTRIBUTORS.md index 18c1c87e0f..7d73f9395c 100644 --- a/pos_discount_all/readme/CONTRIBUTORS.md +++ b/pos_discount_all/readme/CONTRIBUTORS.md @@ -1 +1,4 @@ - Sylvain LE GAL () +- [APSL-Nagarro](): + - Antoni Marroig \<\> + \ No newline at end of file diff --git a/pos_discount_all/static/description/index.html b/pos_discount_all/static/description/index.html index 1c35fbc8d2..abca04941d 100644 --- a/pos_discount_all/static/description/index.html +++ b/pos_discount_all/static/description/index.html @@ -461,6 +461,10 @@

Authors

Contributors

diff --git a/pos_discount_all/static/src/js/models.esm.js b/pos_discount_all/static/src/js/models.esm.js new file mode 100644 index 0000000000..1adb5abfe2 --- /dev/null +++ b/pos_discount_all/static/src/js/models.esm.js @@ -0,0 +1,78 @@ +/** @odoo-module */ + +/* + Copyright (C) 2022-Today GRAP (http://www.grap.coop) + @author Sylvain LE GAL (https://twitter.com/legalsylvain) + Copyright 2024 (APSL-Nagarro) - Antoni Marroig + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ + +import {Order, Orderline} from "@point_of_sale/app/store/models"; +import {patch} from "@web/core/utils/patch"; +import {roundPrecision as round_pr} from "@web/core/utils/numbers"; + +patch(Order.prototype, { + _get_ignored_product_ids_total_discount() { + const productIds = super._get_ignored_product_ids_total_discount(...arguments); + for (const product in this.pos.db.product_by_id) { + if (product.is_discount) { + productIds.push(product.id); + } + } + return productIds; + }, + get_total_with_tax_without_any_discount() { + return round_pr( + this.orderlines.reduce(function (sum, orderLine) { + return sum + orderLine.get_total_without_any_discount().total_included; + }, 0), + this.pos.currency.rounding + ); + }, + get_discount_amount_with_tax_without_any_discount() { + return round_pr( + this.get_total_with_tax_without_any_discount() - this.get_total_with_tax(), + this.pos.currency.rounding + ); + }, + export_for_printing() { + var receipt = super.export_for_printing(...arguments); + receipt.total_discount = + this.get_discount_amount_with_tax_without_any_discount(); + return receipt; + }, +}); + +patch(Orderline.prototype, { + get_total_without_any_discount() { + var product = this.get_product(); + const ignored_product_ids = + this.order._get_ignored_product_ids_total_discount(); + if (ignored_product_ids.includes(product.id)) { + return { + total_excluded: 0.0, + total_included: 0.0, + }; + } + var price_unit_without_any_discount = product.get_price( + this.pos.default_pricelist, + this.get_quantity() + ); + var taxes_ids = this.tax_ids || product.taxes_id; + taxes_ids = taxes_ids.filter((t) => t in this.pos.taxes_by_id); + var product_taxes = this.pos.get_taxes_after_fp( + taxes_ids, + this.order.fiscal_position + ); + var all_taxes_without_any_discount = this.compute_all( + product_taxes, + price_unit_without_any_discount, + this.get_quantity(), + this.pos.currency.rounding + ); + return { + total_excluded: all_taxes_without_any_discount.total_excluded, + total_included: all_taxes_without_any_discount.total_included, + }; + }, +}); diff --git a/pos_discount_all/static/src/js/models.js b/pos_discount_all/static/src/js/models.js deleted file mode 100644 index 6f057eb3f3..0000000000 --- a/pos_discount_all/static/src/js/models.js +++ /dev/null @@ -1,101 +0,0 @@ -/* - Copyright (C) 2022-Today GRAP (http://www.grap.coop) - @author Sylvain LE GAL (https://twitter.com/legalsylvain) - License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -*/ - -odoo.define("pos_discount_all.models", function (require) { - "use strict"; - - const {Order, Orderline} = require("point_of_sale.models"); - const Registries = require("point_of_sale.Registries"); - const {round_precision: round_pr} = require("web.utils"); - - // eslint-disable-next-line no-shadow - const PosDiscountAllOrder = (Order) => - // eslint-disable-next-line no-shadow - class PosDiscountAllOrder extends Order { - // eslint-disable-line no-shadow - // @override - _get_ignored_product_ids_total_discount() { - const productIds = super._get_ignored_product_ids_total_discount( - ...arguments - ); - _.map(this.pos.db.product_by_id, function (product) { - if (product.is_discount) { - productIds.push(product.id); - } - }); - return productIds; - } - - get_total_with_tax_without_any_discount() { - return round_pr( - this.orderlines.reduce(function (sum, orderLine) { - return ( - sum + - orderLine.get_total_without_any_discount().total_included - ); - }, 0), - this.pos.currency.rounding - ); - } - - get_discount_amount_with_tax_without_any_discount() { - return round_pr( - this.get_total_with_tax_without_any_discount() - - this.get_total_with_tax(), - this.pos.currency.rounding - ); - } - - export_for_printing() { - var receipt = super.export_for_printing(...arguments); - receipt.total_discount = - this.get_discount_amount_with_tax_without_any_discount(); - return receipt; - } - }; - - Registries.Model.extend(Order, PosDiscountAllOrder); - - // eslint-disable-next-line no-shadow - const PosDiscountAllOrderLine = (Orderline) => - // eslint-disable-next-line no-shadow - class PosDiscountAllOrderLine extends Orderline { - // eslint-disable-line no-shadow - get_total_without_any_discount() { - var product = this.get_product(); - const ignored_product_ids = - this.order._get_ignored_product_ids_total_discount(); - if (ignored_product_ids.includes(product.id)) { - return { - total_excluded: 0.0, - total_included: 0.0, - }; - } - var price_unit_without_any_discount = product.get_price( - this.pos.default_pricelist, - this.get_quantity() - ); - var taxes_ids = this.tax_ids || product.taxes_id; - taxes_ids = _.filter(taxes_ids, (t) => t in this.pos.taxes_by_id); - var product_taxes = this.pos.get_taxes_after_fp( - taxes_ids, - this.order.fiscal_position - ); - var all_taxes_without_any_discount = this.compute_all( - product_taxes, - price_unit_without_any_discount, - this.get_quantity(), - this.pos.currency.rounding - ); - return { - total_excluded: all_taxes_without_any_discount.total_excluded, - total_included: all_taxes_without_any_discount.total_included, - }; - } - }; - - Registries.Model.extend(Orderline, PosDiscountAllOrderLine); -}); diff --git a/pos_discount_all/static/src/js/order_widget.esm.js b/pos_discount_all/static/src/js/order_widget.esm.js new file mode 100644 index 0000000000..729bcf9f76 --- /dev/null +++ b/pos_discount_all/static/src/js/order_widget.esm.js @@ -0,0 +1,19 @@ +/** @odoo-module */ + +/* + Copyright (C) 2022-Today GRAP (http://www.grap.coop) + @author Sylvain LE GAL (https://twitter.com/legalsylvain) + Copyright 2024 (APSL-Nagarro) - Antoni Marroig + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ + +import {OrderWidget} from "@point_of_sale/app/generic_components/order_widget/order_widget"; +import {patch} from "@web/core/utils/patch"; +import {usePos} from "@point_of_sale/app/store/pos_hook"; + +patch(OrderWidget.prototype, { + setup() { + super.setup(); + this.props.pos = usePos(); + }, +}); diff --git a/pos_discount_all/static/src/xml/OrderSummary.xml b/pos_discount_all/static/src/xml/order_widget.xml similarity index 63% rename from pos_discount_all/static/src/xml/OrderSummary.xml rename to pos_discount_all/static/src/xml/order_widget.xml index f9b5570a13..2f55aee54d 100644 --- a/pos_discount_all/static/src/xml/OrderSummary.xml +++ b/pos_discount_all/static/src/xml/order_widget.xml @@ -2,25 +2,25 @@ - +
Discount Amount: - +
diff --git a/pos_discount_all/tests/tours/PosDiscountAllTour.tour.js b/pos_discount_all/tests/tours/PosDiscountAllTour.tour.js index 25c6ee6cd7..9d5ee072b0 100644 --- a/pos_discount_all/tests/tours/PosDiscountAllTour.tour.js +++ b/pos_discount_all/tests/tours/PosDiscountAllTour.tour.js @@ -1,15 +1,17 @@ +/** @odoo-module */ + /* Copyright (C) 2022-Today GRAP (http://www.grap.coop) @author Sylvain LE GAL (https://twitter.com/legalsylvain) License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html */ -/* eslint-disable no-empty-function */ -odoo.define("pos_discount_all.tour.PosDiscountAllTour", function (require) { - "use strict"; - const Tour = require("web_tour.tour"); +import {registry} from "@web/core/registry"; - var steps = [ +registry.category("web_tour.tours").add("PosDiscountAllTour", { + test: true, + url: "/pos/ui", + steps: () => [ { content: "Test pos_discount_all: Waiting for loading to finish", trigger: "body:not(:has(.loader))", @@ -70,9 +72,5 @@ odoo.define("pos_discount_all.tour.PosDiscountAllTour", function (require) { trigger: ".header-button", run: () => {}, }, - ]; - - Tour.register("PosDiscountAllTour", {test: true, url: "/pos/ui"}, steps); + ], }); - -/* */