Generate report from wizard in odoo 9 - report

I need help about generate report from wizard in odoo 9. On internet I'm find one unfinished example. I want get all user is res.user where create_date (field in res.users) >= date_from and =< date_to from my wizzard.
My source:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_my_wiz_form" model="ir.ui.view">
<field name="name">print.report.form</field>
<field name="model">my.test.report</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Print Report">
<group colspan="4" >
<field name="date_from"/>
<field name="date_to" />
</group>
<group colspan="4" col="6">
<button name="print_report" string="Print Users" type="object"/>
</group>
</form>
</field>
</record>
<record id="action_my_wiz_form" model="ir.actions.act_window">
<field name="name">Print Report</field>
<field name="res_model">my.test.report</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_my_wiz_form"/>
<field name="target">new</field>
</record>
<menuitem name="REPORT" id="menu_my_test_report" action="action_my_wiz_form" sequence="19"/>
</data>
</openerp>
.py file
class my_test_report(models.Model):
_name = 'my.test.report'
_description = 'Test Report'
date_from = fields.Date(string = 'From')
date_to = fields.Date(string = 'To')
def print_report(self, cr, uid, ids, context=None):
datas = {}
if context is None:
context = {}
data = self.read(cr, uid, ids,['date_from', 'date_to'], context=context)
date_from = data[0]['date_from']
date_to = data[0]['date_to']
obj = self.pool.get('res.users')
ids = obj.search(cr, uid, [('create_date','>=',date_from),('create_date','<=',date_to)])
print(ids)
datas = {
'ids': ids,
'model': 'res.users',
'form': data
}
return {
'type': 'ir.actions.report.xml',
'report_name': "XXXXXXX,
'datas': datas,
}
Hw create report_name in .py, I'm put XXXXXXXX with several fields from res.users?
After run code without
return {
'type': 'ir.actions.report.xml',
'report_name': "XXXXXXX,
'datas': datas,
}
in console get [3, 4]
I'm try with this xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_sasa_test">
<t t-call="report.html_container">
<t t-set="data_report_margin_top" t-value="12"/>
<t t-set="data_report_header_spacing" t-value="9"/>
<t t-set="data_report_dpi" t-value="110"/>
<t t-foreach="docs" t-as="o">
<div class="page">
<table class="table table-condensed">
<thead>
<tr>
<th>Name</th>
<th>Test</th>
</tr>
</thead>
<tbody>
<tr>
<td><t t-esc="o.name"/></td>
<td><t t-esc="o.name"/></td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</template>
</odoo>
But after generate pdf i get two pdf page with one row i need all data on one page ---> https://postimg.org/image/gbdadtrm5/
Any solution how define this report?
etc.
id | login | signature
3 | 25.01.17 | ---
4 | 25.01.17 | ---

docs variable represents a record on your model by default unless you define it otherwise. I do not see you define it somewhere else here so your problem is that you have the t-foreach="docs" and then you create a page. The t-foreach="docs" should enclose the whole report view and not the page. Take a look at addons/account/views/report_invoince.xml as to how this loops works.
<template id="report_report_sasa_test">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="your_module.report_sasa_test" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>

Related

How to make button in tree view always visible odoo 15

In odoo 15, i've created a button in tree view, but it not always visible, i must click on a record in the tree view to make the button appear.
My code:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="grabfood_orders_tree" model="ir.ui.view">
<field name="name">grabfood.orders.tree</field>
<field name="model">grabfood.orders</field>
<field name="arch" type="xml">
<tree create="false">
<header>
<button string="Read GrabFood API" name="action_read_grabfood_api" type="object" class="btn-primary"/>
</header>
<field name="name"/>
</tree>
</field>
</record>
</data>
</odoo>
Please help, thanks.
Try this:
https://github.com/Tlki/web_tree_header_buttons_always_visible
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="grabfood_orders_tree" model="ir.ui.view">
<field name="name">grabfood.orders.tree</field>
<field name="model">grabfood.orders</field>
<field name="arch" type="xml">
<tree create="false">
<header>
<button string="Read GrabFood API"
name="action_read_grabfood_api" type="object" class="btn-primary"
attrs="{'always_visible': True}"
/>
</header>
<field name="name"/>
</tree>
</field>
</record>
</data>
</odoo>

how to create a button that opens a popup without automatic registration / creation of the form odoo13

