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',
'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

5
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

2
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):

1
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')

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);
}
}
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;

Loading…
Cancel
Save