Skip to content

Commit

Permalink
[MIG] pos_fixed_discount: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hkapatel-initos committed Aug 6, 2021
1 parent 6d8e563 commit 61d28e3
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 86 deletions.
2 changes: 1 addition & 1 deletion pos_fixed_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pos_fixed_discount/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
* Lorenzo Battistini - https://takobi.online
* Foram Shah <foram.shah@initos.com>
* Helly kapatel <helly.kapatel@initos.com>
85 changes: 85 additions & 0 deletions pos_fixed_discount/static/src/js/FixedDiscountButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
odoo.define("pos_fixed_discount.FixedDiscountButton", function (require) {
"use strict";

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");

class FixedDiscountButton extends PosComponent {
constructor() {
super(...arguments);
useListener("click", this.onClick);
}
async onClick() {
var self = this;
const {confirmed, payload} = await this.showPopup("NumberPopup", {
title: this.env._t("Discount Amount"),
startingValue: 0,
});
if (confirmed) {
var val = Math.round(Math.max(0, Math.min(100, parseFloat(payload))));
this.apply_discount(val);
}
}

async apply_discount(amount) {
var order = this.env.pos.get_order();
var lines = order.get_orderlines();
var product = this.env.pos.db.get_product_by_id(
this.env.pos.config.discount_product_id[0]
);
if (product === undefined) {
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'."
),
});
return;
}
// Remove existing discounts
for (const line of lines) {
if (line.get_product() === product) {
order.remove_orderline(line);
}
}


// Add discount
// We add the price as manually set to avoid recomputation when changing customer.
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";

ProductScreen.addControlButton({
component: FixedDiscountButton,
condition: function () {
return (
this.env.pos.config.module_pos_discount &&
this.env.pos.config.discount_product_id
);
},
});

Registries.Component.add(FixedDiscountButton);

return FixedDiscountButton;
});
76 changes: 0 additions & 76 deletions pos_fixed_discount/static/src/js/discount.js

This file was deleted.

24 changes: 15 additions & 9 deletions pos_fixed_discount/static/src/xml/discount_templates.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">
<t t-extend="DiscountButton">
<t t-jquery="div[class='control-button js_discount']" t-operation="replace">
<div class='control-button js_discount'>
<i class='fa fa-tag' /> Discount (%)
</div>
<t t-extend="pos_discount.DiscountButton">
<t t-jquery="span[class='control-button js_discount']" t-operation="replace">
<span class="control-button js_discount">
<i class="fa fa-tag" />
<span> </span>
<span>Discount (%)</span>
</span>
</t>
</t>
<t t-name="FixedDiscountButton">
<div class='control-button js_fixed_discount'>
<i class='fa fa-tag' /> Discount (Amount)
</div>

<t t-name="FixedDiscountButton" owl="1">
<span class="control-button js_fixed_discount">
<i class="fa fa-tag" />
<span> </span>
<span>Discount (Amount)</span>
</span>
</t>

</templates>

0 comments on commit 61d28e3

Please sign in to comment.