扩展 JS web 模块 Odoo PoS

Extend JS web module Odoo PoS

我想扩展models.js文件中的JS模块PosModel(模型是point_of_sale)。这是因为我想在下面添加一个字段:

models: [
     ...
     model:  'res.partner',
        fields: ['name','street',..,'MY_NEW_FIELD'],

我已经在 static > src > js > models_extend.js 下向我的模块添加了一个新的 js 文件 并将此文件添加到 xml 模板中,如下所示:

<template id="assets_backend" name="dewieuw assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/dewieuw/static/src/js/models_extend.js"></script>
        </xpath>
</template> 

这在我的 models_extend.js 文件中:

function openerp_pos_models(instance, module){ //module is instance.point_of_sale
var QWeb = instance.web.qweb;
var _t = instance.web._t;

var round_di = instance.web.round_decimals;
var round_pr = instance.web.round_precision   

module.PosModel = module.PosModel.extend({
       "Here is the same is in the original file, except for the following line"
{
        model:  'res.partner',
        fields: ['name','street','city','state_id','country_id','vat','phone','zip','mobile','email','ean13','write_date','MY_NEW_FIELD'],
        domain: [['customer','=',true]],
        loaded: function(self,partners){
            self.partners = partners;
            self.db.add_partners(partners);
        },
    },

由于某种原因从未添加新字段,我认为这是因为他没有用我的模块扩展模块?任何想法请。

您的 JS 定义必须包含要加载的自定义模块名称。

如果您查看 official docs,您会发现 您的 JS 必须声明您的模块范围

In Odoo web, modules are declared as functions set on the global openerp variable. The function's name must be the same as the addon (in this case oepetstore) so the framework can find it, and automatically initialize it.

所以,如果你的模块被命名为 oepetstore,你会得到这样的东西:

openerp.oepetstore = function(instance, local) {

在你的情况下,我猜它会是 openerp.dewieuw

提示:执行此操作并简单地添加 console.logalert('foo') 以确保它已加载。