This question has been flagged
1 Reply
6476 Views

I need to call a field of a different model into the POS Receipt (POS-Ticket), 'pos.xml' in  static folder.

So far, I've come to know that its possible through 'model.js', but a syntax or documentation would really help.

Avatar
Discard
Best Answer

Hi,

 To call new model in pos you must define it first in model.js like this:

odoo.define('your_module.models', function (require) {    
"use strict";
var models = require('point_of_sale.models');
models.load_models({   
model: 'your.model', # your model
fields: ['field1','field1'], // fields that will be used from your model
domain: [], // domain filter
loaded: function(self,objs){    
// a function that will be executed on loading   
self.objs = objs;},});
});

you can now call your model in PosTicket xml by :

<t t-esc="widget.pos.objs.field1" />
<t t-esc="widget.pos.objs.field2" />

 Best regards.

Avatar
Discard
Author

Thanks. Can you please let me know, where exactly to paste the above code in models.js?

If you are working on new module, create a file models.js under your_module/static/src/js.

After that inherit the point_of_sale.index to call it:

<template id="report_extend" name="POS Index" inherit_id="point_of_sale.index"><xpath expr="." position="inside">

<script type="text/javascript" src="/your_module/static/src/js/models.js"></script>

</xpath>

</template>

Welcome.