Odoo 8 - Qweb output PDF for HR Evaluation Report - pdf

when clicking the Print Survey button (Human Resources - Apraissal - Interview Requests), the standard output is HTML (action_print_survey method). I want to change output to PDF.
I couldn't find on Odoo configuration nor standard structure for Qweb reports the way they do it as the standard stands (template yes, menu no, python wrapper no).
I tried to right a wrapper but it doesn't work.
Any ideas?
Thanks in advance
Gustavo

Report
Every report must be declared by a report action.
For simplicity, a shortcut <report> element is available to define a report, rather than have to set up the action and its surroundings manually. That <report> can take the following attributes:
id :
the generated record's external id
name (mandatory):
only useful as a mnemonic/description of the report when looking for one in a list of some sort
model (mandatory):
the model your report will be about
report_type (mandatory) :
either qweb-pdf for PDF reports or qweb-html for HTML
report_name :
the name of your report (which will be the name of the PDF output)
groups:
Many2many field to the groups allowed to view/use the current report
attachment_use:
if set to True, the report will be stored as an attachment of the record using the name generated by the attachment expression; you can use this if you need your report to be generated only once (for legal reasons, for example)
attachment:
python expression that defines the name of the report; the record is acessible as the variable object
Example :
<report
id="account_invoices"
model="account.invoice"
string="Invoices"
report_type="qweb-pdf"
name="account.report_invoice"
file="account.report_invoice"
attachment_use="True"
attachment="(object.state in ('open','paid')) and
('INV'+(object.number or '').replace('/','')+'.pdf')"
/>
Reference Link : https://www.odoo.com/documentation/8.0/reference/reports.html

#Gustavo
That is not an html report, it's a rendered template in response to the request for print the survey using that button action. That's why you couldn't find any declaration for the report but you could easily do it by changing the method definition of the model survey.survey like:
def action_print_survey(self, cr, uid, ids, context=None):
context = dict(context or {}, active_ids=ids, active_model=self._name)
return {
'type': 'ir.actions.report.xml',
'report_name': 'module.survey_print',
'context': context,
}
Also you need to define the report module.survey_print to use the original template. For that you could see how to do it on:
https://www.odoo.com/fr_FR/forum/help-1/question/how-to-define-a-custom-methods-functions-to-be-used-in-a-qweb-report-how-to-define-and-use-a-report-parser-92244

Related

How do I get a field in odoo 15 from res.partner module shown in account.move?

In odoo 15 I have created a PDF report for invoices using a custom layout via an external module. The address of the customer is specified at the top left of the first page of the PDF report. The content comes from the record that was created via "Customer" (res.partner) and selected via the field "partner_id". After the selection, the street and postal code as well as city are loaded in the edit view of an invoice and thus transferred to the PDF document.
How can I extend or overwrite the address field in my custom report layout to create an own address field that comes from the customer data (model res.partner)? I have created an additional field there via a module (address_suffix) that can store an address addition. I would like to be able to include this custom field of res.partner in the address field at account.move and in the end into the PDF report.
To illustrate it:
I want this field (address_suffix in res.partner)
can be seen here (account.move):
You can check the OCA partner_address_street3 module. It is similar to yours, it adds a third street field (street3) to store additional address information.
The module extends the address format, so it should automatically show on reports
On your report xm, I think you can try using t-field and using widget contact inside the t-options tag.
Example:
<span t-field="partner_id" t-options='{"widget": "contact", "fields": ["address"]}'/>

change the font size of qweb report dynamically

Is there a module or a way to define the font size of qweb report dynamically for example on the configuration without change it on the code?
You can create a field (or fields) on the res.company module to define font_size or any other features you want and then call them from QWeb this:
# Field can be Integer or Float
<p t-attf-style="font-size: #{o.company_id and o.company_id.font_size or '12'}px;">
# Field can be Char, but is more prone to possible user input error
<p t-attf-style="font-size: #{o.company_id and o.company_id.font_size or '12px'};">
Of course, this requires that whatever model your report is for must have a company_id field to pull from. However, most models have this already, so it is a fairly safe assumption.
This technique isn't really noted anywhere in the documentation, but I'll link to it anyway.
Qweb Documentation
Reports Documentation

How to display custom fields in rally?

I have a ruby script that is trying to pull up some custom fields from Rally, the filter works just fine ( the filter contains one of the custom fields i want to pull up) but when I try to display it, it doesn't show up in the list (the value returned for all custom fields is blank, while appropriate values are returned for FormattedID, Name, Description).
Here's the link [link]http://pastebin.ubuntu.com/6124958/
Please see this post.
Do you fetch the fields?
What version of WS API are you using? If it is v2.0 is c_ prepended to the name of the field in the code?
How is the field spelled in your code and how that spelling compares to Name and Display Name of the field in UI?
There is another reason why custom fields might not appear (other than the versioning and 'c_' issues nickm mentioned). I just found this out after a ton of head banging. The Rally SDK's ui stuff will filter out all fields that are hidden (such as _ref, or other 'hidden' custom fields) so you cannot view them in your apps in grids, charts, etc. For example, when constructing a Rally.ui.grid.Grid, a class called Rally.ui.grid.ColumnBuilder is constructed and it executes a command on the columns of the chart that look like this:
_removeHiddenColumns: function (columns) {
return _.filter(columns, function (column) {
return !column.modelField || !column.modelField.hidden;
});
},
As you can see, if you try to display any fields that are hidden (like _ref for example) in a grid, the column gets removed. So, although you may be fetching the custom fields, they will not show up unless those fields are not 'hidden'.

