diff --git a/partner_firstname/models.py b/partner_firstname/models.py index 39836e712..48342b20d 100644 --- a/partner_firstname/models.py +++ b/partner_firstname/models.py @@ -38,6 +38,21 @@ class ResPartner(models.Model): required=False, store=True) + @api.model + def create(self, vals): + """Add inverted names at creation if unavailable.""" + if "name" in vals: + inverted = self._get_inverse_name( + vals.get("name"), + vals.get("is_company", + self.default_get(["is_company"])["is_company"])) + + for key, value in inverted.iteritems(): + if not vals.get(key): + vals[key] = value + + return super(ResPartner, self).create(vals) + @api.model def default_get(self, fields_list): """Invert name when getting default values."""