-
-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] pos_fixed_discount: Migration to 14.0
- Loading branch information
1 parent
6d8e563
commit 61d28e3
Showing
5 changed files
with
102 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |