Browse Source

Updated Record ID depending on model

pull/1/head
Veronika Kotovich 9 years ago
parent
commit
a2d93ea53f
  1. 1
      __init__.py
  2. 2
      __openerp__.py
  3. 1
      controllers/__init__.py
  4. 30
      controllers/main.py
  5. 4
      mail_move_message_models.py
  6. 5
      mail_move_message_views.xml

1
__init__.py

@ -1 +1,2 @@
import controllers
import mail_move_message_models

2
__openerp__.py

@ -6,7 +6,7 @@
'website' : 'https://yelizariev.github.io',
'price': 9.00,
'currency': 'EUR',
'depends' : ['mail'],
'depends' : ['mail', 'web_polymorphic_field'],
'images': ['images/inbox.png'],
'data':[
'mail_move_message_views.xml',

1
controllers/__init__.py

@ -0,0 +1 @@
import main

30
controllers/main.py

@ -0,0 +1,30 @@
from openerp.addons.web.controllers.main import DataSet
from openerp.tools.translate import _
from openerp.http import request
class DataSetCustom(DataSet):
def _call_kw(self, model, method, args, kwargs):
res = super(DataSetCustom, self)._call_kw(model, method, args, kwargs)
if 'context' in kwargs and kwargs['context'].get('extended_name_with_contact') and res:
model = request.session.model(model)
fields = model.fields_get(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([r[0] for r in res], [contact_field])
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])))
res = final_res
return res

4
mail_move_message_models.py

@ -11,10 +11,11 @@ class wizard(models.TransientModel):
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')
model_id = fields.Many2one('ir.model', string='Model')
res_id = fields.Integer('Record ID')
res_id = fields.Many2one('ir.model', string='Record ID')
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.Char('Model', related='model_id.model')
@api.depends('message_id')
@api.one
@ -51,6 +52,7 @@ class wizard(models.TransientModel):
def on_change_res(self):
if not ( self.model_id and self.res_id ):
self.record_url = ''
return
self.record_url = '/web#id=%s&model=%s' % (self.res_id, self.model_id.model)

5
mail_move_message_views.xml

@ -15,6 +15,7 @@
<form string="Move Message">
<field name="can_move" invisible="1"/>
<field name="message_is_moved" invisible="1"/>
<field name="model" widget="polymorphic" polymorphic="res_id" invisible="1"/>
<p attrs="{'invisible':[('can_move', '!=', False)]}">You cannot move this message. It was already moved with a message bellow. Open one and apply changes there.</p>
<group attrs="{'invisible':[('can_move', '!=', False)]}">
@ -25,8 +26,8 @@
<group attrs="{'invisible':[('can_move', '=', False)]}" col="4">
<field name="move_back" attrs="{'invisible':[('message_is_moved','=',False)]}" colspan="4"/>
<field name="parent_id" domain="[('parent_id','=', False)]" context="{'extended_name':1}" colspan="4"/>
<field name="model_id" colspan="2" />
<field name="res_id" colspan="2"/>
<field name="model_id" colspan="2"/>
<field name="res_id" colspan="2" context="{'extended_name_with_contact':1}"/>
<field name="record_url" colspan="4" widget="url"/>
</group>
<button name="move" string="Move" type="object" class="oe_highlight" attrs="{'invisible':[('can_move', '=', False)]}"/>

Loading…
Cancel
Save