Skip to content

Commit

Permalink
[IMP] base_location: Include onchange for state
Browse files Browse the repository at this point in the history
Incredibly not included in Odoo core.
  • Loading branch information
pedrobaeza committed May 15, 2018
1 parent 12b28a5 commit 6c2c615
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base_location/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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'
],
Expand Down
6 changes: 6 additions & 0 deletions base_location/models/company.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -62,3 +63,8 @@ def _onchange_zip_id(self):
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
6 changes: 6 additions & 0 deletions base_location/models/partner.py
Original file line number Diff line number Diff line change
@@ -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, _
Expand Down Expand Up @@ -64,3 +65,8 @@ def _check_zip(self):
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

0 comments on commit 6c2c615

Please sign in to comment.