11 changed files with 193 additions and 267 deletions
@ -1,5 +1,5 @@ |
|||
## Module <service_charges_pos> |
|||
#### 18.01.2024 |
|||
#### Version 17.0.1.0.0 |
|||
#### ADD |
|||
- Initial commit for Service Charges POS |
|||
#### 02.11.2024 |
|||
#### Version 17.0.1.0.1 |
|||
#### FIX |
|||
Bug fixes for Service Charges POS |
|||
|
@ -1,10 +0,0 @@ |
|||
/** @odoo-module */ |
|||
import { patch } from "@web/core/utils/patch"; |
|||
import { PosStore } from "@point_of_sale/app/store/pos_store"; |
|||
patch(PosStore.prototype, { |
|||
async _processData(loadedData) { |
|||
// To load data to pos session
|
|||
await super._processData(...arguments); |
|||
this.res_config_settings = loadedData["res.config.settings"]; |
|||
} |
|||
}); |
@ -1,100 +1,72 @@ |
|||
/** @odoo-module */ |
|||
import { Component } from "@odoo/owl"; |
|||
import { useService } from "@web/core/utils/hooks"; |
|||
/** @odoo-module **/ |
|||
|
|||
import { _t } from "@web/core/l10n/translation"; |
|||
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen"; |
|||
import { usePos } from "@point_of_sale/app/store/pos_hook"; |
|||
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup"; |
|||
import { useService } from "@web/core/utils/hooks"; |
|||
import { NumberPopup } from "@point_of_sale/app/utils/input_popups/number_popup"; |
|||
import { _t } from "@web/core/l10n/translation"; |
|||
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup"; |
|||
import { Component } from "@odoo/owl"; |
|||
import { usePos } from "@point_of_sale/app/store/pos_hook"; |
|||
import { parseFloat } from "@web/views/fields/parsers"; |
|||
|
|||
export class ServiceChargeButton extends Component { |
|||
static template = "service_charges_pos.ServiceChargeButton"; |
|||
|
|||
setup() { |
|||
this.pos = usePos(); |
|||
this.popup = useService("popup"); |
|||
} |
|||
|
|||
async click() { |
|||
// To show number pop up and service charge applying functions based on conditions.
|
|||
let res_config_settings = this.pos.res_config_settings[this.pos.res_config_settings.length -1] |
|||
var global_selection = res_config_settings.global_selection |
|||
var global_charge = res_config_settings.global_charge |
|||
var visibility = res_config_settings.visibility |
|||
var global_product = res_config_settings.global_product_id[0] |
|||
var order = this.pos.get_order(); |
|||
var lines = order.get_orderlines(); |
|||
if (visibility == 'global') { |
|||
var product = this.pos.db.get_product_by_id(global_product) |
|||
if (product === undefined) { |
|||
await this.popup.add(ErrorPopup, { |
|||
title: _t("No service product found"), |
|||
body: _t("The service product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'.") |
|||
}); |
|||
return |
|||
} |
|||
// Remove existing discounts
|
|||
lines.filter(line => line.get_product() === product).forEach(line => order.removeOrderline(line)); |
|||
var self = this; |
|||
const { confirmed, payload } = await this.popup.add(NumberPopup, { |
|||
title: _t('Service Charge'), |
|||
startingValue: parseInt(global_charge), |
|||
isInputSelected: true |
|||
}) |
|||
if (confirmed) { |
|||
if (payload > 0) { |
|||
if (global_selection == 'amount') { |
|||
order.add_product(product, { |
|||
price: payload |
|||
}); |
|||
} else { |
|||
var total_amount = order.get_total_with_tax() |
|||
var per_amount = payload / 100 * total_amount |
|||
order.add_product(product, { |
|||
price: per_amount |
|||
title: _t("Service Charge"), |
|||
startingValue: this.pos.config.service_charge, |
|||
isInputSelected: true, |
|||
}); |
|||
if (confirmed) { |
|||
const val = Math.max(0, Math.min(100, parseFloat(payload))); |
|||
if (val > 0) { |
|||
await self.apply_service_charge(val); |
|||
} |
|||
} |
|||
} |
|||
} else { |
|||
var type = this.pos.config.charge_type |
|||
var product = this.pos.db.get_product_by_id(this.pos.config.service_product_id[0]); |
|||
|
|||
async apply_service_charge(val) { |
|||
const order = this.pos.get_order(); |
|||
const lines = order.get_orderlines(); |
|||
const product = this.pos.db.get_product_by_id(this.pos.config.service_product_id[0]); |
|||
if (product === undefined) { |
|||
await this.popup.add(ErrorPopup, { |
|||
title: _t("No service product found"), |
|||
body: _t("The service product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'."), |
|||
body: _t( |
|||
"The service product seems misconfigured. Make sure it is flagged as 'Can be Sold' and 'Available in Point of Sale'." |
|||
), |
|||
}); |
|||
return; |
|||
} |
|||
lines.filter(line => line.get_product() === product).forEach(line => order.removeOrderline(line)); |
|||
const {confirmed, payload } = await this.popup.add(NumberPopup, { |
|||
title: _t('Service Charge'), |
|||
startingValue: this.pos.config.service_charge, |
|||
isInputSelected: true |
|||
}) |
|||
if (confirmed) { |
|||
if (payload > 0) { |
|||
if (type == 'amount') { |
|||
order.add_product(product, { |
|||
price: payload |
|||
}); |
|||
// Remove existing service charges
|
|||
lines |
|||
.filter((line) => line.get_product() === product) |
|||
.forEach((line) => order._unlinkOrderline(line)); |
|||
// Add service charge
|
|||
if (this.pos.config.service_charge_type == 'amount') { |
|||
var sc_price = val |
|||
} else { |
|||
var total_amount = order.get_total_with_tax() |
|||
var per_amount = payload / 100 * total_amount |
|||
var sc_price = order.get_total_with_tax() * val / 100 |
|||
} |
|||
order.add_product(product, { |
|||
price: per_amount |
|||
price: sc_price, |
|||
tax_ids: [] |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
ProductScreen.addControlButton({ |
|||
component: ServiceChargeButton, |
|||
condition: function () { |
|||
let res_config_settings = this.pos.config.is_service_charges |
|||
if (res_config_settings) { |
|||
return this.pos.config.is_service_charges |
|||
} else { |
|||
return false |
|||
} |
|||
const { is_service_charges, service_product_id } = this.pos.config; |
|||
return is_service_charges && service_product_id; |
|||
}, |
|||
}); |
|||
|
@ -1,10 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<templates id="template" xml:space="preserve"> |
|||
<!-- Pos button --> |
|||
<t t-name="service_charges_pos.ServiceChargeButton" owl="1"> |
|||
<button class="control-button btn btn-light rounded-0 fw-bolder" t-on-click="() => this.click()"> |
|||
<i class="fa fa-calculator" role="img" aria-label="Service Charge" title="Service Charge" /> |
|||
Service Charge |
|||
</button> |
|||
</t> |
|||
</templates> |
@ -0,0 +1,12 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<templates id="template" xml:space="preserve"> |
|||
|
|||
<t t-name="service_charges_pos.ServiceChargeButton"> |
|||
<span class="control-button btn btn-light rounded-0 fw-bolder" t-on-click="() => this.click()"> |
|||
<i class="fa fa-calculator"></i> |
|||
<span> </span> |
|||
<span>Service Charge</span> |
|||
</span> |
|||
</t> |
|||
|
|||
</templates> |
Loading…
Reference in new issue