From 7dcfefb7002c2af7b316aeafeac8cb32ec28c975 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Tue, 5 Mar 2024 17:18:44 +0100 Subject: [PATCH] [FIX] l10n_es_pos,point_of_sale: ask for customer if split payment Current behavior: When in a spanish PoS, every order needs to be invoiced. If no customer is specified, there is a default customer selected. But if the payment method is split, the default customer should not be selected. And the user should be asked for a customer. Steps to reproduce: - Install the l10n_es_pos module - Go to PoS and create a new order - Select a product and go to payment - Select split payment (Customer Account) - The default customer is selected, but you should be asked for a customer Note: To fix this we use the same behavior as in the base PoS, where the user is asked for a customer if the payment method is split. If no user is selected after being asked for a customer, the default customer is selected. If a user is selected, the user is sent back to the payment screen, as it's done in the base PoS. opw-3736293 closes odoo/odoo#156570 Signed-off-by: Vlad Stroia (vlst) --- .../payment_screen/payment_screen.js | 7 +++-- .../static/tests/tours/spanish_pos_tour.js | 11 ++++++++ addons/l10n_es_pos/tests/test_frontend.py | 6 +++++ .../screens/payment_screen/payment_screen.js | 27 ++++++++++++------- 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/addons/l10n_es_pos/static/src/overrides/components/payment_screen/payment_screen.js b/addons/l10n_es_pos/static/src/overrides/components/payment_screen/payment_screen.js index 1ffa8be745c..b557ddbe3f0 100644 --- a/addons/l10n_es_pos/static/src/overrides/components/payment_screen/payment_screen.js +++ b/addons/l10n_es_pos/static/src/overrides/components/payment_screen/payment_screen.js @@ -2,7 +2,7 @@ import { _t } from "@web/core/l10n/translation"; import {patch} from "@web/core/utils/patch"; import {ErrorPopup} from "@point_of_sale/app/errors/popups/error_popup"; -import {PaymentScreen} from "@point_of_sale/app/screens/payment_screen/payment_screen"; +import { PaymentScreen } from "@point_of_sale/app/screens/payment_screen/payment_screen"; patch(PaymentScreen.prototype, { async validateOrder(isForceValidate) { @@ -18,7 +18,10 @@ patch(PaymentScreen.prototype, { } if (order.is_l10n_es_simplified_invoice) { order.to_invoice = Boolean(this.pos.config.l10n_es_simplified_invoice_journal_id) - order.partner = this.pos.db.partner_by_id[this.pos.config.simplified_partner_id[0]]; + if (await this._askForCustomerIfRequired() === false) { + return false; + } + order.partner = order.partner || this.pos.db.partner_by_id[this.pos.config.simplified_partner_id[0]]; } } return await super.validateOrder(...arguments); diff --git a/addons/l10n_es_pos/static/tests/tours/spanish_pos_tour.js b/addons/l10n_es_pos/static/tests/tours/spanish_pos_tour.js index be5dc08fc27..c90d08d75a3 100644 --- a/addons/l10n_es_pos/static/tests/tours/spanish_pos_tour.js +++ b/addons/l10n_es_pos/static/tests/tours/spanish_pos_tour.js @@ -52,5 +52,16 @@ registry.category("web_tour.tours").add("spanish_pos_tour", { ...ProductScreen.addOrderline("Desk Pad", "1"), ...pay(), ...checkSimplifiedInvoiceNumber("0003"), + + ...ReceiptScreen.clickNextOrder(), + ...ProductScreen.addOrderline("Desk Pad", "1"), + ...ProductScreen.clickPayButton(), + ...PaymentScreen.clickPaymentMethod("Customer Account"), + ...PaymentScreen.clickValidate(), + { + content: "verify that the pos requires the selection of a partner", + trigger: `div.popup.popup-confirm .modal-header:contains('Customer Required')`, + }, + ], }); diff --git a/addons/l10n_es_pos/tests/test_frontend.py b/addons/l10n_es_pos/tests/test_frontend.py index 7e4309ce2ba..2285b3deac7 100644 --- a/addons/l10n_es_pos/tests/test_frontend.py +++ b/addons/l10n_es_pos/tests/test_frontend.py @@ -13,6 +13,12 @@ class TestUi(TestPointOfSaleHttpCommon): return cls.company_data["company"] def test_spanish_pos(self): + split_payment_method = self.env['pos.payment.method'].create({ + 'name': 'Customer Account', + 'split_transactions': True, + }) + self.main_pos_config.payment_method_ids = [(4, split_payment_method.id)] + simp = self.env['account.journal'].create({ 'name': 'Simplified Invoice Journal', 'type': 'sale', diff --git a/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js b/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js index f4c171503f6..51db5b39b66 100644 --- a/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js +++ b/addons/point_of_sale/static/src/app/screens/payment_screen/payment_screen.js @@ -407,17 +407,8 @@ export class PaymentScreen extends Component { return "/point_of_sale/static/src/img/card-bank.png"; } } - async _isOrderValid(isForceValidate) { - if (this.currentOrder.get_orderlines().length === 0 && this.currentOrder.is_to_invoice()) { - this.popup.add(ErrorPopup, { - title: _t("Empty Order"), - body: _t( - "There must be at least one product in your order before it can be validated and invoiced." - ), - }); - return false; - } + async _askForCustomerIfRequired() { const splitPayments = this.paymentLines.filter( (payment) => payment.payment_method.split_transactions ); @@ -432,6 +423,22 @@ export class PaymentScreen extends Component { } return false; } + } + + async _isOrderValid(isForceValidate) { + if (this.currentOrder.get_orderlines().length === 0 && this.currentOrder.is_to_invoice()) { + this.popup.add(ErrorPopup, { + title: _t("Empty Order"), + body: _t( + "There must be at least one product in your order before it can be validated and invoiced." + ), + }); + return false; + } + + if (await this._askForCustomerIfRequired() === false) { + return false; + } if ( (this.currentOrder.is_to_invoice() || this.currentOrder.getShippingDate()) &&