Search code examples
odoo-10

Odoo 10 :Adding field in templates by inheritance



I want to add "default_code" field in addons/point_of_sale/static/src/xml by inheriting it in my custom_module.
But getting these erros when Installing/Upgrading my custom module.
Here is my code :

<?xml version="1.0" encoding="UTF-8"?>
<templates id="pos_inh" xml:space="preserve">
    <t t-name="ProductRef" t-extends="Product">
       <t t-jquery='.product-name' t-operation='inside'>
          <span t-esc="product.default_code"/>
       </t>
    </t>
</templates>

And here is the code where I want to add the default_code field :

<t t-name="Product">
    <span class='product' t-att-data-product-id="product.id">
        <div class="product-img">
            <img t-att-src='image_url' /> 
            <t t-if="!product.to_weight">
                <span class="price-tag">
                    <t t-esc="widget.format_currency(product.price,'Product Price')"/>
                </span>
            </t>
            <t t-if="product.to_weight">
                <span class="price-tag">
                    <t t-esc="widget.format_currency(product.price,'Product Price')+'/'+widget.pos.units_by_id[product.uom_id[0]].name"/>
                </span>
            </t>
        </div>
        <div class="product-name">
            <t t-esc="product.display_name"/>
        </div>
    </span>
</t>

Can you help me? Thank you very much


Solution

  • After some digging on odoo/Apps, I find a module that do something similare, so I just copy, paste and modify the code to do what I need. So, here is the code :

    <?xml version="1.0" encoding="UTF-8"?>
    
        <templates id="template" xml:space="preserve">
            <t t-extend="Product" name="ProductStockWidget">
                <t t-jquery="div.product-name" t-operation="append">
                    <t t-if="product.default_code">
                        <br/>
                        [<t t-esc="product.default_code"/>]
                    </t>
               </t>
           </t>
    
       </templates>
    

    And the jquery code is :

    odoo.define('pos_ref_articles', function (require) {
    
    "use strict";
    
    var module = require('point_of_sale.models');
    
    var models = module.PosModel.prototype.models;
    
    for (var i = 0; i < models.length; i++) {
    
        var model = models[i];
    
        if (model.model === 'product.product') {
    
            model.fields.push('default_code');
    
        }
    
    }
    
    });