← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/contract-management/7.0-block-send-email-lep into lp:contract-management

 

Leonardo Pistone @ camptocamp has proposed merging lp:~camptocamp/contract-management/7.0-block-send-email-lep into lp:contract-management.

Requested reviews:
  Contract Management Core Editors (contract-management-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/contract-management/7.0-block-send-email-lep/+merge/200812
-- 
https://code.launchpad.net/~camptocamp/contract-management/7.0-block-send-email-lep/+merge/200812
Your team OpenERP Community Reviewer/Maintainer is subscribed to branch lp:contract-management.
=== modified file 'analytic_hours_block/__openerp__.py'
--- analytic_hours_block/__openerp__.py	2012-12-17 14:42:58 +0000
+++ analytic_hours_block/__openerp__.py	2014-01-08 11:56:29 +0000
@@ -44,6 +44,7 @@
         ],
     "data": [
         "hours_block_view.xml",
+        "hours_block_data.xml",
         "hours_block_menu.xml",
         "report.xml",
         "security/hours_block_security.xml",

=== modified file 'analytic_hours_block/hours_block.py'
--- analytic_hours_block/hours_block.py	2012-12-18 11:05:03 +0000
+++ analytic_hours_block/hours_block.py	2014-01-08 11:56:29 +0000
@@ -24,6 +24,7 @@
 
 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 @@
             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),

=== added file 'analytic_hours_block/hours_block_data.xml'
--- analytic_hours_block/hours_block_data.xml	1970-01-01 00:00:00 +0000
+++ analytic_hours_block/hours_block_data.xml	2014-01-08 11:56:29 +0000
@@ -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>

=== modified file 'analytic_hours_block/hours_block_view.xml'
--- analytic_hours_block/hours_block_view.xml	2012-12-18 08:46:36 +0000
+++ analytic_hours_block/hours_block_view.xml	2014-01-08 11:56:29 +0000
@@ -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>
-
-                    <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="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="currency_id"/>
-                        <newline/>
-                        <field name="residual" sum="Residual Amount"/>
-                        <field name="amount_total" sum="Total Amount"/>
-                        <field name="state"/>
-                    </group>
-                </sheet>
+                    <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>
+                            <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"/>
+
+                            <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>
+                    <div class="oe_chatter">
+                        <field name="message_follower_ids" widget="mail_followers"/>
+                        <field name="message_ids" widget="mail_thread"/>
+                    </div>
                 </form>
             </field>
         </record>


Follow ups