コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
8092 ビュー

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.

著作者 最善の回答

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

関連投稿 返信 ビュー 活動
4
10月 18
4724
3
5月 23
3953
1
5月 23
2361
2
4月 23
21124
1
9月 22
7233