Reputation: 769
I want to extend the JS module PosModel in the models.js file (model is point_of_sale). This because I would like to add a field under:
models: [
...
model: 'res.partner',
fields: ['name','street',..,'MY_NEW_FIELD'],
I already added a new js file to my module under static > src > js > models_extend.js And added this file to the xml template like so:
<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>
This is in my models_extend.js file:
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);
},
},
For some reason the new field is never added, I think this because he doesn't extend the module with my module? Any ideas pls.
Upvotes: 0
Views: 2442
Reputation: 2431
Your JS definition must include your custom module name to be loaded.
If you look at the official docs you see that your JS must declare your module scope.
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.
So, if your module is named oepetstore
you get something like this:
openerp.oepetstore = function(instance, local) {
In your case I guess it would be openerp.dewieuw
.
Tip: do this and simply add a console.log
or alert('foo')
to make sure it gets loaded.
Upvotes: 1