summaryrefslogtreecommitdiff
path: root/addons/pos_restaurant/static/src/js/Screens
diff options
context:
space:
mode:
authorJoseph Caburnay <jcb@odoo.com>2020-07-31 09:36:39 +0000
committerJoseph Caburnay <jcb@odoo.com>2020-08-12 09:17:34 +0000
commitb0107e9230da5cb5c90819e5bee3e9cd323816ee (patch)
tree110e65cd9a180fbf782a70c392b9378a1f662e89 /addons/pos_restaurant/static/src/js/Screens
parent96f7c5eda84d6b7a1eade31efb8c35aff4ce94c4 (diff)
[IMP] pos_restaurant,point_of_sale: set tip after payment
1. Introduce an option in restaurant config to allow setting tips after payment. 2. Tip form is shown in bills so the customers can choose/set their tips. 3. Validated orders are kept in TipScreen (access via TicketScreen) so that at the end of the day, the user/cashier can set the tips for each validated order. closes odoo/odoo#55488 Task-id: 2117029 Related: odoo/upgrade#1606 Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
Diffstat (limited to 'addons/pos_restaurant/static/src/js/Screens')
-rw-r--r--addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js4
-rw-r--r--addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js17
-rw-r--r--addons/pos_restaurant/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js12
-rw-r--r--addons/pos_restaurant/static/src/js/Screens/TipScreen.js80
4 files changed, 100 insertions, 13 deletions
diff --git a/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js b/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js
index 1bf06c838f5..1a4a1a2f14d 100644
--- a/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js
+++ b/addons/pos_restaurant/static/src/js/Screens/FloorScreen/FloorScreen.js
@@ -271,7 +271,9 @@ odoo.define('pos_restaurant.FloorScreen', function (require) {
.filter(
(o) =>
o.server_id === undefined &&
- (o.orderlines.length !== 0 || o.paymentlines.length !== 0)
+ (o.orderlines.length !== 0 || o.paymentlines.length !== 0) &&
+ // do not count the orders that are already finalized
+ !o.finalized
).length;
table_obj.order_count = table.orders + unsynced_orders;
});
diff --git a/addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js b/addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js
new file mode 100644
index 00000000000..f45d32ba6e2
--- /dev/null
+++ b/addons/pos_restaurant/static/src/js/Screens/PaymentScreen.js
@@ -0,0 +1,17 @@
+odoo.define('pos_restaurant.PosResPaymentScreen', function (require) {
+ 'use strict';
+
+ const PaymentScreen = require('point_of_sale.PaymentScreen');
+ const Registries = require('point_of_sale.Registries');
+
+ const PosResPaymentScreen = (PaymentScreen) =>
+ class extends PaymentScreen {
+ get nextScreen() {
+ return this.env.pos.config.set_tip_after_payment && !this.currentOrder.is_tipped ? 'TipScreen' : super.nextScreen;
+ }
+ };
+
+ Registries.Component.extend(PaymentScreen, PosResPaymentScreen);
+
+ return PosResPaymentScreen;
+});
diff --git a/addons/pos_restaurant/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js b/addons/pos_restaurant/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js
index 5909292e0db..689c3bf40ca 100644
--- a/addons/pos_restaurant/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js
+++ b/addons/pos_restaurant/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js
@@ -20,18 +20,6 @@ odoo.define('pos_restaurant.ReceiptScreen', function(require) {
return super.nextScreen;
}
}
- /**
- * If this order is synced to/from the server, then the draft needs to be deleted
- * after the order is paid and the receipt screen is exited via 'Next Order' button.
- * Thus, we set this order to be removed from server. Note that only the draft version
- * is deleted if we trace the algorithm.
- */
- orderDone() {
- if (this.env.pos.config.iface_floorplan) {
- this.env.pos.db.set_order_to_remove_from_server(this.currentOrder);
- }
- super.orderDone();
- }
};
Registries.Component.extend(ReceiptScreen, PosResReceiptScreen);
diff --git a/addons/pos_restaurant/static/src/js/Screens/TipScreen.js b/addons/pos_restaurant/static/src/js/Screens/TipScreen.js
new file mode 100644
index 00000000000..efbd83ea007
--- /dev/null
+++ b/addons/pos_restaurant/static/src/js/Screens/TipScreen.js
@@ -0,0 +1,80 @@
+odoo.define('pos_restaurant.TipScreen', function (require) {
+ 'use strict';
+
+ const Registries = require('point_of_sale.Registries');
+ const PosComponent = require('point_of_sale.PosComponent');
+ const { parse } = require('web.field_utils');
+ const { useState } = owl.hooks;
+
+ class TipScreen extends PosComponent {
+ constructor() {
+ super(...arguments);
+ this.state = useState({ inputCustomAmount: '' });
+ this._totalAmount = this.currentOrder.get_total_with_tax();
+ }
+ get totalAmount() {
+ return this._totalAmount;
+ }
+ get currentOrder() {
+ return this.env.pos.get_order();
+ }
+ get percentageTips() {
+ return [
+ { percentage: '15%', amount: 0.15 * this.totalAmount },
+ { percentage: '20%', amount: 0.2 * this.totalAmount },
+ { percentage: '25%', amount: 0.25 * this.totalAmount },
+ ];
+ }
+ async setTip(amount) {
+ const order = this.env.pos.get_order();
+ const serverId = this.env.pos.validated_orders_name_server_id_map[order.name];
+
+ if (!serverId) {
+ this.showPopup('ErrorPopup', {
+ title: 'Unsynced order',
+ body: 'This order is not yet synced to server. Make sure it is synced then try again.',
+ });
+ return;
+ }
+
+ // set the tip by temporarily allowing order modification
+ order.finalized = false;
+ order.set_tip(amount);
+ order.finalized = true;
+
+ // set_tip calls add_product which sets the new line as the selected_orderline
+ const tip_line = order.selected_orderline;
+ await this.rpc({
+ method: 'set_tip',
+ model: 'pos.order',
+ args: [serverId, tip_line.export_as_JSON()],
+ });
+ this.goNextScreen();
+ }
+ async tipCustomAmount() {
+ const tipAmount = parse.float(this.state.inputCustomAmount);
+ if (tipAmount > 0.25 * this._totalAmount) {
+ const { confirmed } = await this.showPopup('ConfirmPopup', {
+ title: 'Are you sure?',
+ body: `${this.env.pos.format_currency(
+ tipAmount
+ )} is more than 25% of the order's total amount. Are you sure of this tip amount?`,
+ });
+ if (!confirmed) return;
+ }
+ await this.setTip(tipAmount);
+ }
+ goNextScreen() {
+ this.env.pos.get_order().finalize();
+ this.showScreen(this.nextScreen);
+ }
+ get nextScreen() {
+ return 'FloorScreen';
+ }
+ }
+ TipScreen.template = 'pos_restaurant.TipScreen';
+
+ Registries.Component.add(TipScreen);
+
+ return TipScreen;
+});