我正在继承res_config_settings_views,我希望在每次重新加载页面时都按选中的方式加载分析组下的复选框,即我想将Analytics(分析)会计复选框的值默认设置为true。
我尝试通过在py文件中将其定义为group_analytic_accounting = fields.Boolean(string='', default=True)
来通过继承模型将其设置为true,并且我还尝试将其从xml文件中设置为默认值<field name="group_analytic_accounting">{'default_group_analytic_accounting': 'True'}</field>
两个都被证明是失败的尝试。非常感谢您的任何帮助或指导。
PS:Odoo版本为12
谢谢
编辑: 下面是xml代码
P.S:我继承了res_config_settings_views(Odoo社区->插件->帐户->视图)。我只想修改解析div并加载默认选中的复选框
<xpath expr="//div[@id='analytic']" position="replace">
<div class="row mt16 o_settings_container" id="analytic">
<div class="col-12 col-lg-6 o_setting_box" title="Allows you to use the analytic accounting." groups="account.group_account_user">
<div class="o_setting_left_pane">
<field name="group_analytic_accounting"/>
</div>
<div class="o_setting_right_pane">
<label for="group_analytic_accounting"/>
<div class="text-muted">
Track costs & revenues by project, department, etc.
</div>
<div class="content-group" attrs="{'invisible': [('group_analytic_accounting', '=', False)]}">
<div class="mt16" id="analytic_account_link">
<button name="%(analytic.action_analytic_account_form)d" icon="fa-arrow-right"
type="action" string="Analytic Accounts" class="btn-link"/>
</div>
<div id="analytic_account_groups_link">
<button name="%(analytic.account_analytic_group_action)d" icon="fa-arrow-right"
type="action" string="Analytic Account Groups" class="btn-link"/>
</div>
</div>
</div>
</div>
</div>
下面是python代码
class Account(models.TransientModel):
_inherit = 'res.config.settings'
group_analytic_accounting = fields.Boolean(string='Test Analytic Accounting', implied_group='analytic.group_analytic_accounting', default=True, required=True, change_default=True)
答案 0 :(得分:0)
save
此代码应该起作用。 我们可以看到整个班级吗?
答案 1 :(得分:0)
如果var = fields.Boolean(string='', default=True)
不起作用,请尝试放置计算字段或从该字段调用函数。
def function_name(self):
self.var = True