Odoo Help

0

How to set value for a combobox in a method

By
E.M.
on 9/21/15, 6:20 PM 1,074 views

I have a combobox defined in res.partner:


payment_method = fields.Selection(
selection=[
('bank_transfer', 'Transferencia Bancaria'),
('check', 'Cheque'),  
('direct_debit', 'Domiciliación')
],
string='Método de pago')

I have the same combobox defined in account.invoice.

Then I have a method redefined in account.invoice to set the combobox to the value set in res.partner when partner is selected:

        @api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
payment_method = ***RETRIEVE payment_method FROM partner_id and assign to payment_method in account.invoice****
return super(account_invoice, self).onchange_partner_id(type, partner_id, date_invoice=date_invoice, payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)


How can I retrieve the value payment_method from res.partner and assign to account.invoice form payment_method?

Both combos appears fine in both forms (res.partner and account.invoice) and value at res.partner can be stored correctly, I just want to programatically assign the value from res.partner to account.invoice form.

2
Axel Mendoza
On 9/21/15, 11:54 PM

You could do it like this:

    @api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False, partner_bank_id=False, company_id=False):
result = super(account_invoice, self).onchange_partner_id(type, partner_id, date_invoice=date_invoice, payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)
if partner_id:
partner = self.env['res.partner'].browse(partner_id)
result['value']['payment_method'] = partner.payment_method
return result

Thanks a lot Axel. Not only works but also helped me to further understand how to customize Odoo.

E.M.
on 9/22/15, 5:25 PM

Happy to help

Axel Mendoza
on 9/22/15, 5:48 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 9/21/15, 6:20 PM
Seen: 1074 times
Last updated: 3/21/17, 9:18 AM