[IMP] sale: add name_get and name_search on SO
The goal is to have a name_get for SO returning a value like 'SO0002 - Michel F.' To avoid performance problem, the chosen solution is to add a context key 'sale_show_partner_name' to provide the partner name in name_get(), otherwise it will always add it and kill the performance. This solution is preferred over adding a stored related field for partner name (trigger recompute when partner is renamed for all SO is bad).
This commit is contained in:
@@ -9,7 +9,9 @@ from werkzeug.urls import url_encode
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError, AccessError
|
||||
from odoo.osv import expression
|
||||
from odoo.tools import float_is_zero, float_compare, DEFAULT_SERVER_DATETIME_FORMAT
|
||||
|
||||
from odoo.tools.misc import formatLang
|
||||
|
||||
from odoo.addons import decimal_precision as dp
|
||||
@@ -289,6 +291,29 @@ class SaleOrder(models.Model):
|
||||
default['order_line'] = [(0, 0, line.copy_data()[0]) for line in self.order_line.filtered(lambda l: not l.is_downpayment)]
|
||||
return super(SaleOrder, self).copy_data(default)
|
||||
|
||||
@api.multi
|
||||
def name_get(self):
|
||||
if self._context.get('sale_show_partner_name'):
|
||||
res = []
|
||||
for order in self:
|
||||
name = order.name
|
||||
if order.partner_id.name:
|
||||
name = '%s - %s' % (name, order.partner_id.name)
|
||||
res.append((order.id, name))
|
||||
return res
|
||||
return super(SaleOrder, self).name_get()
|
||||
|
||||
@api.model
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
if self._context.get('sale_show_partner_name'):
|
||||
if operator in ('ilike', 'like', '=', '=like', '=ilike'):
|
||||
domain = expression.AND([
|
||||
args or [],
|
||||
['|', ('name', operator, name), ('partner_id.name', operator, name)]
|
||||
])
|
||||
return self.search(domain, limit=limit).name_get()
|
||||
return super(SaleOrder, self).name_search(name, args, operator, limit)
|
||||
|
||||
@api.model_cr_context
|
||||
def _init_column(self, column_name):
|
||||
""" Initialize the value of the given column for existing rows.
|
||||
|
||||
Reference in New Issue
Block a user