Skip to content

[ADD] pos_formate: add option for select and edit receipt formate #908

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
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions pos_formate/__init__.py
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 wizards
24 changes: 24 additions & 0 deletions pos_formate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
'name': "pos formate",
'version': '1.0',
'depends': ['point_of_sale'],
'author': "gasa",
"license": "LGPL-3",
"sequence": 1,
'data': [
'security/ir.model.access.csv',
'wizards/pos_configure_receipt_views.xml',
'views/res_config_settings_views.xml',
'views/boxed_template.xml',
'views/lined_template.xml',
'views/light_template.xml',
],
'installable': True,
'application': True,
'assets': {
'point_of_sale._assets_pos': [
'pos_formate/static/src/order_receipt_patch.js',
'pos_formate/static/src/order_receipt_patch.xml',
],
},
}
4 changes: 4 additions & 0 deletions pos_formate/models/__init__.py
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 res_config_settings
from . import pos_config
15 changes: 15 additions & 0 deletions pos_formate/models/pos_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from odoo import models, fields


class PosConfig(models.Model):
_inherit = 'pos.config'

receipt_layout = fields.Selection([
('light', 'Light'),
('boxed', 'Boxed'),
('lined', 'Lined'),
], string="Receipt Layout", default='light')

receipt_logo = fields.Binary("Receipt Logo")
receipt_header = fields.Text("Receipt Header")
receipt_footer = fields.Text("Receipt Footer")
30 changes: 30 additions & 0 deletions pos_formate/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import models, fields


class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

pos_receipt_layout = fields.Selection(
selection=[
('light', 'Light'),
('boxed', 'Boxed'),
('lined', 'Lined'),
],
string="POS Receipt Layout",
default='light',
config_parameter='pos.receipt.layout'
)

def action_open_receipt_configuration(self):
return {
'type': 'ir.actions.act_window',
'name': 'Configure Receipt',
'res_model': 'pos.configure.receipt',
'view_mode': 'form',
'target': 'new',
"context": {
"default_pos_config_id": self.pos_config_id.id,
},
}
2 changes: 2 additions & 0 deletions pos_formate/security/ir.model.access.csv
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
access_pos_configure_receipt,pos.configure.receipt,model_pos_configure_receipt,base.group_system,1,1,1,1
44 changes: 44 additions & 0 deletions pos_formate/static/src/order_receipt_patch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/** @odoo-module **/

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

console.log("OrderReceipt Imported:", OrderReceipt);

patch(OrderReceipt, {
template: "pos_formate.order_receipt_inherited",
});

console.log("OrderReceipt Template Patch Applied");

patch(OrderReceipt.prototype, {
setup() {
super.setup();
this.pos = usePos();
console.log("POS Receipt Patch Loaded");
},

get receiptLogo() {
const logo = this.pos.config?.receipt_logo;
console.log("Receipt Logo Data:", logo ? "Logo Found" : "No Logo");
return logo ? `data:image/png;base64,${logo}` : false;
},

get receiptLayout() {
const layout = this.pos.config?.receipt_layout || "light";
console.log("Receipt Layout:", layout);
return layout;
},

get orderQuantity() {
return this.props.data.orderlines.reduce(
(acc, line) => acc + parseFloat(line.qty),
0
);
},

get order() {
return this.pos.get_order();
},
});
Loading