diff --git a/analytic_hours_block/__openerp__.py b/analytic_hours_block/__openerp__.py index 09c78ad7..d6ae9142 100644 --- a/analytic_hours_block/__openerp__.py +++ b/analytic_hours_block/__openerp__.py @@ -44,6 +44,7 @@ you can track and follow how much has been used. ], "data": [ "hours_block_view.xml", + "hours_block_data.xml", "hours_block_menu.xml", "report.xml", "security/hours_block_security.xml", diff --git a/analytic_hours_block/hours_block.py b/analytic_hours_block/hours_block.py index b341702a..064edca5 100644 --- a/analytic_hours_block/hours_block.py +++ b/analytic_hours_block/hours_block.py @@ -24,6 +24,7 @@ from openerp.osv import orm, fields class AccountHoursBlock(orm.Model): _name = "account.hours.block" + _inherit = ['mail.thread'] def _get_last_action(self, cr, uid, ids, name, arg, context=None): """ Return the last analytic line date for an invoice""" @@ -163,6 +164,47 @@ class AccountHoursBlock(orm.Model): block_ids.update([inv.id for inv in invoice.account_hours_block_ids]) return list(block_ids) + def action_send_block(self, cr, uid, ids, context=None): + """Open a form to send by email. Return an action dict.""" + + assert len(ids) == 1, '''\ + This option should only be used for a single ID at a time.''' + + ir_model_data = self.pool.get('ir.model.data') + + try: + template_id = ir_model_data.get_object_reference( + cr, uid, 'analytic_hours_block', 'email_template_hours_block' + )[1] + except ValueError: + template_id = False + + try: + compose_form_id = ir_model_data.get_object_reference( + cr, uid, 'mail', 'email_compose_message_wizard_form' + )[1] + except ValueError: + compose_form_id = False + + ctx = context.copy() + ctx.update({ + 'default_model': self._name, + 'default_res_id': ids[0], + 'default_use_template': bool(template_id), + 'default_template_id': template_id, + 'default_composition_mode': 'comment', + }) + return { + 'type': 'ir.actions.act_window', + 'view_type': 'form', + 'view_mode': 'form', + 'res_model': 'mail.compose.message', + 'views': [(compose_form_id, 'form')], + 'view_id': compose_form_id, + 'target': 'new', + 'context': ctx, + } + _recompute_triggers = { 'account.hours.block': (lambda self, cr, uid, ids, c=None: ids, ['invoice_id', 'type'], 10), diff --git a/analytic_hours_block/hours_block_data.xml b/analytic_hours_block/hours_block_data.xml new file mode 100644 index 00000000..dc5f9eaa --- /dev/null +++ b/analytic_hours_block/hours_block_data.xml @@ -0,0 +1,24 @@ + + + + + + Hours Block - Send by Email + ${(object.user_id.email or object.company_id.email or 'noreply@localhost')|safe} + ${object.company_id.name} Hours Block (Ref ${object.number or 'n/a'}) + ${object.partner_id.id} + + + + Hours_Block_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''} + ${object.partner_id.lang} + Hello ${object.partner_id.name},

+ +

Please find attached your Hours Block Report.

+

Best regards.

+ ]]>
+
+
+
diff --git a/analytic_hours_block/hours_block_view.xml b/analytic_hours_block/hours_block_view.xml index a81bc136..3c6da3a5 100644 --- a/analytic_hours_block/hours_block_view.xml +++ b/analytic_hours_block/hours_block_view.xml @@ -41,44 +41,51 @@ account.hours.block
- -

- -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+ +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ + +