Browse Source

Bug fix when copying partners

14.0
Wolfgang Pichler 6 years ago
committed by Luis Torres
parent
commit
4c863dbe0c
  1. 18
      partner_firstname/models/res_users.py
  2. 1
      partner_firstname/tests/__init__.py
  3. 52
      partner_firstname/tests/test_copy.py

18
partner_firstname/models/res_users.py

@ -3,11 +3,7 @@
# © 2014 Agile Business Group (<http://www.agilebg.com>)
# © 2015 Grupo ESOC (<http://www.grupoesoc.es>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import api, models
_logger = logging.getLogger(__name__)
from odoo import api, models, _
class ResUser(models.Model):
@ -35,3 +31,15 @@ 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 {})
if ('name' not in default) and ('partner_id' not in default):
default['name'] = _("%s (copy)") % self.name
if 'login' not in default:
default['login'] = _("%s (copy)") % self.login
if ('firstname' not in default) and ('lastname' not in default) and ('name' in default):
default.update(self.env['res.partner']._get_inverse_name(default['name'], False))
return super(ResUser, self).copy(default)

1
partner_firstname/tests/__init__.py

@ -11,4 +11,5 @@ from . import (
test_onchange,
test_user_onchange,
test_order,
test_copy,
)

52
partner_firstname/tests/test_copy.py

@ -0,0 +1,52 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
"""Test copy function for models."""
from odoo.tests.common import TransactionCase
from .base import MailInstalled
class UserCase(TransactionCase, MailInstalled):
"""Test ``res.users``."""
def setUp(self):
super(UserCase, self).setUp()
self.create_original()
def create_original(self):
self.original = self.env["res.users"].create({
"firstname": u"Firstname",
"lastname": u"Lastname",
"name": u"Firstname Lastname",
"login": u"firstname.lastname"
})
def tearDown(self):
super(UserCase, self).tearDown()
def compare(self, copy):
self.assertEqual(copy.lastname, u"Lastname2")
self.assertEqual(copy.firstname, u"Firstname2")
self.assertEqual(copy.name, u"Firstname2 Lastname2")
def test_copy_name(self):
"""Copy original with default name set - firstname lastname not set."""
copy = self.original.copy({
"name": u"Firstname2 Lastname2"
})
self.compare(copy)
def test_copy_firstname_lastname(self):
"""Copy original with default firstname and lastname set"""
copy = self.original.copy({
"firstname": u"Firstname2",
"lastname": u"Lastname2"
})
self.compare(copy)
def test_copy_firstname_lastname_name(self):
"""Copy original with default firstname, lastname and name set"""
copy = self.original.copy({
"firstname": u"Firstname2",
"lastname": u"Lastname2",
"name": u"Firstname2 Lastname2"
})
self.compare(copy)
Loading…
Cancel
Save