ADD 12.0 module company_code (#77)

* ADD module company_code

* FIX doc

* FIX doc

* Update company_code/readme/USAGE.rst

Co-Authored-By: bealdav <david.beal@akretion.com>
This commit is contained in:
David Beal
2018-12-12 19:57:22 +01:00
committed by GitHub
parent 79d8f6edc5
commit fe06c37cd5
10 changed files with 573 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# Copyright 2019 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, fields
class ResCompany(models.Model):
_inherit = 'res.company'
code = fields.Char(
required=True, default='CODE',
help="Field used in object name as suffix")
def _add_company_code(self, super_object):
""
""" Add the `code` field to your _rec_name. Use it like that:
def name_get(self):
return self.env['res.company']._add_company_code(super())
"""
records = super_object.__self__
if records and records[0]._name == 'res.company':
codes = {x.id: x.code for x in records}
else:
codes = {x.id: x['company_id']['code'] for x in records
if getattr(x, 'company_id')}
res = [(elm[0], '%s (%s)' % (elm[1], codes[elm[0]] or ''))
for elm in super_object.name_get()]
return res
def name_get(self):
return self.env['res.company']._add_company_code(super())