I want to create a button that opens a popup that takes over some form fields.
These fields can be modified / filled in.
When closing the fields concerned are updated.
without saving or creating the record before I click on the save button.
I don't see how to get there knowing that there are no relational fields.
Should I create a widget, a wizard, both ....
Help me please.
Here is my current code :
test_scale.py :
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class TestScale(models.Model):
_name = 'test.scale'
name = fields.Char(required=True)
weighing = fields.Integer('weighing', default=0)
test_scale.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="test_scale_tree_view" model="ir.ui.view">
<field name="name">test.scale.tree</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<tree string="Test scale">
<field name="name"></field>
<field name="weighing"></field>
</tree>
</field>
</record>
<record id="test_scale_form_view" model="ir.ui.view">
<field name="name">test.scale.form</field>
<field name="model">test.scale</field>
<field name="arch" type="xml">
<form string="Test scale">
<sheet>
<group name="main_info">
<field name="name"></field>
<field name="weighing"></field>
<button name="%(test_scale_configurator_action)d"
type="action"
string="Weighing"
class="oe_highlight"
context="{'weighing': weighing}"></button>
</group>
</sheet>
</form>
</field>
</record>
<record id="saisie_menu_action" model="ir.actions.act_window">
<field name="name">Test_scale</field>
<field name="res_model">test.scale</field>
<field name="type">ir.actions.act_window</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Aucun enregistrement
</p>
</field>
</record>
<menuitem id="test_scale_menu"
name="Test_scale"/>
<menuitem id="test_scale_saisie_menu"
parent="test_scale_menu"
name="Saisie"
action="saisie_menu_action"/>
</odoo>
test_scale_configurator.xml :
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="test_scale_configurator_view_form" model="ir.ui.view">
<field name="name">test.scale.configurator.view.form</field>
<field name="model">test.scale.configurator</field>
<field name="arch" type="xml">
<form>
<field name="weighing"/>
<footer>
<button type="object"
name="button_save"
string="Save"
/>
<button special="cancel"
string="Cancel"
class="btn-secondary"/>
</footer>
</form>
</field>
</record>
<record id="test_scale_configurator_action" model="ir.actions.act_window">
<field name="name">Test Scale</field>
<field name="res_model">test.scale.configurator</field>
<field name="view_mode">form</field>
<field name="target">new</field>
<field name="view_id" ref="test_scale_configurator_view_form"/>
</record>
</odoo>
test_scale_configurator.py :
# -*- coding: utf-8 -*-
from odoo import models, fields
class TestScaleConfigurator(models.TransientModel):
_name = 'test.scale.configurator'
weighing = fields.Integer(string='weighing')
def button_save(self):
self.ensure_one()
return True
This thing is done by relational fields of odoo , For EX:-
In your test.scale model your field is weighing,
First you need to configure your current model test.scale 's id in wizard so you can reference it, like this you can add the field in wizard.
test_scale_id = fields.Many2one(string="Test Scale")
After that add context in you main model's xml file where is the button which one opens the wizard like this.
<button name="%(test_scale_configurator_action)d"
type="action"
string="Weighing"
class="oe_highlight"
context="{'default_test_scale_id': active_id}"></button>
After that this field needs to be invisible in your wizard's form in order to save data in wizard so you can refernce it later.
<field name="test_scale_id" invisible="1"/>
and in your wizard weighing field is stayed like this.
weighing = fields.Integer(string='weighing', related='test_scale_id.weighing', readonly=False)
Note: This process , making field is one time process.
after that you can use any field which is in your main model and you want to use in wizard you can get those fields by test_scale_id.any_of_your_field.

Odoo 10 : Removing a button from customer form view

I want to remove 'Unpublished on Website' button from customer form view.
This button is not part of form view so when i tried below code ,i got an error that element doesn't exist in parent view:
<xpath expr='//div[#class="oe_button_box"]//button[#name="website_publish_button"]' position='replace'>
<button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
<field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
</button>
</xpath>
Then i tried to remove it using css. My css.css file :
button[name=website_publish_button]
{
display:none !important;
}
and template :
<openerp>
<data>
<!-- Adds all assets in Odoo -->
<template id="assets_backend" name="contacts_custom assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!--These links will be called when loading your Odoo -->
<link rel="stylesheet" href="/contacts_custom/static/css/css.css"/>
</xpath>
</template>
</data>
</openerp>
But still button appears.Am i doing something wrong or Is there any other method to remove this button?
You could do it extending the view like this:
<record id="view_partners_form_website" model="ir.ui.view">
<field name="name">view.res.partner.form.website</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="website_partner.view_partners_form_website"/>
<field eval="18" name="priority"/>
<field name="arch" type="xml">
<data>
<button name="website_publish_button" position="replace">
<button type="object" name="callSurvey" icon="contacts_custom/static/description/survey.png" class="oe_stat_button">
<field string="Surveys" name="survey_count" widget="statinfo" modifiers="{'readonly': true}"/>
</button>
</button>
</data>
</field>
</record>
Add a depends entry to the module website_partner to be able to inherit the view that add the button like the snippet above

