Browse Source

Default res_id selected

pull/1/head
Veronika Kotovich 9 years ago
parent
commit
80b6221277
  1. 50
      controllers/main.py
  2. 9
      mail_move_message_models.py

50
controllers/main.py

@ -5,6 +5,28 @@ from openerp.http import request
class DataSetCustom(DataSet):
def _extend_name(self, model, records):
cr, uid, context = request.cr, request.uid, request.context
Model = request.registry[model]
fields = Model.fields_get(cr, uid, False, context)
contact_field = False
for n, f in fields.iteritems():
if f['type'] == 'many2one' and f['relation'] == 'res.partner':
contact_field = n
break
partner_info = {}
if contact_field:
partner_info = Model.read(cr, uid, [r[0] for r in records], [contact_field], context)
partner_info = dict([(p['id'], p[contact_field]) for p in partner_info])
res = []
for r in records:
if partner_info.get(r[0]):
res.append((r[0], _('%s [partner: %s] ID %s') % (r[1], partner_info.get(r[0])[1], r[0])))
else:
res.append((r[0], _('%s ID %s') % (r[1], r[0])))
return res
@http.route('/web/dataset/call_kw/<model>/name_search', type='json', auth="user")
def name_search(self, model, method, args, kwargs):
context = kwargs.get('context')
@ -20,24 +42,14 @@ class DataSetCustom(DataSet):
search_args += [(Model._rec_name, operator, name)]
ids = Model.search(cr, uid, search_args, limit=limit, order='id desc', context=context)
res = Model.name_get(cr, uid, ids, context)
#extend record names with partner and ID
fields = Model.fields_get(cr, uid, False, request.context)
contact_field = False
for n, f in fields.iteritems():
if f['type'] == 'many2one' and f['relation'] == 'res.partner':
contact_field = n
break
partner_info = {}
if contact_field:
partner_info = Model.read(cr, uid, [r[0] for r in res], [contact_field], request.context)
partner_info = dict([(p['id'], p[contact_field]) for p in partner_info])
final_res = []
for r in res:
if partner_info.get(r[0]):
final_res.append((r[0], _('%s [partner: %s] ID %s') % (r[1], partner_info.get(r[0])[1], r[0])))
else:
final_res.append((r[0], _('%s ID %s') % (r[1], r[0])))
return final_res
return self._extend_name(model, res)
return self._call_kw(model, method, args, kwargs)
@http.route('/web/dataset/call_kw/<model>/name_get', type='json', auth="user")
def name_get(self, model, method, args, kwargs):
res = self._call_kw(model, method, args, kwargs)
context = kwargs.get('context')
if context and context.get('extended_name_with_contact'):
res = self._extend_name(model, res)
return res

9
mail_move_message_models.py

@ -17,17 +17,22 @@ class wizard(models.TransientModel):
model_fields = self.fields_get()
return model_fields['model']['selection'] and model_fields['model']['selection'][0][0]
def _default_res(self):
model = self._default_model()
res = self.env[model].search([], order='id desc', limit=1)
return res and res[0].id
message_id = fields.Many2one('mail.message', string='Message')
message_body = fields.Html(related='message_id.body', string='Message to move', readonly=True)
message_moved_by_message_id = fields.Many2one('mail.message', related='message_id.moved_by_message_id', string='Moved with', readonly=True)
message_moved_by_user_id = fields.Many2one('res.users', related='message_id.moved_by_user_id', string='Moved by', readonly=True)
message_is_moved = fields.Boolean(string='Is Moved', related='message_id.is_moved', readonly=True)
parent_id = fields.Many2one('mail.message', string='Search by name')
res_id = fields.Integer(string='Record ID')
model = fields.Selection(_model_selection, string='Model', default=_default_model)
res_id = fields.Integer(string='Record ID', default=_default_res)
record_url = fields.Char('Link to record', readonly=True)
can_move = fields.Boolean('Can move', compute='get_can_move')
move_back = fields.Boolean('Move to origin', help='Move message and submessages to original place')
model = fields.Selection(_model_selection, string='Model', default=_default_model)
partner_id = fields.Many2one('res.partner', string='Author')
filter_by_partner = fields.Boolean('Filter Records by partner')

Loading…
Cancel
Save