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 use a variable from own module inside a report ?

By
Theudric Enicar
on 6/4/15, 7:59 AM 691 views

As beginner with Odoo, I made the following module:

from openerp import models, fields, api


class myconfig(models.TransientModel):
        _name = 'myModule.myconfig'
        _inherit = 'res.config.settings'

         default_isEnabled = fields.Boolean(
                'Enable my module',
                 default=True,
                default_model='myModule.myconfig',
        )

Now, inside my report, I would like to check whether my module is enabled and display one image.
Exactly like the external_layout does with " company.logo ", but with my variable " default_isEnabled "

<img t-if="company.logo" ...

<img t-if="default_isEnabled" .... => doesn't work
<img t-if="'myModule.myconfig.default_isEnabled" .... => doesn't work

I probably missed some steps, but I don't know where to find the information.
I am spending time and time... Tried % if, and lot of other stuff, without success...
Many thanks in advance for your help.

You're not specifying the object that you'd like to use. By default you should be able to access it with o.FieldName, so o.default_isEnabled should work.

Yenthe
on 6/4/15, 5:00 PM
0
Theudric Enicar
On 6/5/15, 9:16 AM

Waht do you mean with "object" ?

Already tried o.default_isEnabled and it really doesn't work.

I read this : http://www.mindissoftware.com/2014/10/17/How-to-save-and-load-module-configuration-in-odoo/

Is it because I use default_isEnabled to name my variable ? Not stored in the database as standard field ?

See below the full code for a better understanding (I made some minor changes):

__openerp__.py

{
        'name': 'My Module',
        'description': 'Test my module ',
        'author': 'Theudric',
        'depends' : ['base', 'report'],
        'application': True,
        'data': ['myModule_view.xml', 'header.xml'],
}

__init__.py

from . import myModule

myModule.py

# -*- coding: utf-8 -*-
from openerp import models, fields, api
        class myconfig(models.TransientModel):
                _name = 'mymodule.myconfig'
                _inherit = 'res.config.settings'
                default_isEnabled = fields.Boolean(
                        'Enable my module',
                        default=True,
                        default_model='mymodule.myconfig',
                )

myModule_view.xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
        <data>
                <record id="view_custom_config_settings" model="ir.ui.view">
                        <field name="name">custom settings</field>
                        <field name="model">mymodule.myconfig</field>
                        <field name="arch" type="xml">
                                <form string="Configure Accounting" version="7.0" class="oe_form_configuration">
                                        <header>
                                                <button string="Apply" type="object" name="execute" class="oe_highlight"/>
                                                or
                                                <button string="Cancel" type="object" name="cancel" class="oe_link"/>
                                        </header>
                                        <field name="default_isEnabled"/>
                                </form>
                        </field>
                 </record>
                 <record id="action_custom_config" model="ir.actions.act_window">
                        <field name="name">Custom Settings</field>
                         <field name="type">ir.actions.act_window</field>
                         <field name="res_model">mymodule.myconfig</field>
                         <field name="view_mode">form</field>
                         <field name="target">inline</field>
                 </record>
                 <menuitem id="menu_custom_config" name="Custom Settings" parent="base.menu_config"
                 sequence="16" action="action_custom_config"/>
         </data>
</openerp>

header.xml

<?xml version="1.0"?>
<openerp>
        <data>
                 <template id="mymodule_header" inherit_id="report.external_layout_header" >
                         <xpath expr="//div[@class='header']" position="inside">
                                 <div t-if="company.logo">Hello it is working with company.logo</div>

                                 <!--div t-if="res.config.settings.default_isEnabled">1 Not working !!!</div-->
                                 <!--div t-if="config.settings.default_isEnabled">2 Not working !!!</div-->
                                 <!--div t-if="settings.default_isEnabled">3 Not working !!!</div-->
                                 <div t-if="default_isEnabled">4 Not working !!!</div>
                                 <!--div t-if="o.res.config.settings.default_isEnabled">5 Not working !!!</div-->
                                 <!--div t-if="o.config.settings.default_isEnabled">6 Not working !!!</div-->
                                 <!--div t-if="o.settings.default_isEnabled">7 Not working !!!</div-->
                                 <!--div t-if="o.default_isEnabled">8 Not working !!!</div-->
                                 <!--div t-if="mymodule.myconfig.default_isEnabled">9 Not working !!!</div-->
                                 <!--div t-if="myconfig.default_isEnabled">10 Not working !!!</div-->
                         </xpath>
                 </template>
         </data>
</openerp>

And now, when I print one invoice, I have no access to my variable default_isEnabled

The goal is to display one image in the invoice header if my variable is enabled. But for now let's write some text instead an image.

All commented <div> just above generated errors. Text "4 Not working !!!" is never displayed : default_isEnabled=True or False

Hope this is more clear now.


It looks using a variable starting with *default_* doesn't work inside xml. But probably working inside .py SOLUTION: I did inherit from *company* and it works

Theudric Enicar
on 6/18/15, 3:51 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: 6/4/15, 7:59 AM
Seen: 691 times
Last updated: 6/5/15, 11:54 AM