-
-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] pos_event_sale: implement event registration reprinting
- Loading branch information
1 parent
3d30f83
commit 1708114
Showing
5 changed files
with
118 additions
and
38 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
pos_event_sale/static/src/js/Screens/AbstractReceiptScreen.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
pos_event_sale/static/src/js/Screens/ReprintReceiptScreen.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
pos_event_sale/static/src/xml/ReprintReceiptScreen/ReprintReceiptScreen.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |