Calling Javascript and get data in models from button in Odoo
Calling Javascript from button in Odoo and obtain records data from model seems simple but made me crazy for some subtle details and messy documentation.
Maybe this is not the perfect way to do it but finally i’ve found it (any suggestion will be appreciate)
The first problem is in obtaing data from current model and relational fields.
I’ve made it with some data taken directly from record.data in javascript and some others in python code with @api.model directives.
This is the code i’ve used for .py
@api.model def get_all_data(self,partner_id, pick_id, company_id,contract_id): packs = 0 result = {} res_ids = self.env['res.partner'].search([['id', '=', partner_id]]) for p in res_ids: result['name'] = p.name result['street'] = p.street result['street2'] = p.street2 result['zip'] = p.zip result['city'] = p.city return(result)
and this for .js
FormController.include({_onButtonClicked: function (event) { if(event.data.attrs['name'] == 'gls_call') { var partner_id = record.data.partner_id.data.id; rpc.query({ model: 'stock.picking', method: 'get_all_data', args: [partner_id,pick_id,company_id,contract_id], }).then(function(res) { var Street= res.street })
Hope all of this can be of any help for someone catching with the same problem!
Un commento su “Calling Javascript and get data in models from button in Odoo”