Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
6 Replies
5296 Tampilan

Hello!

I'm trying to add a new field in my POS Receipt.


I already inherited the template and I added a simple static text.


But I want to add a field, how can I achieve that? Is by JavaScript or Python?


What model does it use? I already tried POS Order, but didn't work


Thanks!


This is my code so far:


from odoo import models

classPosSession(models.Model):
​_inherit = ["pos.session", "evo.payments.session"] # Evo Payments Session is my custom model

def_loader_params_evo_payments_session(self):|
"""        Loads the QR Code to the Order Receipt, calling the Evo Payments Session method        """ 
result = super().CUSTOM_FUNCTION()     
result["search_params"]["fields"].append(CUSTOM_FIELD)
return result


What should I put in CUSTOM_FUNCTION() and CUSTOM_FIELD?

Avatar
Buang

Hi mauricio,

Do you mean you want to add it to the POS receipt?
can you please send an image of the place you want to add the field?

Regards,

Jawaban Terbai

Hi!

You're on the right track. To show a custom field on the POS Receipt, you need to:

✅ 1. Expose the field to the POS frontend (via Python)

If your custom field is on evo.payments.session, you need to load it using the session loader. Your function might look like this:

def _loader_params_evo_payments_session(self):
    result = super()._loader_params_evo_payments_session()
    result["search_params"]["fields"].append("your_custom_field")
    return result

Replace "your_custom_field" with the actual field name from your model.

If you're calling a different function (e.g. _loader_params_pos_session), make sure it returns the needed field too.

✅ 2. Get the field into JavaScript

In your custom JS (extend models.PosModel), load the field like this:

import { PosGlobalState } from 'point_of_sale.models';
import { patch } from 'web.utils';

patch(PosGlobalState.prototype, {
    async _processData(loadedData) {
        await super._processData(...arguments);
        this.evo_field = loadedData['evo.payments.session']?.[0]?.your_custom_field;
    },
});

✅ 3. Add it to the Receipt (QWeb template)

In your inherited receipt template, add:

<t t-if="pos.evo_field">
    <div>Custom Field: <t t-esc="pos.evo_field"/></div>
</t>

Avatar
Buang
Jawaban Terbai

Hii,

Python – Extend pos.order and Session Loader
models/pos_order.py


from odoo import models, fields class PosOrder(models.Model): _inherit = 'pos.order' qr_code = fields.Char(string="QR Code") # your custom field

models/pos_session.py

from odoo import models class PosSession(models.Model): _inherit = ['pos.session', 'evo.payments.session'] def _loader_params_pos_order(self): result = super()._loader_params_pos_order() result["search_params"]["fields"].append("qr_code") # <-- This is your CUSTOM_FIELD return result

qr_code is the custom field you want in the receipt. Replace it with any field you need.

JavaScript – Pass Custom Field to Receipt
static/src/js/extend_order.js


/** @odoo -module **/ import { Order } from "@point_of_sale/app/store/models"; import { patch } from "@web/core/utils/patch"; patch(Order.prototype, { export_for_printing() { const result = super.export_for_printing(); result.qr_code = this.qr_code; // must match field in Python return result; }, });

XML – Add Field to POS Receipt
views/pos_receipt_template.xml

<odoo> <template id="custom_pos_receipt_qr" inherit_id="point_of_sale.pos_ticket"> <xpath expr="//div[@class='pos-receipt-order-data']" position="inside"> <div> <strong>QR Code:</strong> <t t-esc="receipt.qr_code"/> </div> </xpath> </template> </odoo>

4. Manifest File
__manifest__.py


{ "name": "POS Custom QR Receipt", "depends": ["point_of_sale"], "assets": { "point_of_sale._assets_pos": [ "your_module_name/static/src/js/extend_order.js", ], }, "data": [ "views/pos_receipt_template.xml", ], }

i hope it is usefull

Avatar
Buang
Jawaban Terbai

1. Add the field to the POS order model (JS)

Extend the POS model using JavaScript to include the new field:

odoo.define('your_module_name.models', function (require) {

    var models = require('point_of_sale.models');


    models.load_fields('res.partner', ['customer_gstin']); // load custom field from partner


    const _super_order = models.Order.prototype;

    models.Order = models.Order.extend({

        export_for_printing: function () {

            var result = _super_order.export_for_printing.apply(this, arguments);

            result.customer_gstin = this.get_partner() ? this.get_partner().customer_gstin : '';

            return result;

        },

    });

});


2. Update the receipt template

Edit or extend the POS receipt QWeb template to include the field: 

<t t-name="PointOfSale.Ticket">

  ...

  <t t-if="receipt.customer_gstin">

    <div>GSTIN: <t t-esc="receipt.customer_gstin"/></div>

  </t>

  ...

</t>


That’s it! Now the new field will be printed on the POS receipt.

✅ Make sure your custom field exists on the partner model and is synced to the POS.

✅ Don’t forget to restart Odoo and refresh your POS screen after making changes.

Let me know if you need the same for Odoo 14, 15, 16, or 17!

Avatar
Buang
Jawaban Terbai

Hi,


Please refer to this link to know more about customizing POS receipt.


https://www.cybrosys.com/blog/how-to-customize-pos-receipts-in-the-odoo-18


Hope it helps

Avatar
Buang
Jawaban Terbai

def _loader_values_pos_order(self): 
    result = super()._loader_values_pos_order() result['search_params']['fields'].append('esd_qr_code')          return result

Avatar
Buang
Penulis Jawaban Terbai

Yes, I'd like to add a new field to the POS Receipt. It's from a brand new model, so I can't inherit a pos.session method. Do you have any guide or tutorial?


This is my code so far:


from odoo import models

classPosSession(models.Model):
_inherit = ["pos.session", "evo.payments.session"] # Evo Payments Session is my custom model

def_loader_params_evo_payments_session(self):|
"""        Loads the QR Code to the Order Receipt, calling the Evo Payments Session method        """ 
result = super().CUSTOM_FUNCTION()     
result[
"search_params"]["fields"].append(CUSTOM_FIELD)
return
result


What should I put in CUSTOM_FUNCTION() and CUSTOM_FIELD?

Avatar
Buang