Browse Source
[PORT] partner_firstname to 9.0
[PORT] partner_firstname to 9.0
- add missing authors - use reduced license header - move models in models directory - adapt views - show firstname, lastname only in edit mode - use company_type in views instead of is_company - adapt constraint on contacts [PORT][9.0] partner_firstname - remove hack to be able to edit user view. Fixed in odoo/odoo#cf63d4d277ef1ba02ff4ebcdae8583332a1775b1 [PORT][9.0] partner_firstname - Format of string in __openerp__.py [PORT][9.0] Adapt tests to take new constraint raising IntegrityError partner_firstname: Name is not mandatory if partner is an address [FIX] Ensure default values are computed for res.users Add test for shipping address with empty name partner_firstname: fix user creation User name field is required what is stoping to create a new user Fix user form with firstname and lastname asking for a mandatory namepull/663/head
Yannick Vaucher
9 years ago
committed by
Jairo Llopis
14 changed files with 201 additions and 194 deletions
-
17partner_firstname/README.rst
-
21partner_firstname/__init__.py
-
30partner_firstname/__openerp__.py
-
18partner_firstname/exceptions.py
-
5partner_firstname/models/__init__.py
-
36partner_firstname/models/res_partner.py
-
37partner_firstname/models/res_user.py
-
34partner_firstname/tests/__init__.py
-
27partner_firstname/tests/base.py
-
45partner_firstname/tests/test_empty.py
-
3partner_firstname/tests/test_onchange.py
-
53partner_firstname/tests/test_user_onchange.py
-
64partner_firstname/views/res_partner.xml
-
5partner_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,37 @@ |
|||
# -*- 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 |
|||
|
|||
@api.onchange("firstname", "lastname") |
|||
def _compute_name(self): |
|||
"""Write the 'name' field according to splitted data.""" |
|||
for rec in self: |
|||
rec.name = rec.partner_id._get_computed_name( |
|||
rec.lastname, rec.firstname) |
@ -0,0 +1,53 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Yannick Vaucher (Camptocamp SA) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp.tests.common import TransactionCase |
|||
|
|||
|
|||
class UserOnchangeCase(TransactionCase): |
|||
|
|||
def test_create_from_form_only_firstname(self): |
|||
"""In a new users form, a user set only the firstname.""" |
|||
firstname = u"Zoë" |
|||
with self.env.do_in_onchange(): |
|||
# Changes firstname, which triggers onchanges |
|||
self.user.firstname = firstname |
|||
self.user._compute_name() |
|||
|
|||
self.assertEqual(self.user.lastname, False) |
|||
self.assertEqual(self.user.firstname, firstname) |
|||
self.assertEqual(self.user.name, firstname) |
|||
|
|||
def test_create_from_form_only_lastname(self): |
|||
"""In a new user form, a user set only the lastname.""" |
|||
lastname = u"Żywioł" |
|||
with self.env.do_in_onchange(): |
|||
# Changes lastname, which triggers onchanges |
|||
self.user.lastname = lastname |
|||
self.user._compute_name() |
|||
|
|||
self.assertEqual(self.user.firstname, False) |
|||
self.assertEqual(self.user.lastname, lastname) |
|||
self.assertEqual(self.user.name, lastname) |
|||
|
|||
def test_create_from_form_all(self): |
|||
"""In a new user form, a user set all names.""" |
|||
firstname = u"Zoë" |
|||
lastname = u"Żywioł" |
|||
with self.env.do_in_onchange(): |
|||
# Changes firstname, which triggers onchanges |
|||
self.user.firstname = firstname |
|||
self.user._compute_name() |
|||
|
|||
# Changes lastname, which triggers onchanges |
|||
self.user.lastname = lastname |
|||
self.user._compute_name() |
|||
|
|||
self.assertEqual(self.user.lastname, lastname) |
|||
self.assertEqual(self.user.firstname, firstname) |
|||
self.assertEqual(self.user.name, u" ".join((lastname, firstname))) |
|||
|
|||
def setUp(self): |
|||
super(UserOnchangeCase, self).setUp() |
|||
self.user = self.env["res.users"].new() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue