From ffd44c58f92a5bfee78a984da5b4d2bc6aa4e087 Mon Sep 17 00:00:00 2001 From: Archana Vaghasiya Date: Fri, 10 Feb 2023 09:45:50 +0000 Subject: [PATCH] [FIX] point_of_sale: index error when send receipt to customer in offline An IndexError "list index out of range" trace back that occurs in point_of_sale /RecieptScreen :async _sendReceiptToCustomer was caught by sentry. order_server_id is undefined because it is not properly sync with the server step to reproduce: 1. First of all start the session in point_of_sale to produce error we have to be in offline mode and generate product order. 2. Add customer, select a payment method and validate. 3. After validation send email to customer(failed to send mail. because we are in offline mode and order_server_id is undefined ) 4. Now get back to online mode and again send mail to customer 5. This time an IndexError 'list index out of range' is trace-backed. So if order_server_id is null then we throw error to user. sentry-3824163568 closes odoo/odoo#113017 X-original-commit: f7aa70bc0909bea04d6a5c251f966e03ffd44288 Signed-off-by: Trinh Jacky (trj) --- addons/point_of_sale/i18n/point_of_sale.pot | 10 ++++++++++ .../src/js/Screens/ReceiptScreen/ReceiptScreen.js | 12 ++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index 84fb06d9047..aaee7d12134 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -6552,6 +6552,13 @@ msgstr "" #. module: point_of_sale #. odoo-python +#. openerp-web +#: code:addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js:0 +#, python-format +msgid "This order is not yet synced to server. Make sure it is synced then try again." +msgstr "" + +#. module: point_of_sale #: code:addons/point_of_sale/models/pos_session.py:0 #, python-format msgid "" @@ -6687,6 +6694,9 @@ msgstr "" #: code:addons/point_of_sale/static/src/xml/Popups/CashMoveReceipt.xml:0 #, python-format msgid "VAT:" +#: code:addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js:0 +#, python-format +msgid "Unsynced order" msgstr "" #. module: point_of_sale diff --git a/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js b/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js index 6d68ce2b21e..672091990b8 100644 --- a/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/ReceiptScreen/ReceiptScreen.js @@ -4,10 +4,9 @@ import { Printer } from "@point_of_sale/js/printers"; import { is_email } from "web.utils"; import { useErrorHandlers } from "@point_of_sale/js/custom_hooks"; import { AbstractReceiptScreen } from "@point_of_sale/js/Misc/AbstractReceiptScreen"; +import { OfflineErrorPopup } from "@point_of_sale/js/Popups/OfflineErrorPopup"; import { registry } from "@web/core/registry"; - import { OrderReceipt } from "./OrderReceipt"; - import { onMounted, useRef, status } from "@odoo/owl"; import { usePos } from "@point_of_sale/app/pos_hook"; @@ -137,6 +136,15 @@ export class ReceiptScreen extends AbstractReceiptScreen { name: partner ? partner.name : this.orderUiState.inputEmail, }; const order_server_id = this.env.pos.validated_orders_name_server_id_map[orderName]; + if (!order_server_id) { + this.popup.add(OfflineErrorPopup, { + title: this.env._t("Unsynced order"), + body: this.env._t( + "This order is not yet synced to server. Make sure it is synced then try again." + ), + }); + return Promise.reject(); + } await this.rpc({ model: "pos.order", method: "action_receipt_to_customer",