backport base_partner_ref to v8

This commit is contained in:
Alexis de Lattre
2024-11-14 12:15:02 +01:00
parent 6d50a1d6a5
commit ab3c17f687
5 changed files with 151 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import models

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2024 Akretion France (https://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# 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,
}

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import res_partner

View File

@@ -0,0 +1,64 @@
# -*- coding: utf-8 -*-
# Copyright 2017-2024 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# 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)

View File

@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2017-2024 Akretion France (https://www.akretion.com/)
@author: Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<openerp>
<data>
<record id="view_partner_form" model="ir.ui.view">
<field name="name">Move ref in partner form to make it more visible</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="website" position="before">
<field name="ref"/>
</field>
<xpath expr="//page[@name='sales_purchases']//field[@name='ref']" position="replace"/>
</field>
</record>
<record id="view_partner_tree" model="ir.ui.view">
<field name="name">Add ref in partner tree view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_tree"/>
<field name="arch" type="xml">
<!-- show name and ref in separate columns -->
<field name="display_name" position="after">
<field name="ref"/>
<field name="name"/>
</field>
<field name="display_name" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
<record id="res_partner_kanban_view" model="ir.ui.view">
<field name="name">Add ref in partner kanban view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.res_partner_kanban_view"/>
<field name="arch" type="xml">
<field name="display_name" position="after">
<field name="ref"/>
</field>
<li t-if="record.email.raw_value" position="after">
<li t-if="record.ref.raw_value">Ref: <field name="ref"/></li>
</li>
</field>
</record>
</data>
</openerp>