Skip to content

Commit

Permalink
[IMP] Open Related record
Browse files Browse the repository at this point in the history
[FIX] unlink event if date is empty
  • Loading branch information
yelizariev committed May 8, 2015
1 parent 0206a60 commit e5c10d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
18 changes: 17 additions & 1 deletion reminder_base/reminder_base_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def _check_update_reminder(self, vals):
@api.one
def _update_reminder(self, vals):
if not self._check_update_reminder(vals):
print 'no _update_reminder', vals
return

vals = {'name': self._get_reminder_event_name()[0]}
Expand All @@ -54,6 +53,9 @@ def _update_reminder(self, vals):

fdate = self._fields[self._reminder_date_field]
fdate_value = getattr(self, self._reminder_date_field)
if not fdate_value:
event.unlink()
return
if fdate.type == 'date':
vals.update({
'allday': True,
Expand Down Expand Up @@ -101,3 +103,17 @@ class calendar_event(models.Model):

reminder_res_model = fields.Char('Related Document Model for reminding')
reminder_res_id = fields.Integer('Related Document ID for reminding')

@api.multi
def open_reminder_object(self):
r = self[0]
target = self._context.get('target', 'current')
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': r.reminder_res_model,
'res_id': r.reminder_res_id,
'views': [(False, 'form')],
'target': target,
}
18 changes: 17 additions & 1 deletion reminder_base/reminder_base_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form"/>
<field name="arch" type="xml">
<xpath expr="//label[@for='description']" position="before">
<xpath expr="//label[@for='description']" position="after">
<field name="reminder_res_id" invisible="1"/>
<button string="Open Related Record" name="open_reminder_object" type="object" attrs="{'invisible':[('reminder_res_id', '=', 0)]}"/>
</xpath>
</field>
</record>

<record model="ir.ui.view" id="view_calendar_event_form_popup">
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form_popup"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='name']" position="after">
<field name="reminder_res_id" invisible="1"/>
<div attrs="{'invisible':[('reminder_res_id', '=', 0)]}">
<label for="open_reminder_object"/>
<button string="Open Related Record" name="open_reminder_object" type="object"/>
</div>
</xpath>
</field>
</record>


</data></openerp>

0 comments on commit e5c10d3

Please sign in to comment.