From d7793c5fd05308a51a571b24cf2bce30aba488d8 Mon Sep 17 00:00:00 2001 From: Kalantojus Karolis Date: Wed, 18 May 2016 14:31:04 +0300 Subject: [PATCH] partner_firstname: Write in one step Both fields should be written in one go. An inline write like this causes validations to be called two times and fail at times where lastname becomes False and firstname is written only in following write. Use Case: When the intention is to change the order of firstname and lastname, the user is guided to override the _get_inverse_name. One of the simpler approaches is to switch the fields of the result returned by this function. However, this will fail for companies. At the moment lastname and firstname attributes are written, lastname will be written first (if the order is changed it will be False) leaving the record temporarily with both lastname and firstname False which raises an exception in _check_name function. --- partner_firstname/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/partner_firstname/models.py b/partner_firstname/models.py index fe2b5aa09..a07a4de1f 100644 --- a/partner_firstname/models.py +++ b/partner_firstname/models.py @@ -155,7 +155,12 @@ 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"] + values = { + "lastname": parts["lastname"], + "firstname": parts["firstname"] + } + self.write(values) + self.update(values) @api.one @api.constrains("firstname", "lastname")