diff --git a/base_partner_ref/__init__.py b/base_partner_ref/__init__.py new file mode 100644 index 0000000..cde864b --- /dev/null +++ b/base_partner_ref/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import models diff --git a/base_partner_ref/__openerp__.py b/base_partner_ref/__openerp__.py new file mode 100644 index 0000000..1904e42 --- /dev/null +++ b/base_partner_ref/__openerp__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright 2017-2024 Akretion France (https://www.akretion.com) +# @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + 'name': 'Base Partner Reference', + 'version': '8.0.1.0.0', + 'category': 'Partner', + 'license': 'AGPL-3', + 'summary': "Improve usage of partner's Internal Reference", + 'description': """ +Base Partner Reference +====================== + +* Adds Internal Reference in partner tree view + +* Adds Internal Reference in name_get() + +* Adds unicity constraint on Internal Reference + """, + 'author': 'Akretion', + 'website': 'https://github.com/akretion/odoo-usability', + 'depends': ['base'], + 'data': ['views/res_partner.xml'], + 'installable': True, +} diff --git a/base_partner_ref/models/__init__.py b/base_partner_ref/models/__init__.py new file mode 100644 index 0000000..f261da7 --- /dev/null +++ b/base_partner_ref/models/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from . import res_partner diff --git a/base_partner_ref/models/res_partner.py b/base_partner_ref/models/res_partner.py new file mode 100644 index 0000000..b295846 --- /dev/null +++ b/base_partner_ref/models/res_partner.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# Copyright 2017-2024 Akretion France +# @author: Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from openerp.osv import orm, fields +from openerp import api + + +class ResPartner(orm.Model): + _inherit = 'res.partner' + + # copy=False on 'ref' is already in base_usability + _columns = { + # in v8, display_name is stored field + # so, when we inherit name_get() and use additionnal fields, we + # have to update the code for invalidation + 'display_name': fields.char(store={ + 'res.partner': (lambda self, cr, uid, ids, context=None: self.search(cr, uid, [('id', 'child_of', ids)], context=dict(active_test=False)), + ['parent_id', 'is_company', 'name', 'ref'], 10) + }), + } + + _sql_constraints = [( + 'ref_unique', + 'unique(ref)', + 'A partner already exists with this internal reference!' + )] + + def name_get(self, cr, uid, ids, context=None): + if context is None: + context = {} + if isinstance(ids, (int, long)): + ids = [ids] + res = [] + for record in self.browse(cr, uid, ids, context=context): + name = record.name + # START modif of native name_get() method + if record.ref: + name = u"[%s] %s" % (record.ref, name) + # END modif of native name_get() method + if record.parent_id and not record.is_company: + name = "%s, %s" % (record.parent_name, name) + if context.get('show_address_only'): + name = self._display_address(cr, uid, record, without_company=True, context=context) + if context.get('show_address'): + name = name + "\n" + self._display_address(cr, uid, record, without_company=True, context=context) + name = name.replace('\n\n','\n') + name = name.replace('\n\n','\n') + if context.get('show_email') and record.email: + name = "%s <%s>" % (name, record.email) + res.append((record.id, name)) + return res + + @api.model + def name_search(self, name='', args=None, operator='ilike', limit=100): + if args is None: + args = [] + if name and operator == 'ilike': + recs = self.search([('ref', '=', name)] + args, limit=limit) + if recs: + rec_childs = self.search([('id', 'child_of', recs.ids)]) + return rec_childs.name_get() + return super(ResPartner, self).name_search(name=name, args=args, operator=operator, limit=limit) diff --git a/base_partner_ref/views/res_partner.xml b/base_partner_ref/views/res_partner.xml new file mode 100644 index 0000000..18f7a5f --- /dev/null +++ b/base_partner_ref/views/res_partner.xml @@ -0,0 +1,54 @@ + + + + + + + + Move ref in partner form to make it more visible + res.partner + + + + + + + + + + + Add ref in partner tree view + res.partner + + + + + + + + + 1 + + + + + + Add ref in partner kanban view + res.partner + + + + + +
  • +
  • Ref:
  • + +
    +
    + +
    +