From 3dc6c3a3d5f1c76edf7a3169293a100e1ecb628e Mon Sep 17 00:00:00 2001 From: AjmalCybro Date: Sat, 4 Jan 2025 13:19:14 +0530 Subject: [PATCH] Jan 04 [UPDT] : Updated 'pos_invoice_automate' --- pos_invoice_automate/__manifest__.py | 2 +- pos_invoice_automate/doc/RELEASE_NOTES.md | 5 + pos_invoice_automate/models/pos_config.py | 2 + pos_invoice_automate/models/pos_order.py | 1 + .../static/src/js/PaymentScreen.js | 203 +++++++++--------- 5 files changed, 116 insertions(+), 97 deletions(-) diff --git a/pos_invoice_automate/__manifest__.py b/pos_invoice_automate/__manifest__.py index a7ce2f74f..73d384a33 100755 --- a/pos_invoice_automate/__manifest__.py +++ b/pos_invoice_automate/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################# { 'name': 'POS Automate Invoice', - 'version': '16.0.1.0.0', + 'version': '16.0.1.0.1', 'summary': """To manage the POS Invoice Automatically""", 'description': """This module facilitates the automated sending of invoices to customers, along with the ability to schedule emails at specific diff --git a/pos_invoice_automate/doc/RELEASE_NOTES.md b/pos_invoice_automate/doc/RELEASE_NOTES.md index f012efa85..bdfa2d38e 100755 --- a/pos_invoice_automate/doc/RELEASE_NOTES.md +++ b/pos_invoice_automate/doc/RELEASE_NOTES.md @@ -8,3 +8,8 @@ #### Version 16.0.1.0.0 ##### Bug fixes - Resolved the issue while validating the order + +#### 1.1.2025 +#### Version 16.0.1.0.1 +##### Bug fixes +- Bug Fix diff --git a/pos_invoice_automate/models/pos_config.py b/pos_invoice_automate/models/pos_config.py index cc138c013..d760d5cca 100755 --- a/pos_invoice_automate/models/pos_config.py +++ b/pos_invoice_automate/models/pos_config.py @@ -47,6 +47,7 @@ class PosConfig(models.Model): def start_cron(self): """Start the cron scheduler""" + print("............start cron............") if self.interval >= 0: self.is_started = True self.is_stopped = False @@ -75,6 +76,7 @@ class PosConfig(models.Model): def _send_mail(self, config): """Send invoice by Email""" + print("sentmail.....................") point_of_sale = self.env['pos.config'].browse(config) for order in point_of_sale.session_ids.order_ids.filtered( lambda x: x.state == 'invoiced' and not x.is_send): diff --git a/pos_invoice_automate/models/pos_order.py b/pos_invoice_automate/models/pos_order.py index 7fafd0368..2d276e9e0 100755 --- a/pos_invoice_automate/models/pos_order.py +++ b/pos_invoice_automate/models/pos_order.py @@ -68,6 +68,7 @@ class PosOrder(models.Model): } def download_invoice(self): + print("mmmmmmmmmmmmmmmmmmm") if not self.account_move: self.action_pos_order_invoice() template = self.env.ref('pos_invoice_automate.send_mail_template') diff --git a/pos_invoice_automate/static/src/js/PaymentScreen.js b/pos_invoice_automate/static/src/js/PaymentScreen.js index ac6fee9af..ad39eabe1 100755 --- a/pos_invoice_automate/static/src/js/PaymentScreen.js +++ b/pos_invoice_automate/static/src/js/PaymentScreen.js @@ -16,10 +16,12 @@ odoo.define('pos_invoice_automate.PaymentScreen', function(require) { this.currentOrder.set_to_invoice(true); } } - async validateOrder(isForceValidate) { + async validateOrder(isForceValidate) { + try { + this.env.services.ui.block(); const value = await this.env.pos.push_single_order(this.currentOrder); - const config_id = this.env.pos.config.id - const order_id = value[0].id + const config_id = this.env.pos.config.id; + const order_id = value[0].id; if (this.env.pos.config.is_started) { await this.rpc({ model: 'pos.config', @@ -28,14 +30,13 @@ odoo.define('pos_invoice_automate.PaymentScreen', function(require) { }); } else { if (this.env.pos.config.button_operation == 'download') { - var self = this; await this.rpc({ model: 'pos.order', method: 'download_invoice', args: [order_id], - }).then(function(result) { - self.env.legacyActionManager.do_action(result) - }) + }).then((result) => { + this.env.legacyActionManager.do_action(result); + }); } else if (this.env.pos.config.button_operation == 'send') { await this.rpc({ model: 'pos.order', @@ -43,114 +44,124 @@ odoo.define('pos_invoice_automate.PaymentScreen', function(require) { args: [order_id], }); } else if (this.env.pos.config.button_operation == 'download_send_mail') { - var self = this; await this.rpc({ model: 'pos.order', method: 'send_mail_invoice', args: [order_id], - }).then(function(result) { - self.env.legacyActionManager.do_action(result) - }) + }).then((result) => { + this.env.legacyActionManager.do_action(result); + }); } } await super.validateOrder(isForceValidate); + } catch (error) { + console.error("Error during validation:", error); + this.showPopup('ErrorPopup', { + title: this.env._t('Validation Error'), + body: this.env._t('An error occurred while validating the order.'), + }); + } finally { + this.env.services.ui.unblock(); } - async _finalizeValidation() { - if ((this.currentOrder.is_paid_with_cash() || this.currentOrder.get_change()) && this.env.pos.config.iface_cashdrawer && this.env.proxy && this.env.proxy.printer) { - this.env.proxy.printer.open_cashbox(); + } + async _finalizeValidation() { + if ((this.currentOrder.is_paid_with_cash() || this.currentOrder.get_change()) && this.env.pos.config.iface_cashdrawer && this.env.proxy && this.env.proxy.printer) { + this.env.proxy.printer.open_cashbox(); + } + this.currentOrder.initialize_validation_date(); + for (let line of this.paymentLines) { + if (!line.amount === 0) { + this.currentOrder.remove_paymentline(line); } - this.currentOrder.initialize_validation_date(); - for (let line of this.paymentLines) { - if (!line.amount === 0) { - this.currentOrder.remove_paymentline(line); + } + this.currentOrder.finalized = true; + let syncOrderResult, hasError; + try { + // 1. Save order to server. + syncOrderResult = await this.env.pos.push_single_order(this.currentOrder); + // 2. Invoice. + if (this.shouldDownloadInvoice() && this.currentOrder.is_to_invoice()) { + if (syncOrderResult.length) { + await this.env.legacyActionManager.do_action(this.env.pos.invoiceReportAction, { + additional_context: { + active_ids: [syncOrderResult[0].account_move], + }, + }); + } else { + throw { + code: 401, + message: 'Backend Invoice', + data: { + order: this.currentOrder + } + }; } } - this.currentOrder.finalized = true; - let syncOrderResult, hasError; - try { - // 1. Save order to server. - syncOrderResult = await this.env.pos.push_single_order(this.currentOrder); - // 2. Invoice. - if (this.currentOrder.is_to_invoice()) { - if (syncOrderResult.length) { - await this.env.legacyActionManager.do_action('account.account_invoices', { - additional_context: { - active_ids: [syncOrderResult[0].account_move], - }, - }); - } else { - throw { - code: 401, - message: 'Backend Invoice', - data: { - order: this.currentOrder - } - }; - } - } - // 3. Post process. - if (syncOrderResult.length && this.currentOrder.wait_for_push_order()) { - const postPushResult = await this._postPushOrderResolve( - this.currentOrder, - syncOrderResult.map((res) => res.id) - ); - if (!postPushResult) { - this.showPopup('ErrorPopup', { - title: this.env._t('Error: no internet connection.'), - body: this.env._t('Some, if not all, post-processing after syncing order failed.'), - }); - } + // 3. Post process. + if (syncOrderResult.length && this.currentOrder.wait_for_push_order()) { + const postPushResult = await this._postPushOrderResolve( + this.currentOrder, + syncOrderResult.map((res) => res.id) + ); + if (!postPushResult) { + this.showPopup('ErrorPopup', { + title: this.env._t('Error: no internet connection.'), + body: this.env._t('Some, if not all, post-processing after syncing order failed.'), + }); } - } catch (error) { - if (error.code == 700 || error.code == 701) - this.error = true; + } + } catch (error) { + this.env.services.ui.unblock(); + if (error.code == 700 || error.code == 701) + this.error = true; - if ('code' in error) { - // We started putting `code` in the rejected object for invoicing error. - // We can continue with that convention such that when the error has `code`, - // then it is an error when invoicing. Besides, _handlePushOrderError was - // introduce to handle invoicing error logic. - if (this.env.pos.config.button_operation == 'send') { - await this._handlePushOrderError(error); - } + if ('code' in error) { + // We started putting `code` in the rejected object for invoicing error. + // We can continue with that convention such that when the error has `code`, + // then it is an error when invoicing. Besides, _handlePushOrderError was + // introduce to handle invoicing error logic. + if (this.env.pos.config.button_operation == 'send') { + await this._handlePushOrderError(error); + } + } else { + // We don't block for connection error. But we rethrow for any other errors. + if (isConnectionError(error)) { + this.showPopup('OfflineErrorPopup', { + title: this.env._t('Connection Error'), + body: this.env._t('Order is not synced. Check your internet connection'), + }); } else { - // We don't block for connection error. But we rethrow for any other errors. - if (isConnectionError(error)) { - this.showPopup('OfflineErrorPopup', { - title: this.env._t('Connection Error'), - body: this.env._t('Order is not synced. Check your internet connection'), - }); - } else { - throw error; - } + throw error; } - } finally { - // Always show the next screen regardless of error since pos has to - // continue working even offline. - this.showScreen(this.nextScreen); - // Remove the order from the local storage so that when we refresh the page, the order - // won't be there - this.env.pos.db.remove_unpaid_order(this.currentOrder); + } + } finally { + // Always show the next screen regardless of error since pos has to + // continue working even offline. + this.env.services.ui.unblock() + this.showScreen(this.nextScreen); + // Remove the order from the local storage so that when we refresh the page, the order + // won't be there + this.env.pos.db.remove_unpaid_order(this.currentOrder); - // Ask the user to sync the remaining unsynced orders. - if (!hasError && syncOrderResult && this.env.pos.db.get_orders().length) { - const { - confirmed - } = await this.showPopup('ConfirmPopup', { - title: this.env._t('Remaining unsynced orders'), - body: this.env._t( - 'There are unsynced orders. Do you want to sync these orders?' - ), - }); - if (confirmed) { - // NOTE: Not yet sure if this should be awaited or not. - // If awaited, some operations like changing screen - // might not work. - this.env.pos.push_orders(); - } + // Ask the user to sync the remaining unsynced orders. + if (!hasError && syncOrderResult && this.env.pos.db.get_orders().length) { + const { + confirmed + } = await this.showPopup('ConfirmPopup', { + title: this.env._t('Remaining unsynced orders'), + body: this.env._t( + 'There are unsynced orders. Do you want to sync these orders?' + ), + }); + if (confirmed) { + // NOTE: Not yet sure if this should be awaited or not. + // If awaited, some operations like changing screen + // might not work. + this.env.pos.push_orders(); } } } + } }; Registries.Component.extend(PaymentScreen, PosInvoiceAutomatePaymentScreen); return PaymentScreen;