我从python编程和odoo 11开始 在这里,我有两个模型“ res.config.settings”和“ account.tax”,我想当我检查“ Ecotax”时,这是模型“ res.config.settings”中的一个布尔字段,出现税收列表在模型“ account.tax”上。 您对遵循的方法有想法吗? 如何控制其他模型的记录集的显示?可能吗 ? 这是我的python代码:
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
这是我的xml代码:
<?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>
这是我的记录集代码:
<?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>
感谢您的帮助