Browse Source

[REF] partner_firstname: Support duplicate multiple names

Considering following name:

    firstname = Francisco Javier
    lastname = Garcia
    second_lastname = Cabeza de Vaca

    When duplicate:

    firstname = de Vaca Francisco Javier (copy)
    lastname = Garcia
    second_lastname = Cabeza

    It is inverted based on the 'name' and changed the order of the fields

    But when we are duplicating a contact we don't need to recompute the names since that it should be duplicated as it

    Video:

    https://youtu.be/CEFik5COK18
14.0
Fernanda Hernández 3 years ago
committed by Moises Lopez moylop260@vauxoo.com
parent
commit
5ede092b86
  1. 12
      partner_firstname/models/res_partner.py
  2. 7
      partner_firstname/tests/base.py

12
partner_firstname/models/res_partner.py

@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import api, fields, models
from odoo import _, api, fields, models
from .. import exceptions
@ -30,6 +30,12 @@ class ResPartner(models.Model):
def create(self, vals):
"""Add inverted names at creation if unavailable."""
context = dict(self.env.context)
is_contact_copied = (
context.get("copy") and vals.get("firstname") and not vals.get("is_company")
)
if is_contact_copied and "name" in vals:
vals.pop("name", None)
context.pop("default_name", None)
name = vals.get("name", context.get("default_name"))
if name is not None:
@ -57,6 +63,10 @@ class ResPartner(models.Model):
ignored in :meth:`~.create` because it also copies explicitly firstname
and lastname fields.
"""
if default is None:
default = {}
if self.firstname and not self.is_company:
default["firstname"] = _("%s (copy)", self.firstname)
return super(ResPartner, self.with_context(copy=True)).copy(default)
@api.model

7
partner_firstname/tests/base.py

@ -49,8 +49,11 @@ class BaseCase(TransactionCase, MailInstalled):
def test_copy(self):
"""Copy the partner and compare the result."""
self.expect("%s (copy)" % self.lastname, self.firstname)
self.changed = self.original.with_context(copy=True, lang="en_US").copy()
self.changed = self.original.with_context(lang="en_US").copy()
if self.changed.is_company:
self.expect("%s (copy)" % self.lastname, self.firstname)
else:
self.expect(self.lastname, "%s (copy)" % self.firstname)
def test_one_name(self):
"""Test what happens when only one name is given."""

Loading…
Cancel
Save