Simon Capriles
Simon Capriles

Reputation: 183

Odoo PoS not showing custom fields in receipts

I´ve added a field in the 'res.company' model and i´m trying to add them to the receipt, but they are not showing up. I´ve added the fields with the next python file:

# -*- coding: utf-8 -*-

from odoo import models, fields, api, exceptions


class MyModuleCompany(models.Model):
    _inherit = 'res.company'

    branch_code = fields.Integer(string='Branch code')

Then added the fields in the POS company model with the next code:

odoo.define('my_module.company', function (require) {
    "use strict";

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

    models.load_fields('res.company', [
        'branch_code'
    ]);

});

Finally, I tried to make them appear in the receipt with the next xml code:

<?xml version="1.0" encoding="UTF-8"?>
<template xml:space="preserve">

    <t t-extend="OrderReceipt">
        <t t-jquery=".pos-receipt-contact" t-operation="replace">
            <div class="pos-receipt-contact">
                <t t-if='receipt.company.name'>
                    <div><t t-esc='receipt.company.name' /></div>
                </t>
                <t t-if='receipt.company.branch_code'>
                    <div>Branch:<t t-esc='receipt.company.branch_code' /></div>
                </t>
            </div>
        </t>
    </t>

</template>

The field "name" appears but for some reason the "branch" field does not and I can´t find out why.

Upvotes: 0

Views: 1214

Answers (1)

Kenly
Kenly

Reputation: 26748

It is already inherited in l10n_fr_pos_cert module.

I can see the difference in the header of the XML file. They used:

<templates id="template" xml:space="preserve">

 
EDIT:

You successfully added the field to the posmodel (pos variable) and you need just to make that value accessible in the receipt.

var models = require('point_of_sale.models');
var _super_ordermodel = models.Order.prototype;

models.Order = models.Order.extend({
    export_for_printing: function(){
        var receipt = _super_ordermodel.export_for_printing.apply(this, arguments);
        receipt.company.branch_code = this.pos.company.branch_code;
        return receipt;
    },
});

Upvotes: 1

Related Questions