Browse Source

[MIG] partner_firstname: Migration to 13.0

14.0
Laurent Mignon (ACSONE) 5 years ago
committed by Luis Torres
parent
commit
940c03e7aa
  1. 15
      partner_firstname/migrations/12.0.1.0.0/pre-ir_config_param.py
  2. 6
      partner_firstname/models/base_config_settings.py
  3. 5
      partner_firstname/models/res_partner.py
  4. 1
      partner_firstname/models/res_users.py

15
partner_firstname/migrations/12.0.1.0.0/pre-ir_config_param.py

@ -1,15 +0,0 @@
def store_ir_config_param(cr):
"""Prior to version 12.0 the default order of partner
names was last_first. In order to retain this behaviour we
store the config parameter if it is not present.
"""
cr.execute("SELECT 1 FROM ir_config_parameter " "WHERE key = 'partner_names_order'")
if not cr.fetchone():
cr.execute(
"INSERT INTO ir_config_parameter (key, value) VALUES "
"('partner_names_order', 'last_first')"
)
def migrate(cr, version):
store_ir_config_param(cr)

6
partner_firstname/models/base_config_settings.py

@ -26,7 +26,6 @@ class ResConfigSettings(models.TransientModel):
("first_last", "Firstname Lastname"),
]
@api.multi
def _partner_names_order_default(self):
return self.env["res.partner"]._names_order_default()
@ -43,7 +42,6 @@ class ResConfigSettings(models.TransientModel):
res.update(partner_names_order=partner_names_order)
return res
@api.multi
@api.depends("partner_names_order")
def _compute_names_order_changed(self):
current = (
@ -58,19 +56,16 @@ class ResConfigSettings(models.TransientModel):
record.partner_names_order != current
)
@api.multi
@api.onchange("partner_names_order")
def _onchange_partner_names_order(self):
self._compute_names_order_changed()
@api.multi
def set_values(self):
super(ResConfigSettings, self).set_values()
self.env["ir.config_parameter"].sudo().set_param(
"partner_names_order", self.partner_names_order
)
@api.multi
def _partners_for_recalculating(self):
return self.env["res.partner"].search(
[
@ -80,7 +75,6 @@ class ResConfigSettings(models.TransientModel):
]
)
@api.multi
def action_recalculate_partners_name(self):
self.env["ir.config_parameter"].sudo().set_param(
"partner_names_order", self.partner_names_order

5
partner_firstname/models/res_partner.py

@ -49,7 +49,6 @@ class ResPartner(models.Model):
return super(ResPartner, self.with_context(context)).create(vals)
@api.multi
def copy(self, default=None):
"""Ensure partners are copied right.
@ -103,14 +102,12 @@ class ResPartner(models.Model):
else:
return " ".join(p for p in (lastname, firstname) if p)
@api.multi
@api.depends("firstname", "lastname")
def _compute_name(self):
"""Write the 'name' field according to splitted data."""
for record in self:
record.name = record._get_computed_name(record.lastname, record.firstname)
@api.multi
def _inverse_name_after_cleaning_whitespace(self):
"""Clean whitespace in :attr:`~.name` and split it.
@ -186,7 +183,6 @@ class ResPartner(models.Model):
parts.append(False)
return {"lastname": parts[0], "firstname": parts[1]}
@api.multi
def _inverse_name(self):
"""Try to revert the effect of :meth:`._compute_name`."""
for record in self:
@ -194,7 +190,6 @@ class ResPartner(models.Model):
record.lastname = parts["lastname"]
record.firstname = parts["firstname"]
@api.multi
@api.constrains("firstname", "lastname")
def _check_name(self):
"""Ensure at least one name is set."""

1
partner_firstname/models/res_users.py

@ -31,7 +31,6 @@ class ResUser(models.Model):
for rec in self:
rec.name = rec.partner_id._get_computed_name(rec.lastname, rec.firstname)
@api.multi
def copy(self, default=None):
self.ensure_one()
default = dict(default or {})

Loading…
Cancel
Save