odoopoint-of-saleodoo-16odoo-17odoo-18

Inheriting POS Self Order Product Card Template in Odoo 18: Custom Fields Not Showing


I am working with Odoo 18 and have added custom fields to the POS self-order product card. Specifically, I added **preparation_time **and **short_description **fields to the product.template and product.product models. When I directly modify the source code template, the custom fields display correctly on the product card. However, when I try to inherit the template in my custom module, the fields do not show up.

Manifest:

{
    'name': 'Self Order Customisation',
    'version': '18.0.1.0.0',
    'summary': 'Self Order Customisation',
    'license': 'LGPL-3',
    'depends': ['base', 'product', 'stock', 'pos_self_order'],

    'data': [
        'views/product_template.xml',
    ],
    'assets': {
        'point_of_sale.assets': [
            'self_order_customisation/static/src/xml/pos_product_card.xml',
        ],
    },

    'installable': True,
    'auto_install': False,
}

Python file to load field to POS:

class ProductTemplate(models.Model):
    _inherit = 'product.template'

    preparation_time = fields.Char(string='Preparation Time')
    short_description = fields.Char(string='Short Description')


class ProductProduct(models.Model):
    _inherit = 'product.product'

    preparation_time = fields.Char(related='product_tmpl_id.preparation_time', store=True)
    short_description = fields.Char(related='product_tmpl_id.short_description', store=True)

    @api.model
    def _load_pos_data_fields(self, config_id):
        data = super()._load_pos_data_fields(config_id)
        data += ['short_description', 'preparation_time']
        return data

Custom template XML

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

<t t-inherit="pos_self_order.ProductCard" t-inherit-mode="extension">
    <xpath expr="//article/div[hasclass('product-infos')]/span[t-esc='props.product.name']" position="after">

        <span class="mt-2"><t t-if="props.product.short_description" t-esc="props.product.short_description" /></span>
        <t t-if="props.product.preparation_time">
            <span class="mt-2 mb-2">Preparation Time: <t t-esc="props.product.preparation_time" /></span>
        </t>

    </xpath>
</t>
</templates>

The fields do not show up, even though they work when I directly modify the source code template.


Solution

  • I looked into this issue, and it seems that your manifest is not loading your custom template because the original template you are trying to inherit is in the pos_self_order module. The original template is loaded via pos_self_order.assets in its manifest. Therefore, you should also use the same asset bundle in your manifest. Your manifest should look like this:

    'assets': {
    'pos_self_order.assets': [
        'self_order_customisation/static/src/product_card/pos_product_card.xml',
    ],
    

    }

    Otherwise, the template will not be loaded correctly.