From 0d3b5087a8c95fc6a53c2810c3c17405f34edbab Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Fri, 20 Apr 2018 06:48:13 +0200 Subject: [PATCH] [IMP] base_location: Include onchange for state Incredibly not included in Odoo core. --- base_location/__openerp__.py | 3 ++- base_location/models/company.py | 6 ++++++ base_location/models/partner.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/base_location/__openerp__.py b/base_location/__openerp__.py index ab99a039d..1d4810eba 100644 --- a/base_location/__openerp__.py +++ b/base_location/__openerp__.py @@ -1,9 +1,10 @@ # Copyright 2016 Nicolas Bessi, Camptocamp SA +# Copyright 2018 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Location management (aka Better ZIP)', - 'version': '11.0.1.0.0', + 'version': '11.0.1.0.1', 'depends': [ 'base_address_city' ], diff --git a/base_location/models/company.py b/base_location/models/company.py index 3c0e78560..1016a1d23 100644 --- a/base_location/models/company.py +++ b/base_location/models/company.py @@ -1,4 +1,5 @@ # Copyright 2016 Nicolas Bessi, Camptocamp SA +# Copyright 2018 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields, api @@ -62,3 +63,8 @@ class ResCompany(models.Model): self.state_id = self.city_id.state_id else: self.state_id = self.zip_id.state_id + + @api.onchange('state_id') + def onchange_state_id(self): + if self.state_id.country_id: + self.country_id = self.state_id.country_id.id diff --git a/base_location/models/partner.py b/base_location/models/partner.py index 61e172920..befddd1ff 100644 --- a/base_location/models/partner.py +++ b/base_location/models/partner.py @@ -1,4 +1,5 @@ # Copyright 2016 Nicolas Bessi, Camptocamp SA +# Copyright 2018 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api, fields, models, _ @@ -64,3 +65,8 @@ class ResPartner(models.Model): raise ValidationError(_( "The city of partner %s differs from that in " "location %s") % (rec.name, rec.zip_id.name)) + + @api.onchange('state_id') + def onchange_state_id(self): + if self.state_id.country_id: + self.country_id = self.state_id.country_id.id