Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pos_event_sale/models/event_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _compute_payment_status(self):
elif rec.is_paid:
rec.payment_status = "paid"
else:
rec.payment_status = "not_paid"
rec.payment_status = "to_pay"
return res

def _check_auto_confirmation(self):
Expand Down
47 changes: 47 additions & 0 deletions pos_event_sale/static/src/js/Screens/AbstractReceiptScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
Copyright 2023 Camptocamp SA (https://www.camptocamp.com).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/
odoo.define("pos_event_sale.AbstractReceiptScreen", function (require) {
"use strict";

const AbstractReceiptScreen = require("point_of_sale.AbstractReceiptScreen");
const Registries = require("point_of_sale.Registries");

/* eslint-disable no-shadow */
const PosEventSaleAbstractReceiptScreen = (AbstractReceiptScreen) =>
class extends AbstractReceiptScreen {
/**
* Prints the event registration receipts through the printer proxy.
* Doesn't do anything if there's no proxy printer.
*
* @returns {Boolean}
*/
async _printEventRegistrations() {
if (this.env.pos.proxy.printer) {
const $receipts = this.el.getElementsByClassName(
"event-registration-receipt"
);
for (const $receipt of $receipts) {
const printResult =
await this.env.pos.proxy.printer.print_receipt(
$receipt.outerHTML
);
if (!printResult.successful) {
console.error("Unable to print event registration receipt");
console.debug(printResult);
return false;
}
}
return true;
}
return false;
}
};

Registries.Component.extend(
AbstractReceiptScreen,
PosEventSaleAbstractReceiptScreen
);
return AbstractReceiptScreen;
});
42 changes: 5 additions & 37 deletions pos_event_sale/static/src/js/Screens/ReceiptScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,16 @@ odoo.define("pos_event_sale.ReceiptScreen", function (require) {
const ReceiptScreen = require("point_of_sale.ReceiptScreen");
const Registries = require("point_of_sale.Registries");

/* eslint-disable no-shadow */
const PosEventSaleReceiptScreen = (ReceiptScreen) =>
class extends ReceiptScreen {
/**
* Prints the event registration receipts through the printer proxy.
* Doesn't do anything if there's no proxy printer.
*
* @returns {Boolean}
*/
async _printEventRegistrationReceipts() {
if (this.env.pos.proxy.printer) {
for (const receiptEl of this.el.getElementsByClassName(
"event-registration-receipt"
)) {
const printResult =
await this.env.pos.proxy.printer.print_receipt(
receiptEl.outerHTML
);
if (!printResult.successful) {
console.error("Unable to print event registration receipt");
console.debug(printResult);
return false;
}
}
return true;
}
return false;
}
/**
* @override
*/
async _printReceipt() {
// First, print the order receipt
const printed = await super._printReceipt();
// Then, print the event registration receipts
if (printed && this.env.pos.proxy.printer) {
const registrationsPrinted =
await this._printEventRegistrationReceipts();
if (!registrationsPrinted) {
return false;
}
}
return printed;
async printReceipt() {
const res = await super.printReceipt();
await this._printEventRegistrations();
return res;
}
};

Expand Down
45 changes: 45 additions & 0 deletions pos_event_sale/static/src/js/Screens/ReprintReceiptScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Copyright 2023 Camptocamp (https://www.camptocamp.com).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
*/
odoo.define("pos_event_sale.ReprintReceiptScreen", function (require) {
"use strict";

const ReprintReceiptScreen = require("point_of_sale.ReprintReceiptScreen");
const Registries = require("point_of_sale.Registries");
const session = require("web.session");

/* eslint-disable no-shadow */
const PosEventSaleReprintReceiptScreen = (ReprintReceiptScreen) =>
class extends ReprintReceiptScreen {
/**
* @override
*/
async willStart() {
await super.willStart();
const order = this.props.order;
if (order.backendId && order.hasEvents()) {
order.event_registrations = await this.rpc({
model: "event.registration",
method: "search_read",
domain: [
["pos_order_id", "=", order.backendId],
["state", "=", "open"],
],
kwargs: {context: session.user_context},
});
}
}
/**
* @override
*/
async _printReceipt() {
const res = await super._printReceipt();
await this._printEventRegistrations();
return res;
}
};

Registries.Component.extend(ReprintReceiptScreen, PosEventSaleReprintReceiptScreen);
return ReprintReceiptScreen;
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
t-as="registration"
order="currentOrder"
registration="registration"
t-ref="event-registration-receipt"
/>
</t>
</xpath>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2023 Camptocamp (https://www.camptocamp.com).
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
-->
<templates id="template" xml:space="preserve">

<t t-inherit="point_of_sale.ReprintReceiptScreen" t-inherit-mode="extension">
<xpath expr="//div[hasclass('pos-receipt-container')]" position="inside">
<t t-if="props.order.event_registrations">
<EventRegistrationReceipt
t-foreach="props.order.event_registrations"
t-as="registration"
order="props.order"
registration="registration"
/>
</t>
</xpath>
</t>

</templates>