11 changed files with 193 additions and 267 deletions
@ -1,5 +1,5 @@ |
|||||
## Module <service_charges_pos> |
## Module <service_charges_pos> |
||||
#### 18.01.2024 |
#### 02.11.2024 |
||||
#### Version 17.0.1.0.0 |
#### Version 17.0.1.0.1 |
||||
#### ADD |
#### FIX |
||||
- Initial commit for Service Charges POS |
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 */ |
/** @odoo-module **/ |
||||
import { Component } from "@odoo/owl"; |
|
||||
import { useService } from "@web/core/utils/hooks"; |
import { _t } from "@web/core/l10n/translation"; |
||||
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen"; |
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen"; |
||||
import { usePos } from "@point_of_sale/app/store/pos_hook"; |
import { useService } from "@web/core/utils/hooks"; |
||||
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup"; |
|
||||
import { NumberPopup } from "@point_of_sale/app/utils/input_popups/number_popup"; |
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 { |
export class ServiceChargeButton extends Component { |
||||
static template = "service_charges_pos.ServiceChargeButton"; |
static template = "service_charges_pos.ServiceChargeButton"; |
||||
|
|
||||
setup() { |
setup() { |
||||
this.pos = usePos(); |
this.pos = usePos(); |
||||
this.popup = useService("popup"); |
this.popup = useService("popup"); |
||||
} |
} |
||||
|
|
||||
async click() { |
async click() { |
||||
// To show number pop up and service charge applying functions based on conditions.
|
var self = this; |
||||
let res_config_settings = this.pos.res_config_settings[this.pos.res_config_settings.length -1] |
const { confirmed, payload } = await this.popup.add(NumberPopup, { |
||||
var global_selection = res_config_settings.global_selection |
title: _t("Service Charge"), |
||||
var global_charge = res_config_settings.global_charge |
startingValue: this.pos.config.service_charge, |
||||
var visibility = res_config_settings.visibility |
isInputSelected: true, |
||||
var global_product = res_config_settings.global_product_id[0] |
}); |
||||
var order = this.pos.get_order(); |
if (confirmed) { |
||||
var lines = order.get_orderlines(); |
const val = Math.max(0, Math.min(100, parseFloat(payload))); |
||||
if (visibility == 'global') { |
if (val > 0) { |
||||
var product = this.pos.db.get_product_by_id(global_product) |
await self.apply_service_charge(val); |
||||
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)); |
|
||||
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 |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
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'." |
||||
|
), |
||||
|
}); |
||||
|
return; |
||||
|
} |
||||
|
// 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 { |
} else { |
||||
var type = this.pos.config.charge_type |
var sc_price = order.get_total_with_tax() * val / 100 |
||||
var 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'."), |
|
||||
}); |
|
||||
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 |
|
||||
}); |
|
||||
} else { |
|
||||
var total_amount = order.get_total_with_tax() |
|
||||
var per_amount = payload / 100 * total_amount |
|
||||
order.add_product(product, { |
|
||||
price: per_amount |
|
||||
}); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
|
order.add_product(product, { |
||||
|
price: sc_price, |
||||
|
tax_ids: [] |
||||
|
}); |
||||
} |
} |
||||
|
|
||||
} |
} |
||||
|
|
||||
ProductScreen.addControlButton({ |
ProductScreen.addControlButton({ |
||||
component: ServiceChargeButton, |
component: ServiceChargeButton, |
||||
condition: function () { |
condition: function () { |
||||
let res_config_settings = this.pos.config.is_service_charges |
const { is_service_charges, service_product_id } = this.pos.config; |
||||
if (res_config_settings) { |
return is_service_charges && service_product_id; |
||||
return this.pos.config.is_service_charges |
|
||||
} else { |
|
||||
return false |
|
||||
} |
|
||||
}, |
}, |
||||
}); |
}); |
||||
|
@ -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