[MERGE] merged with latest contract-management

This commit is contained in:
Matthieu Dietrich
2014-02-03 14:46:45 +01:00
5 changed files with 567 additions and 32 deletions

View File

@@ -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,46 @@ 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 = {
'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),