我创建了一个模块,向 res.partner 模型和 PoS 合作伙伴添加了一些自定义字段,其中包含一个 python 文件和一个 javascript 文件。我知道两者都正常工作,因为当我在字段中编写一些内容时,记录会在后端更新。问题是 PoS 不显示字段值。添加该字段的 python 文件具有以下形式:
# -*- 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')
javascript 文件具有以下形式:
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);
},
});
});
然后我使用以下代码添加了带有文件“views/computerized_pos_assets_template.xml”的javascript文件:
<?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="/my_module/static/src/js/partner.js"></script>
</xpath>
</template>
</odoo>
尝试使用以下代码使用文件“static/src/xml/computerized_pos.xml”更改 pos 视图:
<?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>
最后在清单文件中,我添加了如下文件:
'data': [
'views/computerized_pos_assets_template.xml',
],
'qweb': [
'static/src/xml/computerized_pos.xml',
],
我注意到的是,在“views/computerized_pos_assets_template.xml”中,我详细说明了 javascript 文件位置,如“/my_module/static/src/js/partner.js”,Odoo 抛出以下错误:
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'
但是当位置是“/static/src/js/partner.js”时,我收到以下错误:
point_of_sale.assets.js:477 Could not get content for /static/src/js/partner.js defined in bundle 'point_of_sale.assets'.