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:
1
company_code/models/__init__.py
Normal file
1
company_code/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import company
|
||||
32
company_code/models/company.py
Normal file
32
company_code/models/company.py
Normal 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())
|
||||
Reference in New Issue
Block a user