How use a fields of module A in module B

i have two module opportunities and job positions .
i am trying to use only one field of "job positions" name Employees in "opportunities" module.
i am new in openerp and have no knowledge about python . so i am using developer option of openerp . i am attaching my both module file .
Is there any attribute of fields or other so my field will use the value of other module values like as :-
crm.lead xml file:-
<field name="name" module="hr.job" />
here module is not using value of "hr.job" and using of "crm.lead" value.
if i used other name it give me "not field found" error.
please expert help me
You seem pretty confused. What you've attached are view files for your modules, for instance one of them is the form view for object named hr.job. This is not as you call it "module files".
What you need to do is create a many2one (or many2many) field from the referenced object you want to the target object you need, meaning adding a field to whatever class's columns you need in the corresponding py file and not view. A very simple example for a class named opportunity_opportunity:
class opportunity_opportunity (osv.osv):
_name = "opportunity.opportunity"
_columns = {
'name' : fields.char('Name', size=64),
'employee_id': fields.many2one('job.position','name')
}
opportunity_opportunity()
you can later add it in the opportunity_view.xml file as any other field:
<field name="employee_id" string="Employee"/>
More importantly, I think you need to seriously first read and understand the developer book: OpenERP 6.1 Developer Book
EDIT: I just noticed you had already posted the same question yesterday here link, this is very frowned upon in stackoverflow. Please take your time to read the openerp documentation before posting questions.

Can I inherit from a standard report in OpenERP?

I want to make changes to the purchase order report in OpenERP 6.1. Do I have to go in and make changes to the purchase module, or can I create a new module that will inherit the standard report and override some details.
You can't exactly inherit another report and just override some details, but you can replace a standard report and make all existing links to it launch your new report instead.
Our zaber_purchase module contains some changes to the purchase order report that our users wanted. Here's the purchase_report.xml file that replaces the standard report with ours.
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<report
auto="False"
id="purchase.report_purchase_order"
model="purchase.order"
name="purchase.order.zaber"
rml="zaber_purchase/report/order.rml"
string="Purchase Order"
usage="default"/>
</data>
</openerp>
Since it's not inheriting but replacing the report, you have to duplicate the whole report in your version. Your report's id has to match the original report's id, including the module name. In the example above, the original report has an id of report_purchase_order, and it's part of the purchase module, so your report id must be purchase.report_purchase_order to replace it. The name has to match the name in your version's parser file, and the rml attribute has to point to your version's RML file.
Thanks to mihai for explaining most of this in the OpenERP forum.
Don Kirkby has a good answer, and after banging my head on a wall for an hour, I'd like to expand it. But stackoverflow, in all its wisdom, won't let me comment on it because I don't have enough rep points, so instead, I'll spam the question with an unanswer.
By "The id has to match the original report's id, including the module name," Don means that if foomodule has <report id="fooreport" ...>, then in your module you will need to say <report id="foomodule.fooreport" ...>. This is because the ids declared by each module live in a namespace scoped to that module. If you don't reference the other (the one you are overriding) module's namespace, then you just end up creating a new report with the same name which is Bad.
For kicks, check out the database tables ir_act_report_xml, which has all the reports, and ir_model_data, which associates reports (and everything else) with the id attribute from the XML that defined the thing.
RML parser classes are registered globally as Services. For example the Sale Order parser class is registered in addons/sale/report/sale_order.py with
report_sxw.report_sxw('report.sale.order', 'sale.order', 'addons/sale/report/sale_order.rml', parser=order, header="external")
If you try to create another parser with the same name, you get an error : The report "sale.order" already exists!
A simple way to replace the sale.order parser and use a custom parser class is to remove it from the global service registry with :
from netsvc import Service
del Service._services['report.sale.order']
Here is a full example we used to conditionally hide the Discount column in the sale order report if there is no discount
from sale.report import sale_order
from report import report_sxw
# create a custom parser inherited from sale order parser:
class new_order_parser(sale_order.order):
'''Custom parser with an additional method
'''
def __init__(self, cr, uid, name, context):
super(new_order_parser, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'has_line_discount': self._has_line_discount,
})
def _has_line_discount(self, order):
return any([l.discount for l in order.order_line])
# remove previous sale.report service :
from netsvc import Service
del Service._services['report.sale.order']
# register the new report service :
report_sxw.report_sxw(
'report.sale.order',
'sale.order',
'addons/path/to/the/sale_order.rml',
parser=new_order_parser
)