1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Business Applications
5 # Copyright (c) 2013 S.A. <http://openerp.com>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import osv, fields
24 class res_partner(osv.Model):
25 _inherit = 'res.partner'
26 _order = 'display_name'
28 def _display_name_compute(self, cr, uid, ids, name, args, context=None):
29 context = dict(context or {})
30 context.pop('show_address', None)
31 return dict(self.name_get(cr, uid, ids, context=context))
33 _display_name_store_triggers = {
34 'res.partner': (lambda self,cr,uid,ids,context=None: self.search(cr, uid, [('id','child_of',ids)]),
35 ['parent_id', 'is_company', 'name'], 10)
38 # indirection to avoid passing a copy of the overridable method when declaring the function field
39 _display_name = lambda self, *args, **kwargs: self._display_name_compute(*args, **kwargs)
42 # extra field to allow ORDER BY to match visible names
43 'display_name': fields.function(_display_name, type='char', string='Name', store=_display_name_store_triggers),
46 class account_invoice(osv.Model):
47 _inherit = 'account.invoice'
50 'commercial_partner_id': fields.related('partner_id', 'commercial_partner_id', string='Commercial Entity', type='many2one',
51 relation='res.partner', store=True, readonly=True,
52 help="The commercial entity that will be used on Journal Entries for this invoice")