Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poder treure accions d'una plantilla #160

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions poweremail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,8 @@ def copy(self, cr, uid, id, default=None, context=None):
if check:
new_name = new_name + '_' + random.choice('abcdefghij') + random.choice('lmnopqrs') + random.choice('tuvwzyz')
default.update({'name':new_name})
# Clean no to copy values
default.update({'ref_ir_act_window':False, 'ref_ir_value': False})
return super(poweremail_templates, self).copy(cr, uid, id, default, context)

def compute_pl(self,
Expand Down Expand Up @@ -1178,6 +1180,23 @@ def create_action_reference(self, cursor, uid, ids, context):
'ref_ir_value': ref_ir_value,
}, context)

def remove_action_reference(self, cursor, uid, ids, context):
values_obj = self.pool.get('ir.values')
action_obj = self.pool.get('ir.actions.act_window')
template = self.pool.get('poweremail.templates').browse(
cursor, uid, ids[0]
)

if template.ref_ir_act_window:
action_id = template.ref_ir_act_window.id
template.write({'ref_ir_act_window': False})
action_obj.unlink(cursor, uid, action_id)

if template.ref_ir_value:
value_id = template.ref_ir_value.id
template.write({'ref_ir_value': False})
values_obj.unlink(cursor, uid, value_id)


poweremail_templates()

Expand Down
7 changes: 7 additions & 0 deletions poweremail_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@
attrs="{'readonly':[('ref_ir_act_window', '!=', False), ('ref_ir_value', '!=', False)]}"
icon="gtk-execute"
/>
<button
string="Remove action and value"
colspan="1" name="remove_action_reference"
type="object"
attrs="{'readonly':[('ref_ir_act_window', '=', False), ('ref_ir_value', '=', False)]}"
icon="gtk-execute"
/>
<separator string="Expression builder" colspan="4"/>
<field name="template_language" on_change="onchange_null_value(model_object_field,sub_model_object_field,null_value,template_language,context)" colspan="4"/>
<notebook colspan="4">
Expand Down
18 changes: 17 additions & 1 deletion tests/test_poweremail_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,20 @@ def test_send_wizards_gets_default_priority_from_template(self):
'template_id': tmpl_id
})
wiz = send_obj.browse(cursor, uid, wiz_id)
self.assertEqual(wiz.priority, '2')
self.assertEqual(wiz.priority, '2')

def test_remove_action_reference(self):
tmpl_obj = self.openerp.pool.get('poweremail.templates')
cursor = self.cursor
uid = self.uid
tmpl_id = self.create_template()
template = tmpl_obj.browse(cursor, uid, tmpl_id)
template.create_action_reference({})
template = tmpl_obj.browse(cursor, uid, tmpl_id)
self.assertTrue(template.ref_ir_act_window)
self.assertTrue(template.ref_ir_value)
template = tmpl_obj.browse(cursor, uid, tmpl_id)

template.remove_action_reference({})
self.assertFalse(template.ref_ir_act_window)
self.assertFalse(template.ref_ir_value)