From 015fa77c4d433ab0c44710f74fb3a6c7cfeda7d1 Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 10 Oct 2024 18:20:39 +0200 Subject: [PATCH] set refund data --- fiscal_epos_print/__manifest__.py | 1 + .../js/ChromeWidgets/SetRefundInfoButton.js | 8 ++--- .../static/src/js/Popups/RefundInfoPopup.js | 11 ------ .../js/Screens/TicketScreen/TicketScreen.js | 20 +++++++++++ fiscal_epos_print/static/src/js/models.js | 34 +++++++++++++++++-- 5 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 fiscal_epos_print/static/src/js/Screens/TicketScreen/TicketScreen.js diff --git a/fiscal_epos_print/__manifest__.py b/fiscal_epos_print/__manifest__.py index c20a8337563..34002569649 100644 --- a/fiscal_epos_print/__manifest__.py +++ b/fiscal_epos_print/__manifest__.py @@ -55,6 +55,7 @@ "fiscal_epos_print/static/src/xml/ChromeWidgets/EpsonFP81IIComponent.xml", # "fiscal_epos_print/static/src/xml/ChromeWidgets/SetLotteryCodeButton.xml", "fiscal_epos_print/static/src/xml/ChromeWidgets/SetRefundInfoButton.xml", + "fiscal_epos_print/static/src/js/Screens/TicketScreen/TicketScreen.js", ], }, "installable": True, diff --git a/fiscal_epos_print/static/src/js/ChromeWidgets/SetRefundInfoButton.js b/fiscal_epos_print/static/src/js/ChromeWidgets/SetRefundInfoButton.js index 0eba44a3c5a..85bb6988f06 100644 --- a/fiscal_epos_print/static/src/js/ChromeWidgets/SetRefundInfoButton.js +++ b/fiscal_epos_print/static/src/js/ChromeWidgets/SetRefundInfoButton.js @@ -45,10 +45,10 @@ export class SetRefundInfoButton extends Component { // } await this.popup.add(RefundInfoPopup, { title: _t("Refund Information Details"), - // refund_date: yyyy + "-" + mm + "-" + dd, - // refund_report: current_order.refund_report, - // refund_doc_num: current_order.refund_doc_num, - // refund_cash_fiscal_serial: current_order.refund_cash_fiscal_serial, + refund_date: current_order.refund_date, + refund_report: current_order.refund_report, + refund_doc_num: current_order.refund_doc_num, + refund_cash_fiscal_serial: current_order.refund_cash_fiscal_serial, // refund_full_refund: current_order.refund_full_refund, }).then(async () => { this.update_refund_info_button(); diff --git a/fiscal_epos_print/static/src/js/Popups/RefundInfoPopup.js b/fiscal_epos_print/static/src/js/Popups/RefundInfoPopup.js index d5c5272a81d..3087daaf787 100644 --- a/fiscal_epos_print/static/src/js/Popups/RefundInfoPopup.js +++ b/fiscal_epos_print/static/src/js/Popups/RefundInfoPopup.js @@ -22,7 +22,6 @@ export class RefundInfoPopup extends AbstractAwaitablePopup { this.inputRefundDocNum = useRef("inputRefundDocNum"); this.inputRefundCashFiscalSerial = useRef("inputRefundCashFiscalSerial"); this.inputRefundFullRefund = useRef("inputRefundFullRefund"); - this.inputDatePicker = this.initializeDatePicker(); } clickConfirmRefund() { this.$el = $(this.el); @@ -70,14 +69,4 @@ export class RefundInfoPopup extends AbstractAwaitablePopup { this.$el.find("#error-message-dialog").show(); } } - initializeDatePicker() { - this.$el = $(this.el); - var element = this.$el.find("#refund_date").get(0); - if (element && !this.datepicker) { - // eslint-disable-next-line - this.datepicker = new Pikaday({ - field: element, - }); - } - } } \ No newline at end of file diff --git a/fiscal_epos_print/static/src/js/Screens/TicketScreen/TicketScreen.js b/fiscal_epos_print/static/src/js/Screens/TicketScreen/TicketScreen.js new file mode 100644 index 00000000000..2731ad0bb46 --- /dev/null +++ b/fiscal_epos_print/static/src/js/Screens/TicketScreen/TicketScreen.js @@ -0,0 +1,20 @@ +/** @odoo-module **/ + +import { TicketScreen } from "@point_of_sale/app/screens/ticket_screen/ticket_screen"; +import { _t } from "@web/core/l10n/translation"; +import { patch } from "@web/core/utils/patch"; + + +patch(TicketScreen.prototype, { + + async onDoRefund() { + const selected_order = this.getSelectedOrder();; + const res = super.onDoRefund(); + const new_order = this.pos.get_order(); + new_order.refund_report = selected_order.fiscal_z_rep_number; + new_order.refund_doc_num = selected_order.fiscal_receipt_number; + new_order.refund_date = selected_order.fiscal_receipt_date; + new_order.refund_cash_fiscal_serial = selected_order.fiscal_printer_serial; + return res; + }, +}); \ No newline at end of file diff --git a/fiscal_epos_print/static/src/js/models.js b/fiscal_epos_print/static/src/js/models.js index fb72fd73c7f..c5955e0e765 100644 --- a/fiscal_epos_print/static/src/js/models.js +++ b/fiscal_epos_print/static/src/js/models.js @@ -20,7 +20,6 @@ patch(PosStore.prototype, { patch(Order.prototype, { setup() { - super.setup(...arguments); this.lottery_code = null; this.refund_report = null; this.refund_date = null; @@ -32,9 +31,14 @@ patch(Order.prototype, { this.fiscal_receipt_amount = null; this.fiscal_receipt_date = null; this.fiscal_z_rep_number = null; - this.fiscal_printer_serial = this.pos.config.fiscal_printer_serial || null; this.fiscal_printer_debug_info = null; + super.setup(...arguments); + + if (!this.fiscal_printer_serial) { + this.fiscal_printer_serial = this.pos.config.fiscal_printer_serial || null; + } + try { if (this.pos.config.module_pos_hr) { this.fiscal_operator_number = this.pos.cashier.fiscal_operator_number || "1"; @@ -91,6 +95,32 @@ patch(Order.prototype, { return json; }, + init_from_JSON(json) { + var res = super.init_from_JSON(...arguments); + this.lottery_code = json.lottery_code; + this.refund_report = json.refund_report; + this.refund_date = json.refund_date; + this.refund_doc_num = json.refund_doc_num; + this.refund_cash_fiscal_serial = json.refund_cash_fiscal_serial; + this.check_order_has_refund(); + this.fiscal_receipt_number = json.fiscal_receipt_number; + this.fiscal_receipt_amount = json.fiscal_receipt_amount; + this.fiscal_receipt_date = json.fiscal_receipt_date; + this.fiscal_z_rep_number = json.fiscal_z_rep_number; + this.fiscal_printer_serial = json.fiscal_printer_serial; + this.fiscal_printer_debug_info = json.fiscal_printer_debug_info; + return res; + }, + + + check_order_has_refund() { + const order = this.pos.get_order(); + if (order) { + const lines = order.orderlines; + order.has_refund = lines.some(line => line.quantity < 0); + } + }, + getPrinterOptions() { var protocol = this.pos.config.use_https ? "https://" : "http://"; var printer_url =