From 2dac5dcc29eccc6c5971f26a1b589e5c404386ee Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Tue, 19 Jan 2016 19:01:02 +0100 Subject: [PATCH] [FIX] Ensure default values are computed for res.users --- partner_firstname/models/__init__.py | 1 + partner_firstname/models/user.py | 30 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 partner_firstname/models/user.py diff --git a/partner_firstname/models/__init__.py b/partner_firstname/models/__init__.py index 4e1de1d72..9bb2012d6 100644 --- a/partner_firstname/models/__init__.py +++ b/partner_firstname/models/__init__.py @@ -2,3 +2,4 @@ # © 2013 Nicolas Bessi (Camptocamp SA) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from . import partner +from . import user diff --git a/partner_firstname/models/user.py b/partner_firstname/models/user.py new file mode 100644 index 000000000..5b0f7c8fc --- /dev/null +++ b/partner_firstname/models/user.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# © 2013 Nicolas Bessi (Camptocamp SA) +# © 2014 Agile Business Group () +# © 2015 Grupo ESOC () +# 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