Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16.0 [IMP] [FIX] fiscal_epos_print: Varie migliorie e correzioni per il modulo #4573

Open
wants to merge 6 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ odoo.define("fiscal_epos_print.EpsonFP81IIComponent", function (require) {
});
if (confirmed) {
fp90.printFiscalReprintLast(
this.env.pos.cashier.fiscal_operator_number || "1"
this.env.pos.get_cashier() || "1"
);
} else {
// TODO not exist
Expand Down Expand Up @@ -166,8 +166,8 @@ odoo.define("fiscal_epos_print.EpsonFP81IIComponent", function (require) {
});
if (confirmed) {
// Fp90.printFiscalReport();
fp90.printFiscalXZReport(
this.env.pos.cashier.fiscal_operator_number || "1"
fp90.printFiscalReport(
this.env.pos.get_cashier() || "1"
);
} else {
// TODO not exist
Expand All @@ -191,7 +191,7 @@ odoo.define("fiscal_epos_print.EpsonFP81IIComponent", function (require) {
});
if (confirmed) {
fp90.printFiscalXReport(
this.env.pos.cashier.fiscal_operator_number || "1"
this.env.pos.get_cashier() || "1"
);
} else {
// TODO not exist
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ odoo.define("fiscal_epos_print.SetRefundInfoButton", function (require) {
var dd = ("0" + current_order.refund_date.getDate()).slice(-2);
var mm = ("0" + (current_order.refund_date.getMonth() + 1)).slice(-2);
var yyyy = current_order.refund_date.getFullYear();

this.showPopup("RefundInfoPopup", {
title: _t("Refund Information Details"),
refund_date: yyyy + "-" + mm + "-" + dd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,38 +25,42 @@ odoo.define("fiscal_epos_print.PaymentScreen", function (require) {
}

async sendToFP90Printer(order) {
if (this.env.pos.config.printer_ip && !order.is_to_invoice()) {
// TODO self.chrome does not exists
// this.chrome.loading_show();
// this.chrome.loading_message(_t('Connecting to the fiscal printer'));
if (
order.has_refund &&
this.env.pos.context &&
this.env.pos.context.refund_details
) {
order.refund_date = this.env.pos.context.refund_date;
order.refund_report = this.env.pos.context.refund_report;
order.refund_doc_num = this.env.pos.context.refund_doc_num;
order.refund_cash_fiscal_serial =
this.env.pos.context.refund_cash_fiscal_serial;
}

var printer_options = order.getPrinterOptions();
printer_options.order = order;
var receipt = order.export_for_printing();
var fp90 = new eposDriver(printer_options, this);
await fp90.printFiscalReceipt(receipt);
await new Promise((resolve) => setTimeout(resolve, 2000));
// This line causes problems on bill split. What's the sense of deleting the actual pos context?!
// It regenerates orders which are already partly paid using split function...
// this.env.pos.context = {};
// TODO self.chrome does not exists
// this.chrome.loading_show();
// this.chrome.loading_message(_t('Connecting to the fiscal printer'));
if (
order.has_refund &&
this.env.pos.context &&
this.env.pos.context.refund_details
) {
order.refund_date = this.env.pos.context.refund_date;
order.refund_report = this.env.pos.context.refund_report;
order.refund_doc_num = this.env.pos.context.refund_doc_num;
order.refund_cash_fiscal_serial =
this.env.pos.context.refund_cash_fiscal_serial;
}

var printer_options = order.getPrinterOptions();
printer_options.order = order;
var receipt = order.export_for_printing();
var fp90 = new eposDriver(printer_options, this);
await fp90.printFiscalReceipt(receipt);
// This line causes problems on bill split. What's the sense of deleting the actual pos context?!
// It regenerates orders which are already partly paid using split function...
// this.env.pos.context = {};
}

async _finalizeValidation() {
var currentOrder = this.currentOrder;
await this.sendToFP90Printer(currentOrder);
await super._finalizeValidation();
if (this.env.pos.config.printer_ip && !currentOrder.is_to_invoice()) {
await this.sendToFP90Printer(currentOrder);
if (currentOrder._printed) {
await super._finalizeValidation();
}
}
else {
await super._finalizeValidation();
}
}

_isOrderValid(isForceValidate) {
Expand Down
60 changes: 32 additions & 28 deletions fiscal_epos_print/static/src/js/epson_epos_print.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ odoo.define("fiscal_epos_print.epson_epos_print", function (require) {
: [];
var msgPrinter = "";
var info = "";
var body_msg = "";
var order_lines_msg = "";
var order_payment_msg = "";

if (tagStatus.length > 0 && res.success) {
info = add_info[tagStatus[0]];
Expand All @@ -155,26 +158,29 @@ odoo.define("fiscal_epos_print.epson_epos_print", function (require) {
JSON.stringify(tag_list_names) +
"\n" +
JSON.stringify(add_info);
order_lines_msg = order.orderlines.map((l) => `\n${l.full_product_name || ""}, Quantity: ${l.quantity || ""}, Price: ${l.price || ""}, Discount: ${l.discount || ""}`).join(",");
order_payment_msg = order.paymentlines.map((l) => `\nType: ${l.payment_method.name || ""}, Amount: ${l.amount || ""}`).join(",");
// Sender.env.pos.push_single_order(order);
}
if (tagStatus.length > 0) {
info = add_info[tagStatus[0]];
msgPrinter = decodeFpStatus(info);
}
// TODO
// sender.chrome.screens['receipt'].lock_screen(true);
// TODO is this correct?

body_msg = `${_t("An error happened while sending data to the printer.\nError code: ")}${res.code || ""}` +
`${_t("\nStatus: ")}${res.status || ""}` +
`${_t("\nPrinter Code: ")}${info || ""}\n${_t("Error Message: ")}${msgPrinter}`;
if (order) {
body_msg += `\n${_t("Order Details.\nOrder lines: {")}${order_lines_msg}` +
`${_t(" }\nPayment Lines: {")}${order_payment_msg}` +
`${_t(" }\nTechnical details: \nXML: ")}${order.fp_xml}`;
}
Gui.showPopup("ErrorPopup", {
title: _t("Connection to the printer failed"),
body:
_t(
"An error happened while sending data to the printer. Error code: "
) +
(res.code || "") +
"\n" +
_t("Error Message: ") +
msgPrinter,
body: body_msg,
});
// TODO
// sender.chrome.screens['receipt'].lock_screen(true);
return;
}

Expand Down Expand Up @@ -705,21 +711,21 @@ odoo.define("fiscal_epos_print.epson_epos_print", function (require) {
receipt.lottery_code.padEnd(16, " ") +
'0000" />';
}
if (receipt.rounding_applied !== 0 && !has_refund) {
xml += self.printRounding({
amount: Math.abs(
round_pr(
receipt.rounding_applied,
self.sender.env.pos.currency.rounding
)
),

//Check for roundings Payments
//If it's needed, adds a payment line with payment method type 6 in case of a rounding
if (Math.abs(receipt.total_paid) < Math.abs(receipt.subtotal)) {
let payment_round = 0;
payment_round = round_pr(
(receipt.subtotal - receipt.total_paid), self.sender.env.pos.currency.rounding
);
xml += this.printRecTotal({
payment: Math.abs(payment_round),
paymentType: "6",
operator: fiscal_operator,
});
xml +=
'<printRecSubtotal operator="' +
fiscal_operator +
'" option="1" />';
}
}

// TODO is always the same Total for refund and payments?
receipt.ticket = "";
_.each(receipt.paymentlines, function (l) {
Expand Down Expand Up @@ -752,13 +758,11 @@ odoo.define("fiscal_epos_print.epson_epos_print", function (require) {
'<endFiscalReceipt operator="' +
fiscal_operator +
'" /></printerFiscalReceipt>';
this.fiscalPrinter.send(this.url, xml);
this.order.fp_xml = xml;
this.fiscalPrinter.send(this.url, xml, 0, "sync");
console.log(xml);
},

/*
DON'T USE, this fiscal closure is forbid by Epson by default
*/
printFiscalReport: function (f_op) {
var xml = "<printerFiscalReport>";
xml += '<printZReport operator="' + f_op + '" timeout="" />';
Expand Down
7 changes: 5 additions & 2 deletions fiscal_epos_print/static/src/js/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ odoo.define("fiscal_epos_print.models", function (require) {
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;

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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
id="refund_full_refund"
class="detail refund_full_refund"
type='checkbox'
t-att-value="props.refund_full_refund || ''"
t-att-checked="props.refund_full_refund || ''"
t-ref="inputRefundFullRefund"
/>
</div>
Expand Down
Loading