Browse Source
Merge pull request #238 from yvaucher/9.0-port-partner-firstname
Merge pull request #238 from yvaucher/9.0-port-partner-firstname
[9.0] [PORT] partner_firstnamepull/231/merge
Pedro M. Baeza
9 years ago
16 changed files with 403 additions and 205 deletions
-
17partner_firstname/README.rst
-
21partner_firstname/__init__.py
-
34partner_firstname/__openerp__.py
-
21partner_firstname/exceptions.py
-
5partner_firstname/models/__init__.py
-
107partner_firstname/models/res_partner.py
-
30partner_firstname/models/res_user.py
-
39partner_firstname/tests/__init__.py
-
30partner_firstname/tests/base.py
-
82partner_firstname/tests/test_create.py
-
65partner_firstname/tests/test_defaults.py
-
38partner_firstname/tests/test_delete.py
-
48partner_firstname/tests/test_empty.py
-
3partner_firstname/tests/test_onchange.py
-
64partner_firstname/views/res_partner.xml
-
4partner_firstname/views/res_user.xml
@ -1,21 +1,4 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
# Author: Nicolas Bessi. Copyright Camptocamp SA |
|||
# Copyright (C) |
|||
# 2014: Agile Business Group (<http://www.agilebg.com>) |
|||
# 2015: Grupo ESOC <www.grupoesoc.es> |
|||
# |
|||
# This program is free software: you can redistribute it and/or modify |
|||
# it under the terms of the GNU Affero General Public License as |
|||
# published by the Free Software Foundation, either version 3 of the |
|||
# License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU Affero General Public License for more details. |
|||
# |
|||
# 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/>. |
|||
|
|||
# © 2013 Nicolas Bessi (Camptocamp SA) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import models |
@ -0,0 +1,5 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2013 Nicolas Bessi (Camptocamp SA) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
from . import res_partner |
|||
from . import res_user |
@ -0,0 +1,30 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2013 Nicolas Bessi (Camptocamp SA) |
|||
# © 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 openerp import api, models |
|||
|
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class ResUser(models.Model): |
|||
_inherit = 'res.users' |
|||
|
|||
@api.model |
|||
def default_get(self, fields_list): |
|||
"""Invert name when getting default values.""" |
|||
result = super(ResUser, self).default_get(fields_list) |
|||
|
|||
partner_model = self.env['res.partner'] |
|||
inverted = partner_model._get_inverse_name( |
|||
partner_model._get_whitespace_cleaned_name(result.get("name", "")), |
|||
result.get("is_company", False)) |
|||
|
|||
for field in inverted.keys(): |
|||
if field in fields_list: |
|||
result[field] = inverted.get(field) |
|||
|
|||
return result |
@ -1,31 +1,12 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################## |
|||
# |
|||
# Authors: Nemry Jonathan |
|||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu) |
|||
# All Rights Reserved |
|||
# |
|||
# WARNING: This program as such is intended to be used by professional |
|||
# programmers who take the whole responsibility of assessing all potential |
|||
# consequences resulting from its eventual inadequacies and bugs. |
|||
# End users who are looking for a ready-to-use solution with commercial |
|||
# guarantees and support are strongly advised to contact a Free Software |
|||
# Service Company. |
|||
# |
|||
# This program is Free Software; you can redistribute it and/or |
|||
# modify it under the terms of the GNU General Public License |
|||
# as published by the Free Software Foundation; either version 2 |
|||
# of the License, or (at your option) any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|||
# |
|||
############################################################################## |
|||
# © 2014 Nemry Jonathan (Acsone SA/NV) (http://www.acsone.eu) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import test_empty, test_name, test_onchange |
|||
from . import ( |
|||
test_create, |
|||
test_defaults, |
|||
test_delete, |
|||
test_empty, |
|||
test_name, |
|||
test_onchange |
|||
) |
@ -0,0 +1,82 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L. - Jairo Llopis. |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
"""Test default values for models.""" |
|||
|
|||
from openerp.tests.common import TransactionCase |
|||
from .base import MailInstalled |
|||
|
|||
|
|||
class PersonCase(TransactionCase): |
|||
"""Test ``res.partner`` when it is a person.""" |
|||
context = {"default_is_company": False} |
|||
model = "res.partner" |
|||
|
|||
def setUp(self): |
|||
super(PersonCase, self).setUp() |
|||
self.good_values = { |
|||
"firstname": u"Núñez", |
|||
"lastname": u"Fernán", |
|||
} |
|||
self.good_values["name"] = "%s %s" % (self.good_values["lastname"], |
|||
self.good_values["firstname"]) |
|||
if "default_is_company" in self.context: |
|||
self.good_values["is_company"] = self.context["default_is_company"] |
|||
self.values = self.good_values.copy() |
|||
|
|||
def tearDown(self): |
|||
self.record = (self.env[self.model] |
|||
.with_context(self.context) |
|||
.create(self.values)) |
|||
|
|||
for key, value in self.good_values.iteritems(): |
|||
self.assertEqual( |
|||
self.record[key], |
|||
value, |
|||
"Checking key %s" % key) |
|||
|
|||
super(PersonCase, self).tearDown() |
|||
|
|||
def test_no_name(self): |
|||
"""Name is calculated.""" |
|||
del self.values["name"] |
|||
|
|||
def test_wrong_name_value(self): |
|||
"""Wrong name value is ignored, name is calculated.""" |
|||
self.values["name"] = u"BÄD" |
|||
|
|||
def test_wrong_name_context(self): |
|||
"""Wrong name context is ignored, name is calculated.""" |
|||
del self.values["name"] |
|||
self.context["default_name"] = u"BÄD" |
|||
|
|||
def test_wrong_name_value_and_context(self): |
|||
"""Wrong name value and context is ignored, name is calculated.""" |
|||
self.values["name"] = u"BÄD1" |
|||
self.context["default_name"] = u"BÄD2" |
|||
|
|||
|
|||
class CompanyCase(PersonCase): |
|||
"""Test ``res.partner`` when it is a company.""" |
|||
context = {"default_is_company": True} |
|||
|
|||
def setUp(self): |
|||
super(CompanyCase, self).setUp() |
|||
self.good_values.update(lastname=self.values["name"], firstname=False) |
|||
self.values = self.good_values.copy() |
|||
|
|||
|
|||
class UserCase(PersonCase, MailInstalled): |
|||
"""Test ``res.users``.""" |
|||
model = "res.users" |
|||
context = {"default_login": "user@example.com"} |
|||
|
|||
def tearDown(self): |
|||
# Cannot create users if ``mail`` is installed |
|||
if self.mail_installed(): |
|||
# Skip tests |
|||
super(PersonCase, self).tearDown() |
|||
else: |
|||
# Run tests |
|||
super(UserCase, self).tearDown() |
@ -0,0 +1,65 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L. - Jairo Llopis. |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
"""Test default values for models.""" |
|||
|
|||
from openerp.tests.common import TransactionCase |
|||
from .base import MailInstalled |
|||
|
|||
|
|||
class PersonCase(TransactionCase): |
|||
"""Test ``res.partner`` when it is a person.""" |
|||
context = {"default_is_company": False} |
|||
model = "res.partner" |
|||
|
|||
def setUp(self): |
|||
super(PersonCase, self).setUp() |
|||
self.values = { |
|||
"firstname": u"Núñez", |
|||
"lastname": u"Fernán", |
|||
} |
|||
self.values["name"] = "%s %s" % (self.values["lastname"], |
|||
self.values["firstname"]) |
|||
if "default_is_company" in self.context: |
|||
self.values["is_company"] = self.context["default_is_company"] |
|||
|
|||
def tearDown(self): |
|||
for key, value in self.values.iteritems(): |
|||
self.assertEqual( |
|||
self.defaults.get(key), |
|||
value, |
|||
"Checking key %s" % key) |
|||
|
|||
return super(PersonCase, self).tearDown() |
|||
|
|||
def test_default_get(self): |
|||
"""Getting default values for fields includes new fields.""" |
|||
self.defaults = (self.env[self.model] |
|||
.with_context(self.context, |
|||
default_name=self.values["name"]) |
|||
.default_get(self.values.keys())) |
|||
|
|||
|
|||
class CompanyCase(PersonCase): |
|||
"""Test ``res.partner`` when it is a company.""" |
|||
context = {"default_is_company": True} |
|||
|
|||
def tearDown(self): |
|||
self.values.update(lastname=self.values["name"], firstname=False) |
|||
return super(CompanyCase, self).tearDown() |
|||
|
|||
|
|||
class UserCase(PersonCase, MailInstalled): |
|||
"""Test ``res.users``.""" |
|||
model = "res.users" |
|||
context = {"default_login": "user@example.com"} |
|||
|
|||
def tearDown(self): |
|||
# Cannot create users if ``mail`` is installed |
|||
if self.mail_installed(): |
|||
# Skip tests |
|||
super(PersonCase, self).tearDown() |
|||
else: |
|||
# Run tests |
|||
super(UserCase, self).tearDown() |
@ -0,0 +1,38 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 Grupo ESOC |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from openerp.tests.common import TransactionCase |
|||
from .base import MailInstalled |
|||
|
|||
|
|||
class CompanyCase(TransactionCase): |
|||
model = "res.partner" |
|||
context = {"default_is_company": True} |
|||
|
|||
def test_computing_after_unlink(self): |
|||
"""Test what happens if recomputed after unlinking. |
|||
|
|||
This test might seem useless, but really this happens when module |
|||
``partner_relations`` is installed. |
|||
|
|||
See https://github.com/OCA/partner-contact/issues/154. |
|||
""" |
|||
data = {"name": u"Söme name"} |
|||
record = self.env[self.model].with_context(**self.context).create(data) |
|||
record.unlink() |
|||
record.recompute() |
|||
|
|||
|
|||
class PersonCase(CompanyCase): |
|||
context = {"default_is_company": False} |
|||
|
|||
|
|||
class UserCase(CompanyCase, MailInstalled): |
|||
model = "res.users" |
|||
context = {"default_login": "user@example.com"} |
|||
|
|||
def test_computing_after_unlink(self): |
|||
# Cannot create users if ``mail`` is installed |
|||
if not self.mail_installed(): |
|||
super(UserCase, self).test_computing_after_unlink() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue