Skip to Content
Menu
This question has been flagged

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.

Avatar
Discard
Best Answer

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
Avatar
Discard
Author

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

Happy to help

Related Posts Replies Views Activity
1
May 21
2863
4
Oct 19
8647
1
Jan 18
7891
1
Feb 17
3899
0
Jan 17
3405