This question has been flagged
2366 Views

Hi

I start with python programming and odoo 11 Here I have two model "res.config.settings" and "account.tax" I would like that when I check "Ecotax" which is a Boolean field which is in the model "res.config.settings" a list of tax appears on the model "account.tax". Do you have an idea of the method to follow? How can I control the display of record set from another model? is it possible ? Here is my python code:

from odoo import models, fields, api
import logging
class EcotaxeConfig(models.TransientModel):
_inherit = "res.config.settings"

is_ecotaxe = fields.Boolean('Ecotaxe', help="Warning : To include Ecotaxe ",default=False)


@api.model
def get_values(self):
    res = super(EcotaxeConfig, self).get_values()
    get_param = self.env['ir.config_parameter'].sudo().get_param
    res.update(
        is_ecotaxe=get_param('l10n_fr_ecotaxe.is_ecotaxe'),                                                                         
    )
    return res

def set_values(self):
    super(EcotaxeConfig, self).set_values()
    set_param = self.env['ir.config_parameter'].sudo().set_param
    set_param('l10n_fr_ecotaxe.is_ecotaxe', self.is_ecotaxe)

@api.onchange('is_ecotaxe')
def _onchange_is_ecotaxe(self):
    tax = self.env['account.tax'].search([
        ('company_id', '=', self.env.user.company_id.id)  ] )
    if self.is_ecotaxe == True:
       for eco in tax :
            eco.visible_eco=True
       else :
        for eco in tax :
        eco.visible_eco=False

Here is my xml code:

<?xml version="1.0" encoding="UTF-8"?> <odoo> <record model="ir.ui.view" id="account_tax_eco_form"> <field name="name">account_taxe_eco_form</field> <field name="model">res.config.settings</field> <field name="inherit_id" ref="account.res_config_settings_view_form"/> <field name="arch" type="xml"> <div id="eu_service" position="after"> <div class="col-xs-12 col-md-6 o_setting_box" > <div class="o_setting_left_pane"> <field name="is_ecotaxe"/> </div> <div class="o_setting_right_pane"> <label for="is_ecotaxe"/> <div class="text-muted"> if you want to add ecotaxes with other taxes </div> </div> </div> </div> </field>

Here is my record set code:

<?xml version="1.0" encoding="utf-8"?> <odoo> <record model="account.tax" id="taxe0" > <field name="name">Eco/Cat02/42070</field> <field name="type_tax_use" >sale</field> <field name="amount_type">fixed</field> <field name="amount">10</field> <field name="price_include">True</field> <field name="include_base_amount">True</field> <field name="visible">False</field> </record> <record model="account.tax" id="taxe1" > <field name="name" >Eco/Cat02/42070</field> <field name="type_tax_use" >purchase</field> <field name="amount_type">fixed</field> <field name="amount">10</field> <field name="price_include">True</field> <field name="include_base_amount">True</field> <field name="visible">False</field> </record> <record model="account.tax" id="taxe2" > <field name="name">Eco/Cat02/42080</field> <field name="type_tax_use" >sale</field> <field name="amount_type">fixed</field> <field name="amount">6.67</field> <field name="price_include">True</field> <field name="include_base_amount">True</field> <field name="visible">False</field> </record>

Thanks for your help
Avatar
Discard