1

I´ve created a module that adds some custom fields to the res.partner model and the PoS partner with a python file and a javascript file. I know both are working correctly because when I write some content in the field, the record is updated in the backend. The problem is that the PoS doesn´t show the field value. The python file that adds the field have the following form:

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

from odoo import models, fields, api

class MyModulePartner(models.Model):
    _inherit = 'res.partner'

    billing_name = fields.Char(string='Billing name')
    billing_number = fields.Char(string='Billing number')

The javascript file has the next form:

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

   var models = require('point_of_sale.models');
   var _super_posmodel = models.PosModel.prototype;

   models.PosModel = models.PosModel.extend({
   initialize: function (session, attributes) {
      var partner_model = _.find(this.models, function(model) {
           return model.model === 'res.partner';
      });
      partner_model.fields.push(['billing_name', 'billing_number']);
      return _super_posmodel.initialize.call(this, session, attributes);
      },
   });
});

Then I added the javascript file with the file "views/computerized_pos_assets_template.xml" with the following code:

<?xml version="1.0" encoding="utf-8"?>
<odoo>

   <template id="assets" inherit_id="point_of_sale.assets">
      <xpath expr="." position="inside">
         <script type="text/javascript" src="https://stackoverflow.com/my_module/static/src/js/partner.js"></script>
      </xpath>
   </template>

</odoo>

Tried to change the pos view with the file "static/src/xml/computerized_pos.xml" with the following code:

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

    <t t-extend="ClientDetailsEdit">
        <t t-jquery=".client-details-left" t-operation="replace">
            <div class='client-details-left'>
                <div class='client-detail'>
                    <span class='label'>Razón</span>
                    <input class='detail client-billing-name'           name='billing_name'     t-att-value='partner.billing_name || ""'></input>
                </div>
                <div class='client-detail'>
                    <span class='label'>Tax ID</span>
                    <input class='detail vat'           name='vat'     t-att-value='partner.vat || ""'></input>
                </div>
                <div class='client-detail'>
                    <span class='label'>Barcode</span>
                    <input class='detail barcode'       name='barcode'    t-att-value='partner.barcode || ""'></input>
                </div>
                <div class='client-detail'>
                    <span class='label'>Correo</span>
                    <input class='detail client-email'  name='email'    type='email'    t-att-value='partner.email || ""'></input>
                </div>
            </div>
        </t>
   </t>

<t t-extend="ClientDetails">
        <t t-jquery=".client-details-left" t-operation="replace">
            <div class='client-details-left'>
                <div class="client-detail">
                    <span class="label">Razón</span>
                    <t t-if='partner.billing_name'>
                        <span class="detail client-billing-name"><t t-esc="partner.billing_name"/></span>
                    </t>
                    <t t-if='!partner.billing_name'>
                        <span class="detail client-billing-name empty">N/A</span>
                    </t>
                </div>
                <div class='client-detail'>
                    <span class='label'>Barcode</span>
                    <t t-if='partner.barcode'>
                        <span class='detail client-id'><t t-esc='partner.barcode'/></span>
                    </t>
                    <t t-if='!partner.barcode'>
                        <span class='detail client-id empty'>N/A</span>
                    </t>
                </div>
                <div class='client-detail'>
                    <span class='label'>Correo</span>
                    <t t-if='partner.email'>
                        <span class='detail client-email'><t t-esc='partner.email' /></span>
                    </t>
                    <t t-if='!partner.email'>
                        <span class='detail client-email empty'>N/A</span>
                    </t>
                </div>
            </div>
        </t>
   </t>

And finally in the manifest file I´ve added the files like the following:

'data': [
        'views/computerized_pos_assets_template.xml',
    ],
    'qweb': [
        'static/src/xml/computerized_pos.xml',
    ],

Something that I´ve noticed is that when in the "views/computerized_pos_assets_template.xml" I detail the javascript file location like "/my_module/static/src/js/partner.js" Odoo throws the following error:

Traceback (most recent call last):
  File "/opt/odoo/odoo13/odoo/http.py", line 619, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo13/odoo/http.py", line 309, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo/odoo13/odoo/tools/pycompat.py", line 14, in reraise
    raise value
  File "/opt/odoo/odoo13/odoo/http.py", line 664, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo13/odoo/http.py", line 345, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo13/odoo/service/model.py", line 93, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo13/odoo/http.py", line 338, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo13/odoo/http.py", line 910, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo13/odoo/http.py", line 510, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo13/addons/web/controllers/main.py", line 1320, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/odoo13/addons/web/controllers/main.py", line 1312, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo13/odoo/api.py", line 383, in call_kw
    result = _call_kw_model(method, model, args, kwargs)
  File "/opt/odoo/odoo13/odoo/api.py", line 356, in _call_kw_model
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/odoo13/odoo/models.py", line 4845, in search_read
    result = records.read(fields)
  File "/opt/odoo/odoo13/odoo/models.py", line 2877, in read
    fields = self.check_field_access_rights('read', fields)
  File "/opt/odoo/odoo13/odoo/models.py", line 2809, in check_field_access_rights
    invalid_fields = {name for name in fields if not valid(name)}
  File "/opt/odoo/odoo13/odoo/models.py", line 2809, in <setcomp>
    invalid_fields = {name for name in fields if not valid(name)}
  File "/opt/odoo/odoo13/odoo/models.py", line 2800, in valid
    field = self._fields.get(fname)
TypeError: unhashable type: 'list'

But when the location is "/static/src/js/partner.js" I get the following error:

point_of_sale.assets.js:477 Could not get content for /static/src/js/partner.js defined in bundle 'point_of_sale.assets'.
2
  • 1
    Try to load fields like this :- models.load_fields("res.partner", ["billing_name", "document_number"]); Commented Mar 25, 2020 at 2:51
  • It´s even easier, thank you @VishnuVaNnErI Commented Mar 28, 2020 at 16:50

1 Answer 1

1

I´ve realized that the function I used to push fields doesn´t support lists, so after I corrected the js file like the following, the field worked correcly:

odoo.define('kyohei_pos_computerized_billing.partner', function (require) {
    "use strict";

    var models = require('point_of_sale.models');
    var super_posmodel = models.PosModel.prototype;

    models.PosModel = models.PosModel.extend({
        initialize: function (session, attributes) {
            var partner_model = _.find(this.models, function (model){
                return model.model === 'res.partner';
            });
            partner_model.fields.push('billing_name');
            return super_posmodel.initialize.call(this, session, attributes);
        },
    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

What version of Odoo is this and would this work for version 14?
This used to work on Odoo 13. In Odoo 14 OWL appeared and this doesn´t work.
It actually still works, you're a lifesaver! Would you by any chance know how I can automatically append a product to the orderline and set a custom price on the appended product (on click of like a custom button)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.