-
Notifications
You must be signed in to change notification settings - Fork 2.4k
[ADD] pos_receipt: allow custom receipt layout with preview #904
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
Draft
niyp-odoo
wants to merge
1
commit into
odoo:18.0
Choose a base branch
from
odoo-dev:18.0-POS-receipt-niyp
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from . import models | ||
from . import wizard |
This file contains hidden or 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 @@ | ||
{ | ||
'name': 'POS receipt', | ||
'version': '1.0', | ||
'author': 'niyp', | ||
'depends': ['point_of_sale'], | ||
'data': [ | ||
'security/ir.model.access.csv', | ||
'wizard/pos_receipt_wizard_views.xml', | ||
'views/res_config_settings_view.xml', | ||
'views/boxes_receipt.xml', | ||
'views/lined_receipt.xml', | ||
'views/light_receipt.xml', | ||
], | ||
'assets': { | ||
'point_of_sale._assets_pos': [ | ||
'pos_receipt/static/src/**/*', | ||
], | ||
}, | ||
'installable': True, | ||
'license': 'LGPL-3', | ||
} |
This file contains hidden or 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,4 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from . import pos_config | ||
from . import res_config_settings |
This file contains hidden or 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,15 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class POSConfig(models.Model): | ||
_inherit = 'pos.config' | ||
|
||
receipt_layout = fields.Selection([ | ||
('light', 'Light'), | ||
('lined', 'Lined'), | ||
('boxes', 'Boxes'), | ||
], string="Receipt Layout", default='light') | ||
|
||
receipt_logo = fields.Binary(string='Receipt Logo', related='company_id.logo', readonly=False) |
This file contains hidden or 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,19 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = 'res.config.settings' | ||
|
||
receipt_layout = fields.Selection(related='pos_config_id.receipt_layout', readonly=False) | ||
|
||
def action_pos_receipt_layout(self): | ||
return { | ||
'type': 'ir.actions.act_window', | ||
'name': 'Configure your pos receipt', | ||
'res_model': 'pos.receipt.wizard', | ||
'view_mode': 'form', | ||
'target': 'new', | ||
'context': {'active_pos_config_id': self.pos_config_id.id, 'dialog_size': 'extra-large'}, | ||
} |
This file contains hidden or 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,2 @@ | ||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink | ||
pos_receipt.access_receipt_layout,access_receipt_layout,pos_receipt.model_pos_receipt_wizard,base.group_user,1,1,1,1 |
This file contains hidden or 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,22 @@ | ||
import { OrderReceipt } from "@point_of_sale/app/screens/receipt_screen/receipt/order_receipt"; | ||
import { patch } from "@web/core/utils/patch"; | ||
import { usePos } from "@point_of_sale/app/store/pos_hook"; | ||
|
||
patch(OrderReceipt, { | ||
template: "pos_receipt.order_receipt_inherited" | ||
}); | ||
|
||
patch(OrderReceipt.prototype, { | ||
setup(){ | ||
super.setup(); | ||
this.pos = usePos(); | ||
}, | ||
|
||
get orderQuantity() { | ||
return this.props.data.orderlines.reduce((acc, line) => acc + parseFloat(line.qty), 0); | ||
}, | ||
|
||
get order() { | ||
return this.pos.get_order(); | ||
} | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="custom_pos_receipt_boxes"> | ||
<div style="text-align: center; width: 300px; margin: auto; border: 1px solid black; padding: 10px;"> | ||
<img t-if="logo" t-att-src="image_data_uri(logo)" alt="Logo" style="height: 70px; " /> | ||
<p style="margin: 5px 0;">Odoo India Pvt Ltd<br />Infocity Gandhinagar<br />Tax Id: | ||
233300990223</p> | ||
<t t-esc="header" /> | ||
<h2 style="margin: 5px 0;">701</h2> | ||
<t t-if="is_restaurant"> Served by MOG <br /> Table 5 Guest 3 </t> | ||
<table style="width: 100%; border-collapse: collapse; text-align: left;"> | ||
<tr> | ||
<th style="border: 1px solid black;">No</th> | ||
<th style="border: 1px solid black;">Item</th> | ||
<th style="border: 1px solid black;">Amount</th> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid black;">1</td> | ||
<td style="border: 1px solid black;">Margarita Pizza<br />3 X 200<br />HSN: | ||
2300976</td> | ||
<td style="border: 1px solid black;">$600</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid black;">2</td> | ||
<td style="border: 1px solid black;">Bacon Burger<br />5 X 150</td> | ||
<td style="border: 1px solid black;">$750</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid black;">3</td> | ||
<td style="border: 1px solid black;">Apple Pie<br />3 X 80<br />HSN: 2300976</td> | ||
<td style="border: 1px solid black;">$240</td> | ||
</tr> | ||
<tr> | ||
<td style="border: 1px solid black;">4</td> | ||
<td style="border: 1px solid black;">Cheese Burger<br />5 X 150<br />HSN: | ||
2300976</td> | ||
<td style="border: 1px solid black;">$750</td> | ||
</tr> | ||
</table> | ||
<div class="border-bottom border-dark py-1 mb-2" style="font-size: 12px;"> | ||
<div class="d-flex justify-content-between small"> | ||
<span>Total Qty 12</span> | ||
<span>Sub Total $1625</span> | ||
</div> | ||
</div> | ||
<div class="text-end mb-2 fw-bold small border-bottom border-dark" | ||
style="font-size: 12px;"> | ||
Cash $1625 | ||
</div> | ||
<table style="width: 100%; border-collapse: collapse; text-align: left;"> | ||
<tr> | ||
<th>Tax</th> | ||
<th>Amount</th> | ||
<th>Base</th> | ||
<th>Total</th> | ||
</tr> | ||
<tr> | ||
<td>SGST 2.5%</td> | ||
<td>40.2</td> | ||
<td>1584.8</td> | ||
<td>1625</td> | ||
</tr> | ||
<tr> | ||
<td>CGST 2.5%</td> | ||
<td>40.2</td> | ||
<td>1584.8</td> | ||
<td>1625</td> | ||
</tr> | ||
</table> | ||
<t t-esc="footer" /> | ||
<p style="margin: 5px 0;">Odoo Point of Sale</p> | ||
<p style="margin: 5px 0;">Order 0001-003-0004</p> | ||
<p style="margin: 5px 0;">04/06/2024 08:30:24</p> | ||
</div> | ||
</template> | ||
</odoo> |
This file contains hidden or 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,37 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="custom_receipt_static_light" t-name="custom_receipt_static"> | ||
<div style="font-family: Arial, sans-serif; width: 350px; margin: auto; text-align: center; border: 1px solid #ddd; padding: 10px;"> | ||
<img t-if="logo" t-att-src="image_data_uri(logo)" alt="Logo" style="height: 70px; "/> | ||
<p style="margin: 5px 0; font-size: 12px;"> | ||
Tel: +1 555-555-5556<br/> | ||
[email protected]<br/> | ||
http://www.example.com | ||
</p> | ||
<t t-esc="header"/> | ||
<h1 style="margin: 10px 0;">301</h1> | ||
<t t-if="is_restaurant"> | ||
Served by MOG <br/> | ||
Table 5 Guest 3 | ||
</t> | ||
<table style="width: 100%; text-align: left; font-size: 14px;"> | ||
<tr><td><b>Margarita Pizza</b></td><td style="text-align: right;">$ 140.00</td></tr> | ||
<tr><td><span style="border: 1px solid #000; padding: 2px 5px;">1.00</span> x $140.00 / Units</td></tr> | ||
|
||
<tr><td><b>Bacon Burger</b></td><td style="text-align: right;">$ 33.00</td></tr> | ||
<tr><td><span style="border: 1px solid #000; padding: 2px 5px;">1.00</span> x $33.00 / Units</td></tr> | ||
|
||
<tr><td><b>Apple Pie</b></td><td style="text-align: right;">$ 85.00</td></tr> | ||
<tr><td><span style="border: 1px solid #000; padding: 2px 5px;">1.00</span> x $85.00 / Units</td></tr> | ||
</table> | ||
<hr/> | ||
<table style="width: 100%; text-align: left; font-size: 14px;"> | ||
<tr><td>TOTAL</td><td style="text-align: right;">$ 258.00</td></tr> | ||
<tr><td>Cash</td><td style="text-align: right;">$ 258.00</td></tr> | ||
</table> | ||
<t t-esc="footer"/> | ||
<p style="margin-top: 10px; font-size: 12px;">Powered by Odoo</p> | ||
<p style="font-size: 12px;">Order 00003-001-0001<br/>03/19/2025 17:55:58</p> | ||
</div> | ||
</template> | ||
</odoo> |
This file contains hidden or 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,105 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="custom_receipt_lined" t-name="custom_receipt_handwritten"> | ||
<div style="width: 320px; margin: auto; border: 2px solid black; padding: 10px; text-align: center;"> | ||
<img t-if="logo" t-att-src="image_data_uri(logo)" alt="Logo" style="height: 70px; "/> | ||
<div style="font-size: 12px; line-height: 1.5;"> | ||
Odoo India pvt ltd<br/> | ||
Infocity Gandhinagar<br/> | ||
<strong>Tax Id: 2233004900223</strong> | ||
</div> | ||
<t t-esc="header"/> | ||
<h1 style="margin: 10px 0; font-size: 22px; font-weight: bold;">701</h1> | ||
<t t-if="is_restaurant"> | ||
Served by MOG <br/> | ||
Table 5 Guest 3 | ||
</t> | ||
<table style="width: 100%; font-size: 12px; text-align: left; border-collapse: collapse; margin-top: 10px;"> | ||
<thead class="border-top border-bottom border-dark"> | ||
<tr> | ||
<th>No</th> | ||
<th>Item</th> | ||
<th>Qty</th> | ||
<th>Prices</th> | ||
<th>Amount</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td>1</td> | ||
<td>Margarita Pizza</td> | ||
<td>3</td> | ||
<td>200</td> | ||
<td>600</td> | ||
</tr> | ||
<tr> | ||
<td>2</td> | ||
<td>Bacon Burger</td> | ||
<td>5</td> | ||
<td>150</td> | ||
<td>750</td> | ||
</tr> | ||
<tr> | ||
<td>3</td> | ||
<td>Apple Pie</td> | ||
<td>2</td> | ||
<td>100</td> | ||
<td>200</td> | ||
</tr> | ||
<tr> | ||
<td>4</td> | ||
<td>Cheese Burger</td> | ||
<td>1</td> | ||
<td>75</td> | ||
<td>75</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<div class="border-top border-dark py-1 mb-2"> | ||
<div class="d-flex justify-content-between small"> | ||
<span>Total Qty | ||
12 | ||
</span> | ||
<span class="bg-dark text-white">Sub Total $ | ||
1625 | ||
</span> | ||
</div> | ||
</div> | ||
<div class="text-end mb-2 fw-bold small"> | ||
Bank | ||
1625 | ||
</div> | ||
|
||
<table style="width: 100%; font-size: 12px; text-align: left; border-collapse: collapse; margin-top: 10px;"> | ||
<thead> | ||
<tr> | ||
<th>Tax</th> | ||
<th>Amount</th> | ||
<th>Base</th> | ||
<th>Total</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><i>SGST 2.5%</i></td> | ||
<td>40.2</td> | ||
<td>1584.8</td> | ||
<td>1625</td> | ||
</tr> | ||
<tr> | ||
<td><i>CGST 2.5%</i></td> | ||
<td>40.2</td> | ||
<td>1584.8</td> | ||
<td>1625</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<t t-esc="footer"/> | ||
<div style="text-align: center; font-size: 12px; margin-top: 10px;"> | ||
<strong>Odoo Point of Sale</strong><br/> | ||
Order 0001-003-0004<br/> | ||
04/06/2024 08:30:24 | ||
</div> | ||
</div> | ||
</template> | ||
</odoo> |
This file contains hidden or 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,18 @@ | ||
<odoo> | ||
<data> | ||
<record id="view_pos_receipt_settings_inherited" model="ir.ui.view"> | ||
<field name="name">pos.reciept.settings.form.inherit</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="point_of_sale.res_config_settings_view_form"/> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//block[@id='pos_bills_and_receipts_section']/setting" position="replace"> | ||
<setting id="document_layout_setting" string="Receipt Layout" help="Choose the layout of your receipt"> | ||
<field name="receipt_layout"/> | ||
<br/> | ||
<button name="action_pos_receipt_layout" string="Configure receipt" type="object" class="oe_link" icon="oi-arrow-right"/> | ||
</setting> | ||
</xpath> | ||
</field> | ||
</record> | ||
</data> | ||
</odoo> |
This file contains hidden or 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,3 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from . import pos_receipt_wizard |
This file contains hidden or 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,50 @@ | ||
# Part of Odoo. See LICENSE file for full copyright and licensing details. | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class PosReceiptWizard(models.TransientModel): | ||
_name = 'pos.receipt.wizard' | ||
_description = 'POS Receipt Layout' | ||
|
||
def _get_default_pos_config(self): | ||
return self.env['pos.config'].browse([self.env.context.get('active_pos_config_id')]) | ||
|
||
pos_config_id = fields.Many2one('pos.config', string='Point of Sale', default=_get_default_pos_config, required=True) | ||
receipt_layout = fields.Selection(related='pos_config_id.receipt_layout', readonly=False, required=True) | ||
receipt_logo = fields.Binary(related='pos_config_id.receipt_logo', readonly=False) | ||
receipt_header = fields.Text(related='pos_config_id.receipt_header', readonly=False) | ||
receipt_footer = fields.Text(related='pos_config_id.receipt_footer', readonly=False) | ||
receipt_preview = fields.Html(compute='_compute_receipt_preview') | ||
|
||
@api.depends('receipt_layout', 'receipt_header', 'receipt_footer', 'receipt_logo') | ||
def _compute_receipt_preview(self): | ||
if self.receipt_layout == "lined": | ||
self.receipt_preview = self.env['ir.ui.view']._render_template( | ||
'pos_receipt.custom_receipt_lined', | ||
{ | ||
'header': self.receipt_header, | ||
'footer': self.receipt_footer, | ||
'logo': self.receipt_logo, | ||
} | ||
) | ||
|
||
elif self.receipt_layout == "boxes": | ||
self.receipt_preview = self.env['ir.ui.view']._render_template( | ||
'pos_receipt.custom_pos_receipt_boxes', | ||
{ | ||
'header': self.receipt_header, | ||
'footer': self.receipt_footer, | ||
'logo': self.receipt_logo, | ||
} | ||
) | ||
|
||
else: | ||
self.receipt_preview = self.env['ir.ui.view']._render_template( | ||
'pos_receipt.custom_receipt_static_light', | ||
{ | ||
'header': self.receipt_header, | ||
'footer': self.receipt_footer, | ||
'logo': self.receipt_logo, | ||
} | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this loop over self? If not why?