Replace name_get, name_search with get_rec_name and search_rec_name
Return only id for default value of many2one
This commit is contained in:
1 parent
9827fef679
commit
d0d0b8747e
4 files changed
+27
-41
No files matched your search
+6
-13
@@ -1,4 +1,5 @@
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms.
|
||||
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
#this repository contains the full copyright notices and license terms.
|
||||
from trytond.osv import fields, OSV
|
||||
|
||||
|
||||
@@ -8,8 +9,6 @@ class Category(OSV):
|
||||
_description = __doc__
|
||||
|
||||
name = fields.Char('Name', required=True, translate=True)
|
||||
complete_name = fields.Function('get_complete_name', type="char",
|
||||
string='Complete Name')
|
||||
parent = fields.Many2One('product.category','Parent', select=1)
|
||||
childs = fields.One2Many('product.category', 'parent',
|
||||
string='Childs')
|
||||
@@ -18,23 +17,17 @@ class Category(OSV):
|
||||
super(Category, self).__init__()
|
||||
self._order.insert(0, ('name', 'ASC'))
|
||||
|
||||
def get_complete_name(self, cursor, user, ids, name, arg, context=None):
|
||||
res = self.name_get(cursor, user, ids, context=context)
|
||||
return dict(res)
|
||||
|
||||
def name_get(self, cursor, user, ids, context=None):
|
||||
def get_rec_name(self, cursor, user, ids, name, arg, context=None):
|
||||
if not ids:
|
||||
return []
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
return {}
|
||||
res = {}
|
||||
categories = self.browse(cursor, user, ids, context=context)
|
||||
res = []
|
||||
for category in categories:
|
||||
if category.parent:
|
||||
name = category.parent.name+' / '+ category.name
|
||||
else:
|
||||
name = category.name
|
||||
res.append((category.id, name))
|
||||
res[category.id] = name
|
||||
return res
|
||||
|
||||
Category()
|
||||
+3
-3
@@ -11,7 +11,7 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<![CDATA[
|
||||
<tree string="Product Categories">
|
||||
<field name="name" select="1"/>
|
||||
<field name="complete_name"/>
|
||||
<field name="rec_name"/>
|
||||
</tree>
|
||||
]]>
|
||||
</field>
|
||||
@@ -39,8 +39,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<field name="name"/>
|
||||
<label name="parent"/>
|
||||
<field name="parent"/>
|
||||
<label name="complete_name"/>
|
||||
<field name="complete_name" colspan="3"/>
|
||||
<label name="rec_name"/>
|
||||
<field name="rec_name" colspan="3"/>
|
||||
<notebook colspan="4">
|
||||
<page string="Childs" col="1" id="childs">
|
||||
<field name="childs"/>
|
||||
|
||||
+16
-21
@@ -79,35 +79,30 @@ class Product(OSV):
|
||||
required=True, ondelete='CASCADE')
|
||||
code = fields.Char("Code", size=None)
|
||||
description = fields.Text("Description", translate=True)
|
||||
complete_name = fields.Function('get_complete_name', string="Complete Name", type="char")
|
||||
|
||||
|
||||
def get_complete_name(self, cursor, user, ids, name, arg, context=None):
|
||||
return dict(self.name_get(cursor, user, ids, context=context))
|
||||
|
||||
def name_get(self, cursor, user, ids, context=None):
|
||||
def get_rec_name(self, cursor, user, ids, name, arg, context=None):
|
||||
if not ids:
|
||||
return []
|
||||
if isinstance(ids, (int, long)):
|
||||
ids = [ids]
|
||||
res = []
|
||||
return {}
|
||||
res = {}
|
||||
for product in self.browse(cursor, user, ids, context=context):
|
||||
name = product.name
|
||||
if product.code:
|
||||
name = '[' + product.code + '] ' + product.name
|
||||
res.append((product.id, name))
|
||||
res[product.id] = name
|
||||
return res
|
||||
|
||||
def name_search(self, cursor, user, name, args=None, operator='ilike',
|
||||
context=None, limit=None):
|
||||
if not args:
|
||||
args = []
|
||||
ids = self.search(cursor, user, [('code', '=', name)] + args,
|
||||
limit=limit, context=context)
|
||||
if ids:
|
||||
return self.name_get(cursor, user, ids, context=context)
|
||||
return super(Product, self).name_search(cursor, user, name,
|
||||
args=args, operator=operator, context=context, limit=limit)
|
||||
def search_rec_name(self, cursor, user, name, args, context=None):
|
||||
args2 = []
|
||||
i = 0
|
||||
while i < len(args):
|
||||
ids = self.search(cursor, user, [('code', args[i][1], args[i][2])],
|
||||
context=context)
|
||||
if ids:
|
||||
args2.append(('id', 'in', ids))
|
||||
else:
|
||||
args2.append(('name', args[i][1], args[i][2]))
|
||||
i += 1
|
||||
return args2
|
||||
|
||||
def delete(self, cursor, user, ids, context=None):
|
||||
template_obj = self.pool.get('product.template')
|
||||
|
||||
@@ -82,15 +82,13 @@ class Uom(OSV):
|
||||
return False
|
||||
uom = self.browse(cursor, user, context['category'][0],
|
||||
context=context)
|
||||
return category_obj.name_get(cursor, user, uom.category.id,
|
||||
context=context)[0]
|
||||
return uom.category.id
|
||||
else:
|
||||
if not context['category'][0]:
|
||||
return False
|
||||
product = product_obj.browse(cursor, user,
|
||||
context['category'][0], context=context)
|
||||
return category_obj.name_get(cursor, user,
|
||||
product.default_uom.category.id, context=context)[0]
|
||||
return product.default_uom.category.id
|
||||
return False
|
||||
|
||||
def on_change_factor(self, cursor, user, ids, value, context=None):
|
||||
|
||||
Reference in new issue
Block a user