|
@ -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; |
|
|