Browse Source

Jan 04 [UPDT] : Updated 'pos_invoice_automate'

pull/364/head
AjmalCybro 4 months ago
parent
commit
3dc6c3a3d5
  1. 2
      pos_invoice_automate/__manifest__.py
  2. 5
      pos_invoice_automate/doc/RELEASE_NOTES.md
  3. 2
      pos_invoice_automate/models/pos_config.py
  4. 1
      pos_invoice_automate/models/pos_order.py
  5. 203
      pos_invoice_automate/static/src/js/PaymentScreen.js

2
pos_invoice_automate/__manifest__.py

@ -21,7 +21,7 @@
############################################################################# #############################################################################
{ {
'name': 'POS Automate Invoice', 'name': 'POS Automate Invoice',
'version': '16.0.1.0.0', 'version': '16.0.1.0.1',
'summary': """To manage the POS Invoice Automatically""", 'summary': """To manage the POS Invoice Automatically""",
'description': """This module facilitates the automated sending of invoices 'description': """This module facilitates the automated sending of invoices
to customers, along with the ability to schedule emails at specific to customers, along with the ability to schedule emails at specific

5
pos_invoice_automate/doc/RELEASE_NOTES.md

@ -8,3 +8,8 @@
#### Version 16.0.1.0.0 #### Version 16.0.1.0.0
##### Bug fixes ##### Bug fixes
- Resolved the issue while validating the order - Resolved the issue while validating the order
#### 1.1.2025
#### Version 16.0.1.0.1
##### Bug fixes
- Bug Fix

2
pos_invoice_automate/models/pos_config.py

@ -47,6 +47,7 @@ class PosConfig(models.Model):
def start_cron(self): def start_cron(self):
"""Start the cron scheduler""" """Start the cron scheduler"""
print("............start cron............")
if self.interval >= 0: if self.interval >= 0:
self.is_started = True self.is_started = True
self.is_stopped = False self.is_stopped = False
@ -75,6 +76,7 @@ class PosConfig(models.Model):
def _send_mail(self, config): def _send_mail(self, config):
"""Send invoice by Email""" """Send invoice by Email"""
print("sentmail.....................")
point_of_sale = self.env['pos.config'].browse(config) point_of_sale = self.env['pos.config'].browse(config)
for order in point_of_sale.session_ids.order_ids.filtered( for order in point_of_sale.session_ids.order_ids.filtered(
lambda x: x.state == 'invoiced' and not x.is_send): lambda x: x.state == 'invoiced' and not x.is_send):

1
pos_invoice_automate/models/pos_order.py

@ -68,6 +68,7 @@ class PosOrder(models.Model):
} }
def download_invoice(self): def download_invoice(self):
print("mmmmmmmmmmmmmmmmmmm")
if not self.account_move: if not self.account_move:
self.action_pos_order_invoice() self.action_pos_order_invoice()
template = self.env.ref('pos_invoice_automate.send_mail_template') template = self.env.ref('pos_invoice_automate.send_mail_template')

