Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to auto attach PDF to e-mail when inheriting function?

By
Yenthe
on 7/14/15, 8:10 AM 1,291 views

Hi guys,

I want to automatically attach my custom report when the user clicks on 'Send by Email' (function action_quotation_send). The first thing that I did is create a custom report. Here is the important code from it:

 <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_saleorder_document_expand">
<!--My report code -->
</template>

<template id="report_saleorder_expand">
    <t t-call="report.html_container">
        <t t-foreach="doc_ids" t-as="doc_id">
            <t t-raw="translate_doc(doc_id, doc_model, 'partner_id.lang', 'aa_maatwerk_u_sentric.report_saleorder_document_expand')"/>
        </t>
    </t>
</template>
</data>
</openerp>

I then created a new report link in XML:

 <?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
       <report 
            id="report_sale_order_expand"
            string="Offerte / Order gedetailleerd"
            model="sale.order" 
            report_type="qweb-pdf"
            file="aa_maatwerk_u_sentric.report_saleorder_expand" 
            name="aa_maatwerk_u_sentric.report_saleorder_expand" 
        />
    </data>
</openerp>

I then created an e-mail template, which is almost identical to the default e-mail that is sent. I've only changed the ref and the name here:

 <!--Email template -->
        <record id="email_template_edi_sale_expand" model="email.template">
            <field name="name">Advanced Sales Order - Send by Email</field>
            <field name="email_from">${(object.user_id.email or '')|safe}</field>
            <field name="subject">${object.company_id.name|safe} ${object.state in ('draft', 'sent') and 'Quotation' or 'Order'} (Ref ${object.name or 'n/a' })</field>
            <field name="partner_to">${object.partner_invoice_id.id}</field>
            <field name="model_id" ref="sale.model_sale_order"/>
            <field name="auto_delete" eval="True"/>
            <field name="report_template" ref="report_sale_order_expand"/>
            <field name="report_name">${(object.name or '').replace('/','_')}_${object.state == 'draft' and 'draft' or ''}</field>
            <field name="lang">${object.partner_id.lang}</field>
            <field name="body_html"><![CDATA[
<div style="font-family: 'Lucica Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
    <p>Hello ${object.partner_id.name},</p>
    
    <p>Here is your ${object.state in ('draft', 'sent') and 'quotation' or 'order confirmation'} from ${object.company_id.name}: </p>
    <p style="border-left: 1px solid #8e0000; margin-left: 30px;">
       &nbsp;&nbsp;<strong>REFERENCES</strong><br />
       &nbsp;&nbsp;Order number: <strong>${object.name}</strong><br />
       &nbsp;&nbsp;Order total: <strong>${object.amount_total} ${object.pricelist_id.currency_id.name}</strong><br />
       &nbsp;&nbsp;Order date:  ${format_tz(object.date_order, tz=user.tz, context={'lang':object.partner_id.lang})} <br />
       % if object.origin:
       &nbsp;&nbsp;Order reference: ${object.origin}<br />
       % endif
       % if object.client_order_ref:
       &nbsp;&nbsp;Your reference: ${object.client_order_ref}<br />
       % endif
       % if object.user_id:
       &nbsp;&nbsp;Your contact: <a href="mailto:${object.user_id.email or ''}?subject=Order ${object.name}">${object.user_id.name}</a>
       % endif
    </p>
    % if object.paypal_url:
    <br/>
    <p>It is also possible to directly pay with Paypal:</p>
        <a style="margin-left: 120px;" href="${object.paypal_url}">
            <img class="oe_edi_paypal_button" src="/sale/static/img/btn_paynowcc_lg.gif"/>
        </a>
    % endif
    <br/>
    <p>If you have any question, do not hesitate to contact us.</p>
    <p>Thank you for choosing ${object.company_id.name or 'us'}!</p>
    <br/>
    <br/>
    <div style="width: 375px; margin: 0px; padding: 0px; background-color: #8E0000; border-top-left-radius: 5px 5px; border-top-right-radius: 5px 5px; background-repeat: repeat no-repeat;">
        <h3 style="margin: 0px; padding: 2px 14px; font-size: 12px; color: #DDD;">
            <strong style="text-transform:uppercase;">${object.company_id.name}</strong></h3>
    </div>
    <div style="width: 347px; margin: 0px; padding: 5px 14px; line-height: 16px; background-color: #F2F2F2;">
        <span style="color: #222; margin-bottom: 5px; display: block; ">
        % if object.company_id.street:
            ${object.company_id.street}<br/>
        % endif
        % if object.company_id.street2:
            ${object.company_id.street2}<br/>
        % endif
        % if object.company_id.city or object.company_id.zip:
            ${object.company_id.zip} ${object.company_id.city}<br/>
        % endif
        % if object.company_id.country_id:
            ${object.company_id.state_id and ('%s, ' % object.company_id.state_id.name) or ''} ${object.company_id.country_id.name or ''}<br/>
        % endif
        </span>
        % if object.company_id.phone:
            <div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; ">
                Phone:&nbsp; ${object.company_id.phone}
            </div>
        % endif
        % if object.company_id.website:
            <div>
                Web :&nbsp;<a href="${object.company_id.website}">${object.company_id.website}</a>
            </div>
        %endif
        <p></p>
    </div>
</div>
            ]]></field>
        </record>

And eventually I inherited the function action_quotation_send to modify it to my needs:

 class sale_order(osv.osv):
    _inherit = 'sale.order'
    def action_quotation_send(self, cr, uid, ids, context=None):
        '''
        This function opens a window to compose an email, with the edi sale template message loaded by default
        '''
        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, 'aa_maatwerk_u_sentric', 'email_template_edi_sale_expand')[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 = dict()
        ctx.update({
            'default_model': 'sale.order',
            'default_res_id': ids[0],
            'default_use_template': bool(template_id),
            'default_template_id': template_id,
            'default_composition_mode': 'comment',
            'mark_so_as_sent': True
        })
        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,
        }

But when I want to install the module I will get the following error:

 File "/odoo/odoo-server/openerp/addons/base/ir/ir_model.py", line 908, in xmlid_lookup
    raise ValueError('External ID not found in the system: %s' % (xmlid))
ParseError: "External ID not found in the system: aa_maatwerk_u_sentric.report_sale_order_expand" while parsing /odoo/odoo-server/addons/aa_maatwerk_u_sentric/templates.xml:432

So what exactly am I missing or referencing incorrect? I don't see what is wrong..

Thanks,
Yenthe

1

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 7/15/15, 2:04 AM

Might be there is an issue inside your __openerp__.py / 'data' : ['email_template.xml' , 'report.xml']. If email_template is before report file in the given list then system raise this error.

I've converted your comment to an answer since this was exactly the problem! This really makes sense since the module doesn't know about it yet at that point. Thanks a lot Emipro! Accepted and upvoted, enjoy that karma. :)

Yenthe
on 7/15/15, 2:05 AM

At the end, your problem is solved, that matters !

Emipro Technologies Pvt. Ltd.
on 7/15/15, 2:06 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/14/15, 8:10 AM
Seen: 1291 times
Last updated: 9/17/15, 2:59 PM