ODOO my header doesn't appears in my custom report

I have some trouble with my report header in odoo.
I can't make it appears correctly.
I've made a custom report here's the code:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="report_timesheet">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="doc">
<div class="page">
<t t-call="report.external_layout">
#SOMESTUFF
</t>
</div>
</t>
</t>
</template>
</data>
</odoo>
The thing is my header appears twice when I run this code, I've seen from standard module example that the line
<t t-call="report.external_layout">
should be before
<div class="page">
but when I do that the header doesn't appear at all. Does anyone have any idea about what's going wrong with this?
You can create your report as following:
<template id="report_invoice_document">
<t t-call="report.external_layout">
....
</t>
</template>
<template id="report_invoice">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="account.report_invoice_document" t-lang="o.partner_id.lang"/>
</t>
</t>
</template>

QWebException: "'NoneType' object is not callable" while evaluating 'has_shortage_so_lines(data)==True'

I found the another question at here. But there is no answer.
I got the error
QWebException: "'NoneType' object is not callable" while evaluating 'has_shortage_so_lines(data)==True'
This is my report_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- External Consumption Report -->
<!-- Landscape Paper Format-->
<record id="paperformat_LetterLandscape" model="report.paperformat">
<field name="name">US Letter Landscape</field>
<field name="default" eval="True"/>
<field name="format">Letter</field>
<field name="page_height">0</field>
<field name="page_width">0</field>
<field name="orientation">Landscape</field>
<field name="margin_top">15</field>
<field name="margin_bottom">15</field>
<field name="margin_left">2</field>
<field name="margin_right">2</field>
<field name="header_line" eval="False"/>
<field name="header_spacing">7</field>
<field name="dpi">100</field>
</record>
<!--Report XLS-->
<report
id="action_report_shortage_xls"
model="sale.order"
string="Shortage Report"
report_type="qweb-html"
name="sale.report_shortage_xls"
file="sale.report_shortage_xls"/>
<!--Paper Format to shortage report-->
<record id="action_report_shortage_xls" model="ir.actions.report.xml">
<field name="paperformat_id" ref="stock.paperformat_LetterLandscape"/>
</record>
</data>
</openerp>
This is my report_xls.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- Translatable template -->
<template id="report_shortage_xls">
<div class="workbook">
<div class="worksheet" name="Shortage Report">
<table>
<tbody>
<tr>
<td easyfx="font: height 200;align: horizontal left,vert center">Printed On :</td>
<td><span t-usertime="%d-%m-%Y %H:%M" /></td>
</tr>
<tr>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th colspan="17" easyfx="font: height 400, bold on;align: horizontal center,vert center">Shortage Report</th>
</tr>
<!--<tr>
<th>
<span t-esc="has_shortage_so_lines(o.id)"/>
</th>
</tr>-->
</thead>
</table>
<t t-if="has_shortage_so_lines(data)==True">
<table>
<thead>
<tr>
<th easyfx="font:height 200, bold on;align: horizontal center,vert center;">Date</th>
<th easyfx="font:height 200, bold on;align: horizontal center,vert center;">SO No</th>
<th easyfx="font:height 200, bold on;align: horizontal center,vert center;">Customer Ref No</th>
</tr>
</thead>
</table>
</t>
</div>
</div>
</template>
<!-- Main template -->
<template id="xls_report_shortage">
<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', 'sale.report_shortage_xls')"/>
</t>
</t>
</template>
</data>
</openerp>
This is my report.py
class ShortageReport(report_sxw.rml_parse):
def __init__(self, cr, uid, name, context):
super(ShortageReport, self).__init__(cr, uid, name, context=context)
self.localcontext.update({
'get_date_from': self.get_date_from,
'get_date_to': self.get_date_to,
'has_shortage_so_lines': self.has_shortage_so_lines,
'get_shortage_lines': self.get_shortage_lines,
})
def has_shortage_so_lines(self, order_id):
_logger.info("sale order id >>> : %r", order_id)
lines_obj = self.get_shortage_so_lines(order_id)
if lines_obj:
return True
return False
class report_shortage_xls(osv.AbstractModel):#(models.AbstractModel):
_name = 'report.stock.report_shortage_xls'
_inherit = 'report.abstract_report'
_template = 'stock.report_shortage_xls'
_wrapped_report_class = ShortageReport
Is there any way to export the xls from odoo. Thank you so much for your helping.
Make sure here
_template = 'stock.report_shortage_xls'
it must be module name with report name, you have created report for sale.order and you have given stock module name, is it correct in your case ?
For more information you should refer our blog on Qweb Report.

Resources