203
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); 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 value = await this.env.pos.push_single_order(this.currentOrder);
const config_id = this.env.pos.config.id const config_id = this.env.pos.config.id;
const order_id = value[0].id const order_id = value[0].id;
if (this.env.pos.config.is_started) { if (this.env.pos.config.is_started) {
await this.rpc({ await this.rpc({
model: 'pos.config', model: 'pos.config',
@ -28,14 +30,13 @@ odoo.define('pos_invoice_automate.PaymentScreen', function(require) {
}); });
} else { } else {
if (this.env.pos.config.button_operation == 'download') { if (this.env.pos.config.button_operation == 'download') {
var self = this;
await this.rpc({ await this.rpc({
model: 'pos.order', model: 'pos.order',
method: 'download_invoice', method: 'download_invoice',
args: [order_id], args: [order_id],
}).then(function(result) { }).then((result) => {
self.env.legacyActionManager.do_action(result) this.env.legacyActionManager.do_action(result);
}) });
} else if (this.env.pos.config.button_operation == 'send') { } else if (this.env.pos.config.button_operation == 'send') {
await this.rpc({ await this.rpc({
model: 'pos.order', model: 'pos.order',
@ -43,114 +44,124 @@ odoo.define('pos_invoice_automate.PaymentScreen', function(require) {
args: [order_id], args: [order_id],
}); });
} else if (this.env.pos.config.button_operation == 'download_send_mail') { } else if (this.env.pos.config.button_operation == 'download_send_mail') {
var self = this;
await this.rpc({ await this.rpc({
model: 'pos.order', model: 'pos.order',
method: 'send_mail_invoice', method: 'send_mail_invoice',
args: [order_id], args: [order_id],
}).then(function(result) { }).then((result) => {
self.env.legacyActionManager.do_action(result) this.env.legacyActionManager.do_action(result);
}) });
} }
} }
await super.validateOrder(isForceValidate); 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) { async _finalizeValidation() {
this.env.proxy.printer.open_cashbox(); 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) { this.currentOrder.finalized = true;
if (!line.amount === 0) { let syncOrderResult, hasError;
this.currentOrder.remove_paymentline(line); 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; // 3. Post process.
let syncOrderResult, hasError; if (syncOrderResult.length && this.currentOrder.wait_for_push_order()) {
try { const postPushResult = await this._postPushOrderResolve(
// 1. Save order to server. this.currentOrder,
syncOrderResult = await this.env.pos.push_single_order(this.currentOrder); syncOrderResult.map((res) => res.id)
// 2. Invoice. );
if (this.currentOrder.is_to_invoice()) { if (!postPushResult) {
if (syncOrderResult.length) { this.showPopup('ErrorPopup', {
await this.env.legacyActionManager.do_action('account.account_invoices', { title: this.env._t('Error: no internet connection.'),
additional_context: { body: this.env._t('Some, if not all, post-processing after syncing order failed.'),
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.'),
});
}
} }
} catch (error) { }
if (error.code == 700 || error.code == 701) } catch (error) {
this.error = true; this.env.services.ui.unblock();
if (error.code == 700 || error.code == 701)
this.error = true;
if ('code' in error) { if ('code' in error) {
// We started putting `code` in the rejected object for invoicing 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`, // We can continue with that convention such that when the error has `code`,
// then it is an error when invoicing. Besides, _handlePushOrderError was // then it is an error when invoicing. Besides, _handlePushOrderError was
// introduce to handle invoicing error logic. // introduce to handle invoicing error logic.
if (this.env.pos.config.button_operation == 'send') { if (this.env.pos.config.button_operation == 'send') {
await this._handlePushOrderError(error); 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 { } else {
// We don't block for connection error. But we rethrow for any other errors. throw error;
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;
}
} }
} finally { }
// Always show the next screen regardless of error since pos has to } finally {
// continue working even offline. // Always show the next screen regardless of error since pos has to
this.showScreen(this.nextScreen); // continue working even offline.
// Remove the order from the local storage so that when we refresh the page, the order this.env.services.ui.unblock()
// won't be there this.showScreen(this.nextScreen);
this.env.pos.db.remove_unpaid_order(this.currentOrder); // 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. // Ask the user to sync the remaining unsynced orders.
if (!hasError && syncOrderResult && this.env.pos.db.get_orders().length) { if (!hasError && syncOrderResult && this.env.pos.db.get_orders().length) {
const { const {
confirmed confirmed
} = await this.showPopup('ConfirmPopup', { } = await this.showPopup('ConfirmPopup', {
title: this.env._t('Remaining unsynced orders'), title: this.env._t('Remaining unsynced orders'),
body: this.env._t( body: this.env._t(
'There are unsynced orders. Do you want to sync these orders?' 'There are unsynced orders. Do you want to sync these orders?'
), ),
}); });
if (confirmed) { if (confirmed) {
// NOTE: Not yet sure if this should be awaited or not. // NOTE: Not yet sure if this should be awaited or not.
// If awaited, some operations like changing screen // If awaited, some operations like changing screen
// might not work. // might not work.
this.env.pos.push_orders(); this.env.pos.push_orders();
}
} }
} }
} }
}
}; };
Registries.Component.extend(PaymentScreen, PosInvoiceAutomatePaymentScreen); Registries.Component.extend(PaymentScreen, PosInvoiceAutomatePaymentScreen);
return PaymentScreen; return PaymentScreen;

Loading…
Cancel
Save