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.

2

Odoo V8 problem: Custom Module inheriting account.invoice still loads standard invoice template - what am I doing wrong?

By
NSC
on 7/12/15, 4:13 PM 1,676 views

My issue, see above... I created a custom module while studying some information about that in the web. But yet without any real success... I can install my module without any error messages and the appropriate menu entry appears in account.invoice view, but when pressing it, the old standard template is shown and not my own report template which is inside my external module. Can you tell me why not? I think, I did not do anything other than in former times for OpenERP v7, only considering API and report engine changes of Odoo v8.

What I have not yet understood, is how new report engine has to find my .xml report template (which replaces old .rml one). One of the blog entries I read about that claims, this template needs to be in folder "views" inside my module folder (not any more in folder "reports" like before with RML reporting) and that it is found there via its template_id. I did so - I put it there, but obviously, it is NOT found this way. But no example in the web regarding that issue uses an entire path to this report template like before with rml! Can anybody explain me how I have to "explain" the module where my own report template is located?

I used these tutorials as a base (sorry, I did not manage to insert them as links - this did not work; dunno why not):

http://www.zbeanztech.com/blog/qweb-report

http://blog.emiprotechnologies.com/create-qweb-report-odoo/


Here are some code sequences (please tell me where they are erroneous or incompatible with Odoo V8):

Report Parser and simple minimal report template to get started:

# -*- coding: utf-8 -*-
##############################################################################
# Modification of standard invoice template
##############################################################################

import time
from openerp.report import report_sxw
from openerp.osv import osv

class my_account_invoice(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(fq_account_invoice, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'time': time,
})

#remove previous sale.report service :
#from netsvc import Service
#del Service._services['account.report_invoice']

class myreportinvoice(osv.AbstractModel): #individual name, but extending osv.AbstractModel
_name = 'report.account.report_invoice' #_name = ‘report.<module_name>.<report_name>’
_inherit = 'report.abstract_report'
_template='account.report_invoice' #_template = ‘<module_name>.<report_name>’
_wrapped_report_class=my_account_invoice #_wrapped_report_class = <parser_class_name>

<template id="report_invoice">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="report.external_layout">
<div class="page">
<h2>New Invoice Template</h2>
<p>This object's name is <span t-field="o.name"/></p>
</div>
</t>
</t>
</t>
</template>

Menu Entry:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
id="my_account_invoices"
model="account.invoice"
string="My New Invoice"
report_type="qweb-pdf"
name="account.report_invoice"
file="account.report_invoice"
attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
attachment_use="False"
/>
</data>
</openerp>

If I replace the original ID 'report_invoice' to an own, individual one, for example 'report_my_invoice', I get the following error:
QWebTemplateNotFound: External ID not found in the system: account.report_my_invoice

But in settings --> reports, it looks like my new report is registered in a right way: The old original one has its own views, and my new one, too. Looks good, so far, but nevertheless, I can not print it because of this error. If it is registered with this ID in settings --> reports, why this error? Any idea ???



1
David Bertha
On 7/13/15, 3:32 AM

The module name should be your module name, not the name of the inherited module.

What's in your __openerp__.py file ?

I made a custom report for invoice too :

report_group_invoice.xml :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="report_group_invoice_document">
...
</template>
<template id="report_group_invoice">
<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', 'delivery_carrier_pickingup.report_group_invoice_document')"/>
</t>
</t>
</template>
</data>
</openerp>


report.xml :


<report 
id="delivery_grouped_invoice"
model="account.invoice"
string="Grouped invoice"
report_type="qweb-pdf"
name="delivery_carrier_pickingup.report_group_invoice"
file="delivery_carrier_pickingup.report_group_invoice"
attachment_use="True"
attachment="(object.state in ('open','paid')) and ('INV'+(object.number or '').replace('/','')+'.pdf')"
/>

Those 2 files are in the "data" list of my openerp.py file

If you want to add arguments to the qweb engine :


class GroupedInvoiceReport(models.AbstractModel):
_name = 'report.delivery_carrier_pickingup.report_group_invoice'
def render_html(self, cr, uid, ids, data=None, context=None):
"""Add period start and period end from context to args of report template"""
if context is None :
    context= {}
report_obj = self.pool['report']
report = report_obj._get_report_from_name(cr, uid, 'delivery_carrier_pickingup.report_group_invoice')
docargs = {
'doc_ids': ids,
'doc_model': report.model,
'docs': self.pool.get('account.invoice').browse(cr,uid, ids,context=context),
}
docargs.update(<arguments>)
return report_obj.render(cr, uid, ids, 'delivery_carrier_pickingup.report_group_invoice', docargs, context=context)

My answer to NSC :
A report entry (with the <report/> tag) define a report, not a menu entry : https://www.odoo.com/documentation/8.0/reference/reports.html


Okay then, maybe pointing out this misunderstanding of mine has already cleared up my mind for that - if report-tag is not only for menu entry but all the report definition, then model-tag inside seems to be underlying data source for it...

NSC
on 7/13/15, 6:27 AM
1
NSC
On 7/13/15, 4:25 AM

This is an answer of @David Bertha's post - I can do what I want; it will not appear under the post it refers to :(:

Thank you for this, David! I think, you have just acknowledged what I found out later in the night! When refering to my own module overall and not any more to account, I was able to load my minimal template to get started when pressing the menu item! The only location left where I referenced account model is model field in menu entry (report.xml in your example). But this is only for the menu to know where to appear, isn't it?

What I am still wondering about is, how the module can know which data models it can access... I have not yet accessed any field for account.invoice in my getting-started-minimal-template (it is still nothing else than a skeleton), but I will try later on, if I can access any field.

In every case, if the "original" id/model should not be referenced, this does not definitely seem to be a "real" inheritance mechanism, but full autonomism of custom report module. The only question left for me would then be the one mentioned above - how to specify which data models the module may access. Could you, @David Bertha (or anybody else) clear up my mind regarding that?


//Edit:

Problem solved by only referencing to own module name and not the one of the model I wish to use data from in my report

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/12/15, 4:13 PM
Seen: 1676 times
Last updated: 12/10/16, 2:48 AM