You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.3 KiB

  1. from openerp.addons.web.controllers.main import DataSet
  2. from openerp.tools.translate import _
  3. from openerp.http import request
  4. class DataSetCustom(DataSet):
  5. def _call_kw(self, model, method, args, kwargs):
  6. res = super(DataSetCustom, self)._call_kw(model, method, args, kwargs)
  7. if 'context' in kwargs and kwargs['context'].get('extended_name_with_contact') and res:
  8. model = request.session.model(model)
  9. fields = model.fields_get(False, request.context)
  10. contact_field = False
  11. for n, f in fields.iteritems():
  12. if f['type'] == 'many2one' and f['relation'] == 'res.partner':
  13. contact_field = n
  14. break
  15. partner_info = {}
  16. if contact_field:
  17. partner_info = model.read([r[0] for r in res], [contact_field])
  18. partner_info = dict([(p['id'], p[contact_field]) for p in partner_info])
  19. final_res = []
  20. for r in res:
  21. if partner_info.get(r[0]):
  22. final_res.append((r[0], _('%s [partner: %s] ID %s') % (r[1], partner_info.get(r[0])[1], r[0])))
  23. else:
  24. final_res.append((r[0], _('%s ID %s') % (r[1], r[0])))
  25. res = final_res
  26. return res