|
@ -38,12 +38,16 @@ class ResPartner(models.Model): |
|
|
required=False, |
|
|
required=False, |
|
|
store=True) |
|
|
store=True) |
|
|
|
|
|
|
|
|
|
|
|
@api.model |
|
|
|
|
|
def _get_computed_name(self, lastname, firstname): |
|
|
|
|
|
"""Write the 'name' field according to splitted data.""" |
|
|
|
|
|
return u" ".join((p for p in (lastname, firstname) if p)) |
|
|
|
|
|
|
|
|
@api.one |
|
|
@api.one |
|
|
@api.depends("firstname", "lastname") |
|
|
@api.depends("firstname", "lastname") |
|
|
def _compute_name(self): |
|
|
def _compute_name(self): |
|
|
"""Write the 'name' field according to splitted data.""" |
|
|
"""Write the 'name' field according to splitted data.""" |
|
|
self.name = u" ".join((p for p in (self.lastname, |
|
|
|
|
|
self.firstname) if p)) |
|
|
|
|
|
|
|
|
self.name = self._get_computed_name(self.lastname, self.firstname) |
|
|
|
|
|
|
|
|
@api.one |
|
|
@api.one |
|
|
def _inverse_name_after_cleaning_whitespace(self): |
|
|
def _inverse_name_after_cleaning_whitespace(self): |
|
@ -65,8 +69,8 @@ class ResPartner(models.Model): |
|
|
else: |
|
|
else: |
|
|
self._inverse_name() |
|
|
self._inverse_name() |
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
def _inverse_name(self): |
|
|
|
|
|
|
|
|
@api.model |
|
|
|
|
|
def _get_inverse_name(self, name, is_company=False): |
|
|
"""Try to revert the effect of :meth:`._compute_name`. |
|
|
"""Try to revert the effect of :meth:`._compute_name`. |
|
|
|
|
|
|
|
|
- If the partner is a company, save it in the lastname. |
|
|
- If the partner is a company, save it in the lastname. |
|
@ -78,15 +82,18 @@ class ResPartner(models.Model): |
|
|
trimmed whitespace. |
|
|
trimmed whitespace. |
|
|
""" |
|
|
""" |
|
|
# Company name goes to the lastname |
|
|
# Company name goes to the lastname |
|
|
if self.is_company or not self.name: |
|
|
|
|
|
parts = [self.name or False, False] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if is_company or not name: |
|
|
|
|
|
parts = [name or False, False] |
|
|
# Guess name splitting |
|
|
# Guess name splitting |
|
|
else: |
|
|
else: |
|
|
parts = self.name.split(" ", 1) |
|
|
|
|
|
|
|
|
parts = name.split(" ", 1) |
|
|
while len(parts) < 2: |
|
|
while len(parts) < 2: |
|
|
parts.append(False) |
|
|
parts.append(False) |
|
|
|
|
|
return parts |
|
|
|
|
|
|
|
|
|
|
|
@api.one |
|
|
|
|
|
def _inverse_name(self): |
|
|
|
|
|
parts = self._get_inverse_name(self.name, self.is_company) |
|
|
self.lastname, self.firstname = parts |
|
|
self.lastname, self.firstname = parts |
|
|
|
|
|
|
|
|
@api.one |
|
|
@api.one |
|
|