Skip to content

Commit

Permalink
[MIG] pos_discount_all: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed Dec 20, 2024
1 parent 8c8fbcd commit 70fc6d4
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 114 deletions.
3 changes: 3 additions & 0 deletions pos_discount_all/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ Contributors
------------

- Sylvain LE GAL (https://twitter.com/legalsylvain)
- `APSL-Nagarro <https://apsl.tech>`__:

- Antoni Marroig <[email protected]>

Other credits
-------------
Expand Down
10 changes: 3 additions & 7 deletions pos_discount_all/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand All @@ -17,12 +17,8 @@
"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",
],
"web.assets_tests": [
"pos_discount_all/tests/tours/PosDiscountAllTour.tour.js",
"point_of_sale._assets_pos": [
"pos_discount_all/static/src/**/*",
],
},
"demo": [
Expand Down
3 changes: 3 additions & 0 deletions pos_discount_all/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
- Sylvain LE GAL (<https://twitter.com/legalsylvain>)
- [APSL-Nagarro](<https://apsl.tech>):
- Antoni Marroig \<<[email protected]>\>

4 changes: 4 additions & 0 deletions pos_discount_all/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li>Sylvain LE GAL (<a class="reference external" href="https://twitter.com/legalsylvain">https://twitter.com/legalsylvain</a>)</li>
<li><a class="reference external" href="https://apsl.tech">APSL-Nagarro</a>:<ul>
<li>Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="other-credits">
Expand Down
78 changes: 78 additions & 0 deletions pos_discount_all/static/src/js/models.esm.js
Original file line number Diff line number Diff line change
@@ -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,
};
},
});
101 changes: 0 additions & 101 deletions pos_discount_all/static/src/js/models.js

This file was deleted.

19 changes: 19 additions & 0 deletions pos_discount_all/static/src/js/order_widget.esm.js
Original file line number Diff line number Diff line change
@@ -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();
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
<!--
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 - See http://www.gnu.org/licenses/agpl-3.0.html
-->
<templates id="template" xml:space="preserve">

<t
t-name="OrderSummary"
t-inherit="point_of_sale.OrderSummary"
t-name="OrderWidget"
t-inherit="point_of_sale.OrderWidget"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//div[@t-if='_tax.hasTax']" position="after">
<xpath expr="//div[@t-if='props.tax']" position="after">
<t
t-set="_discount_amount"
t-value="props.order.get_discount_amount_with_tax_without_any_discount()"
t-value="props.pos?.get_order().get_discount_amount_with_tax_without_any_discount()"
/>
<div t-if="_discount_amount" class="subentry">
Discount Amount:
<span class="value discount-amount">
<t t-esc="env.pos.format_currency(_discount_amount)" />
<t t-esc="env.utils.formatCurrency(_discount_amount)" />
</span>
</div>
</xpath>
Expand Down

0 comments on commit 70fc6d4

Please sign in to comment.