I am trying to set a conditional default for the field 'Fiscal Position' (.property_account_position_id) in res.partner model based on the Country (country_id) selected for that contact. If Country is "United States (233)", Fiscal Position is "Fiscal Position for United States (3)"; else Fiscal Position is "International (5)"
Can someone tell me what I am doing wrong?
# -*- coding: utf-8 -*-
from odoo import api, fields, models
class ResPartner(models.Model):
_name = ‘res.partner’
_inherit = ‘res.partner’
country_id = fields.Many2one(‘res.country’, string=‘Country’,
help=“Apply only if delivery or invoicing country match.“)
property_account_position_id = fields.Many2one(‘account.fiscal.position’, company_dependent=True,
string=“Fiscal Position”,help=“The fiscal position will determine taxes and accounts used for the partner.“,oldname=“property_account_position”,readonly=False)
@api.onchange(‘country_id’)
def assign_fiscal_position(self):
for record in self:if record.country_id == 233:
record.property_account_position_id = 3
else:
record.property_account_position_id = 5