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
71cd05ea70
commit
1972fe7fcf
1 file changed
+35
-102
+35
-102
@@ -112,8 +112,7 @@ class Purchase(ModelWorkflow, OSV):
|
||||
payment_term_ids = payment_term_obj.search(cursor, user,
|
||||
self.payment_term.domain, context=context)
|
||||
if len(payment_term_ids) == 1:
|
||||
return payment_term_obj.name_get(cursor, user, payment_term_ids,
|
||||
context=context)[0]
|
||||
return payment_term_ids[0]
|
||||
return False
|
||||
|
||||
def default_warehouse(self, cursor, user, context=None):
|
||||
@@ -121,8 +120,7 @@ class Purchase(ModelWorkflow, OSV):
|
||||
location_ids = location_obj.search(cursor, user,
|
||||
self.warehouse.domain, context=context)
|
||||
if len(location_ids) == 1:
|
||||
return location_obj.name_get(cursor, user, location_ids,
|
||||
context=context)[0]
|
||||
return location_ids[0]
|
||||
return False
|
||||
|
||||
def default_company(self, cursor, user, context=None):
|
||||
@@ -130,8 +128,7 @@ class Purchase(ModelWorkflow, OSV):
|
||||
if context is None:
|
||||
context = {}
|
||||
if context.get('company'):
|
||||
return company_obj.name_get(cursor, user, context['company'],
|
||||
context=context)[0]
|
||||
return context['company']
|
||||
return False
|
||||
|
||||
def default_state(self, cursor, user, context=None):
|
||||
@@ -150,8 +147,7 @@ class Purchase(ModelWorkflow, OSV):
|
||||
if context.get('company'):
|
||||
company = company_obj.browse(cursor, user, context['company'],
|
||||
context=context)
|
||||
return currency_obj.name_get(cursor, user, company.currency.id,
|
||||
context=context)[0]
|
||||
return company.currency.id
|
||||
return False
|
||||
|
||||
def default_currency_digits(self, cursor, user, context=None):
|
||||
@@ -191,14 +187,14 @@ class Purchase(ModelWorkflow, OSV):
|
||||
res['payment_term'] = party.supplier_payment_term.id
|
||||
|
||||
if res['invoice_address']:
|
||||
res['invoice_address'] = address_obj.name_get(cursor, user,
|
||||
res['invoice_address'], context=context)[0]
|
||||
if res['payment_term']:
|
||||
res['payment_term'] = payment_term_obj.name_get(cursor, user,
|
||||
res['payment_term'], context=context)[0]
|
||||
else:
|
||||
res['invoice_address.rec_name'] = address_obj.browse(cursor, user,
|
||||
res['invoice_address'], context=context).rec_name
|
||||
if not res['payment_term']:
|
||||
res['payment_term'] = self.default_payment_term(cursor, user,
|
||||
context=context)
|
||||
if res['payment_term']:
|
||||
res['payment_term.rec_name'] = payment_term_obj.browse(cursor, user,
|
||||
res['payment_term'], context=context).rec_name
|
||||
return res
|
||||
|
||||
def on_change_with_currency_digits(self, cursor, user, ids, vals,
|
||||
@@ -563,33 +559,29 @@ class Purchase(ModelWorkflow, OSV):
|
||||
res[purchase.id] = val
|
||||
return 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]
|
||||
res = []
|
||||
return {}
|
||||
res = {}
|
||||
for purchase in self.browse(cursor, user, ids, context=context):
|
||||
res.append((purchase.id, purchase.reference or str(purchase.id) \
|
||||
+ ' ' + purchase.party.name))
|
||||
res[purchase.id] = purchase.reference or str(purchase.id) \
|
||||
+ ' - ' + purchase.party.name
|
||||
return res
|
||||
|
||||
def name_search(self, cursor, user, name='', args=None, operator='ilike',
|
||||
context=None, limit=None):
|
||||
if args is None:
|
||||
args = []
|
||||
if name:
|
||||
ids = self.search(cursor, user,
|
||||
[('reference', operator, name)] + args, limit=limit,
|
||||
context=context)
|
||||
ids += self.search(cursor, user,
|
||||
[('supplier_reference', operator, name)] + args, limit=limit,
|
||||
context=context)
|
||||
if not ids:
|
||||
ids = self.search(cursor, user, [('party', operator, name)] + args,
|
||||
limit=limit, context=context)
|
||||
res = self.name_get(cursor, user, ids, context=context)
|
||||
return res
|
||||
def search_rec_name(self, cursor, user, name, args, context=None):
|
||||
args2 = []
|
||||
i = 0
|
||||
while i < lend(args):
|
||||
names = args[i][2].split(' - ', 1)
|
||||
ids = self.search(cursor, user, ['OR',
|
||||
('reference', args[i][1], names[0]),
|
||||
('supplier_reference', args[i][1], names[0]),
|
||||
], context=context)
|
||||
args2.append(('id', 'in', ids))
|
||||
if len(names) != 1 and names[1]:
|
||||
args2.append(('party', args[i][1], names[1]))
|
||||
i += 1
|
||||
return args2
|
||||
|
||||
def copy(self, cursor, user, ids, default=None, context=None):
|
||||
if default is None:
|
||||
@@ -938,14 +930,14 @@ class PurchaseLine(OSV):
|
||||
res['taxes'].append(tax.id)
|
||||
|
||||
if not vals.get('description'):
|
||||
res['description'] = product_obj.name_get(cursor, user, product.id,
|
||||
context=ctx)[0][1]
|
||||
res['description'] = product_obj.browse(cursor, user, product.id,
|
||||
context=ctx).rec_name
|
||||
|
||||
category = product.purchase_uom.category
|
||||
if not vals.get('unit') \
|
||||
or vals.get('unit') not in [x.id for x in category.uoms]:
|
||||
res['unit'] = uom_obj.name_get(cursor, user, product.purchase_uom.id,
|
||||
context=context)[0]
|
||||
res['unit'] = product.purchase_uom.id
|
||||
res['unit.rec_name'] = product.purchase_uom.rec_name
|
||||
res['unit_digits'] = product.purchase_uom.digits
|
||||
return res
|
||||
|
||||
@@ -1196,8 +1188,6 @@ class Template(OSV):
|
||||
res = default_uom.id
|
||||
else:
|
||||
res = default_uom.id
|
||||
if res:
|
||||
res = uom_obj.name_get(cursor, user, res, context=context)[0]
|
||||
return res
|
||||
|
||||
Template()
|
||||
@@ -1298,8 +1288,7 @@ class ProductSupplier(OSV):
|
||||
if context is None:
|
||||
context = {}
|
||||
if context.get('company'):
|
||||
return company_obj.name_get(cursor, user, context['company'],
|
||||
context=context)[0]
|
||||
return context['company']
|
||||
return False
|
||||
|
||||
def compute_supply_date(self, cursor, user, product_supplier, date=None,
|
||||
@@ -1367,8 +1356,7 @@ class ProductSupplierPrice(OSV):
|
||||
if context.get('company'):
|
||||
company = company_obj.browse(cursor, user, context['company'],
|
||||
context=context)
|
||||
return currency_obj.name_get(cursor, user, company.currency.id,
|
||||
context=context)[0]
|
||||
return company.currency.id
|
||||
return False
|
||||
|
||||
ProductSupplierPrice()
|
||||
@@ -1477,24 +1465,11 @@ class Move(OSV):
|
||||
string='Exception State')
|
||||
|
||||
def get_purchase(self, cursor, user, ids, name, arg, context=None):
|
||||
purchase_obj = self.pool.get('purchase.purchase')
|
||||
|
||||
res = {}
|
||||
for move in self.browse(cursor, user, ids, context=context):
|
||||
res[move.id] = False
|
||||
if move.purchase_line:
|
||||
res[move.id] = move.purchase_line.purchase.id
|
||||
|
||||
purchase_names = {}
|
||||
for purchase_id, purchase_name in purchase_obj.name_get(cursor,
|
||||
user, [x for x in res.values() if x], context=context):
|
||||
purchase_names[purchase_id] = purchase_name
|
||||
|
||||
for i in res.keys():
|
||||
if res[i] and res[i] in purchase_names:
|
||||
res[i] = (res[i], purchase_names[res[i]])
|
||||
else:
|
||||
res[i] = False
|
||||
return res
|
||||
|
||||
def get_purchase_exception_state(self, cursor, user, ids, name, arg,
|
||||
@@ -1543,56 +1518,14 @@ class Move(OSV):
|
||||
res[name][move.id] = move.purchase_line[name[9:]]
|
||||
else:
|
||||
res[name][move.id] = move.purchase_line[name[9:]].id
|
||||
|
||||
if 'purchase_unit' in res.keys():
|
||||
unit_names = {}
|
||||
for unit_id, unit_name in uom_obj.name_get(cursor, user,
|
||||
list(set([x for x in res['purchase_unit'].values() if x])),
|
||||
context=context):
|
||||
unit_names[unit_id] = (unit_id, unit_name)
|
||||
for i in res['purchase_unit'].keys():
|
||||
if res['purchase_unit'][i] and \
|
||||
res['purchase_unit'][i] in unit_names:
|
||||
res['purchase_unit'][i] = unit_names[
|
||||
res['purchase_unit'][i]]
|
||||
else:
|
||||
res['purchase_unit'][i] = False
|
||||
|
||||
if 'purchase_currency' in res.keys():
|
||||
currency_names = {}
|
||||
for currency_id, currency_name in currency_obj.name_get(cursor,
|
||||
user,
|
||||
list(set([x for x in res['purchase_currency'].values() if x])),
|
||||
context=context):
|
||||
currency_names[currency_id] = (currency_id, currency_name)
|
||||
for i in res['purchase_currency'].keys():
|
||||
if res['purchase_currency'][i] and \
|
||||
res['purchase_currency'][i] in currency_names:
|
||||
res['purchase_currency'][i] = currency_names[
|
||||
res['purchase_currency'][i]]
|
||||
else:
|
||||
res['purchase_currency'][i] = False
|
||||
return res
|
||||
|
||||
def get_supplier(self, cursor, user, ids, name, arg, context=None):
|
||||
party_obj = self.pool.get('party.party')
|
||||
|
||||
res = {}
|
||||
for move in self.browse(cursor, user, ids, context=context):
|
||||
res[move.id] = False
|
||||
if move.purchase_line:
|
||||
res[move.id] = move.purchase_line.purchase.party.id
|
||||
|
||||
party_names = {}
|
||||
for party_id, party_name in party_obj.name_get(cursor, user,
|
||||
[x for x in res.values() if x], context=context):
|
||||
party_names[party_id] = party_name
|
||||
|
||||
for i in res.keys():
|
||||
if res[i] and res[i] in party_names:
|
||||
res[i] = (res[i], party_names[res[i]])
|
||||
else:
|
||||
res[i] = False
|
||||
return res
|
||||
|
||||
def search_supplier(self, cursor, user, name, args, context=None):
|
||||
|
||||
Reference in new issue
Block a user