Browse Source

[FIX] Avoid writes if no changes in name, firstname, lastname ...

pull/289/head
Antonio Espinosa 9 years ago
parent
commit
51c4c6088b
  1. 12
      partner_firstname/models/res_partner.py
  2. 11
      partner_second_lastname/models/res_partner.py

12
partner_firstname/models/res_partner.py

@ -189,7 +189,10 @@ class ResPartner(models.Model):
def _inverse_name(self):
"""Try to revert the effect of :meth:`._compute_name`."""
parts = self._get_inverse_name(self.name, self.is_company)
self.lastname, self.firstname = parts["lastname"], parts["firstname"]
if parts["lastname"] != self.lastname:
self.lastname = parts["lastname"]
if parts["firstname"] != self.firstname:
self.firstname = parts["firstname"]
@api.one
@api.constrains("firstname", "lastname")
@ -236,3 +239,10 @@ class ResPartner(models.Model):
# Force calculations there
records._inverse_name()
_logger.info("%d partners updated installing module.", len(records))
@api.multi
def write(self, vals):
if vals.get('name') == self.name:
vals.pop('name', None)
if vals:
return super(ResPartner, self).write(vals)

11
partner_second_lastname/models/res_partner.py

@ -45,9 +45,8 @@ class ResPartner(models.Model):
@api.depends("firstname", "lastname", "lastname2")
def _compute_name(self):
"""Write :attr:`~.name` according to splitted data."""
self.name = self._get_computed_name(self.lastname,
self.firstname,
self.lastname2)
self.name = self._get_computed_name(
self.lastname, self.firstname, self.lastname2)
@api.one
def _inverse_name(self):
@ -58,8 +57,10 @@ class ResPartner(models.Model):
before, after = dict(), dict()
for key, value in parts.iteritems():
(before if value else after)[key] = value
self.update(before)
self.update(after)
if any([before[k] != self[k] for k in before.keys()]):
self.update(before)
if any([after[k] != self[k] for k in after.keys()]):
self.update(after)
@api.model
def _get_inverse_name(self, name, is_company=False):

Loading…
Cancel
Save