Browse Source

Merge PR #1126 into 14.0

Signed-off-by yajo
14.0
OCA-git-bot 2 years ago
parent
commit
40103d0394
  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