mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[imp] add mail thread with report attached to hours block
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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),
|
||||
|
||||
24
analytic_hours_block/hours_block_data.xml
Normal file
24
analytic_hours_block/hours_block_data.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" ?>
|
||||
<openerp>
|
||||
<!-- Mail template are declared in a NOUPDATE block
|
||||
so users can freely customize/delete them -->
|
||||
<data noupdate="1">
|
||||
<record id="email_template_hours_block" model="email.template">
|
||||
<field name="name">Hours Block - Send by Email</field>
|
||||
<field name="email_from">${(object.user_id.email or object.company_id.email or 'noreply@localhost')|safe}</field>
|
||||
<field name="subject">${object.company_id.name} Hours Block (Ref ${object.number or 'n/a'})</field>
|
||||
<field name="email_recipients">${object.partner_id.id}</field>
|
||||
<field name="model_id" ref="analytic_hours_block.model_account_hours_block"/>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="report_template" ref="block_hours_report"/>
|
||||
<field name="report_name">Hours_Block_${(object.number or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''}</field>
|
||||
<field name="lang">${object.partner_id.lang}</field>
|
||||
<field name="body_html"><![CDATA[
|
||||
<p>Hello ${object.partner_id.name},</p>
|
||||
|
||||
<p>Please find attached your Hours Block Report.</p>
|
||||
<p>Best regards.</p>
|
||||
]]></field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -41,44 +41,51 @@
|
||||
<field name="model">account.hours.block</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Hours Blocks" version="7.0">
|
||||
<sheet>
|
||||
<h1>
|
||||
<field name="invoice_id" placeholder="Choose an invoice..."/>
|
||||
<label for="type" string="Based on:" class="oe_inline"/>
|
||||
<field name="type" class="oe_inline"/>
|
||||
</h1>
|
||||
<header>
|
||||
<button name="action_send_block" type="object" string="Send by Email" class="oe_highlight"/>
|
||||
</header>
|
||||
<sheet>
|
||||
<h1>
|
||||
<field name="invoice_id" placeholder="Choose an invoice..."/>
|
||||
<label for="type" string="Based on:" class="oe_inline"/>
|
||||
<field name="type" class="oe_inline"/>
|
||||
</h1>
|
||||
|
||||
<group>
|
||||
<field name="last_action_date" />
|
||||
<field name="close_date" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="last_action_date" />
|
||||
<field name="close_date" />
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<separator colspan="4" string="Hours Quantity / Amount"/>
|
||||
<field name="amount_hours_block" string="Bought"/>
|
||||
<field name="amount_hours_block_done" string="Used"/>
|
||||
<field name="amount_hours_block_delta" string="Difference"/>
|
||||
</group>
|
||||
<group>
|
||||
<separator colspan="4" string="Hours Quantity / Amount"/>
|
||||
<field name="amount_hours_block" string="Bought"/>
|
||||
<field name="amount_hours_block_done" string="Used"/>
|
||||
<field name="amount_hours_block_delta" string="Difference"/>
|
||||
</group>
|
||||
|
||||
<group>
|
||||
<separator colspan="4" string="Invoice's related information"/>
|
||||
<field name="date_invoice"/>
|
||||
<field name="name"/>
|
||||
<field name="number"/>
|
||||
<field name="partner_id" groups="base.group_user"/>
|
||||
<field name="user_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
<group>
|
||||
<separator colspan="4" string="Invoice's related information"/>
|
||||
<field name="date_invoice"/>
|
||||
<field name="name"/>
|
||||
<field name="number"/>
|
||||
<field name="partner_id" groups="base.group_user"/>
|
||||
<field name="user_id"/>
|
||||
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
|
||||
|
||||
<field name="journal_id" invisible="1"/>
|
||||
<field name="period_id" invisible="1" groups="account.group_account_user"/>
|
||||
<field name="journal_id" invisible="1"/>
|
||||
<field name="period_id" invisible="1" groups="account.group_account_user"/>
|
||||
|
||||
<field name="currency_id"/>
|
||||
<newline/>
|
||||
<field name="residual" sum="Residual Amount"/>
|
||||
<field name="amount_total" sum="Total Amount"/>
|
||||
<field name="state"/>
|
||||
</group>
|
||||
</sheet>
|
||||
<field name="currency_id"/>
|
||||
<newline/>
|
||||
<field name="residual" sum="Residual Amount"/>
|
||||
<field name="amount_total" sum="Total Amount"/>
|
||||
<field name="state"/>
|
||||
</group>
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" widget="mail_followers"/>
|
||||
<field name="message_ids" widget="mail_thread"/>
|
||||
</div>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user