Odoo v12 Add more data to many2one field in recordData javascript

Viewed 152

The recordData object in javascript has all the fields data. In 'account.invoice' this is the object:

Invoice Form

Invoice Javascript recordData

The Many2one fields data:

res.partner Many2one data

The "data" only has "display_name" and "id", but i need "vat" field.

Is there a way to get more fields?

My first option is a rpc to get the partner data using the id (this.recordData.partner_id.data.id), i tried and it works.

var def = this._rpc({
    model: 'res.partner',
    method: 'search_read',
    domain: [
        ['id', '=', this.recordData.partner_id.data.id]
    ],
}).then(function (result) {
    partner_data = result[0];
});

My second option is a related field, also works.

partner_vat = fields.Char(related='partner_id.vat')

But i want to know if i can avoid this rpc call and avoid create a new related field.

Thanks.

1 Answers

When you call search_read, you can specify fields param in your _rpc call. For example:

var def = this._rpc({
    model: 'res.partner',
    method: 'search_read',
    domain: [
        ['id', '=', this.recordData.partner_id.data.id]
    ],
    fields: ['id', 'vat'],
}).then(function (result) {
    partner_data = result[0];
});
Related