Browse Source

Rename methods to follow guidelines.

pull/104/head
Jairo Llopis 10 years ago
parent
commit
299b4e2f5f
  1. 2
      partner_firstname/data/res_partner.yml
  2. 20
      partner_firstname/models.py

2
partner_firstname/data/res_partner.yml

@ -16,4 +16,4 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
- !function {model: res.partner, name: _firstname_install}
- !function {model: res.partner, name: _install_partner_firstname}

20
partner_firstname/models.py

@ -33,21 +33,21 @@ class ResPartner(models.Model):
firstname = fields.Char("First name") firstname = fields.Char("First name")
lastname = fields.Char("Last name") lastname = fields.Char("Last name")
name = fields.Char( name = fields.Char(
compute="_name_compute",
inverse="_name_clean_inverse",
compute="_compute_name",
inverse="_inverse_name_after_cleaning_whitespace",
required=False, required=False,
store=True) store=True)
@api.one @api.one
@api.depends("firstname", "lastname") @api.depends("firstname", "lastname")
def _name_compute(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.name = u" ".join((p for p in (self.lastname,
self.firstname) if p)) self.firstname) if p))
@api.one @api.one
def _name_clean_inverse(self):
"""Clean whitespace in ``name`` and call :meth:`._name_inverse`."""
def _inverse_name_after_cleaning_whitespace(self):
"""Clean whitespace in ``name`` and call :meth:`._inverse_name`."""
# Remove unneeded whitespace # Remove unneeded whitespace
clean = u" ".join(self.name.split(None)) clean = u" ".join(self.name.split(None))
@ -57,11 +57,11 @@ class ResPartner(models.Model):
# Save name in the real fields # Save name in the real fields
else: else:
self._name_inverse()
self._inverse_name()
@api.one @api.one
def _name_inverse(self):
"""Try to revert the effect of :meth:`._name_compute`.
def _inverse_name(self):
"""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.
- Otherwise, make a guess. - Otherwise, make a guess.
@ -91,7 +91,7 @@ class ResPartner(models.Model):
raise exceptions.EmptyNamesError(self) raise exceptions.EmptyNamesError(self)
@api.model @api.model
def _firstname_install(self):
def _install_partner_firstname(self):
"""Save names correctly in the database. """Save names correctly in the database.
Before installing the module, field ``name`` contains all full names. Before installing the module, field ``name`` contains all full names.
@ -103,5 +103,5 @@ class ResPartner(models.Model):
("lastname", "=", False)]) ("lastname", "=", False)])
# Force calculations there # Force calculations there
records._name_inverse()
records._inverse_name()
_logger.info("%d partners updated installing module.", len(records)) _logger.info("%d partners updated installing module.", len(records))
Loading…
Cancel
Save