[FIX] event: convert related country_id field to compute field
authorDenis Ledoux <dle@odoo.com>
Thu, 16 Oct 2014 09:14:39 +0000 (11:14 +0200)
committerDenis Ledoux <dle@odoo.com>
Thu, 16 Oct 2014 09:15:34 +0000 (11:15 +0200)
To avoid being able to change the country of the address (res.partner) from this field

addons/event/event.py

index 270e73c..9aab9b8 100644 (file)
@@ -139,6 +139,11 @@ class event_event(models.Model):
         else:
             self.date_end_located = False
 
+    @api.one
+    @api.depends('address_id')
+    def _compute_country(self):
+        self.country_id = self.address_id.country_id
+
     date_begin_located = fields.Datetime(string='Start Date Located', compute='_compute_date_begin_tz')
     date_end_located = fields.Datetime(string='End Date Located', compute='_compute_date_end_tz')
 
@@ -163,8 +168,8 @@ class event_event(models.Model):
     address_id = fields.Many2one('res.partner', string='Location',
         default=lambda self: self.env.user.company_id.partner_id,
         readonly=False, states={'done': [('readonly', True)]})
-    country_id = fields.Many2one('res.country', string='Country', related='address_id.country_id',
-        store=True, readonly=False, states={'done': [('readonly', True)]})
+    country_id = fields.Many2one('res.country', string='Country',
+        store=True, compute='_compute_country')
     description = fields.Html(string='Description', oldname='note', translate=True,
         readonly=False, states={'done': [('readonly', True)]})
     company_id = fields.Many2one('res.company', string='Company', change_default=True,