赞
踩
这种配置项适合的场景在于个人化的场景,用户A可能会选择这一项,用户B可能不会选择这一项。
继承 res.config.settings 模型,增加配置项字段,关联到一个 group 上
- # -*- coding: utf-8 -*-#
-
- # -------------------------------------------------------------------------------
- # Name: roke_res_config_settings
- # Author: CAO.T.F
- # Date: 2019/4/20
- # Description: 增加 是否允许负库存出库 配置项
-
- # -------------------------------------------------------------------------------
-
- from odoo import api, fields, models
-
-
- class ResConfigSettings(models.TransientModel):
- _inherit = 'res.config.settings'
-
- group_stock_allow_negative_inventory = fields.Boolean("Allow Negative Inventory",
- implied_group='roke_stock.group_allow_negative_inventory')
创建 group
- <?xml version="1.0" encoding="utf-8"?>
- <odoo>
- <data noupdate="0">
-
- <!-- 是否允许出库 -->
- <record id="group_allow_negative_inventory" model="res.groups">
- <field name="name">是否允许出库</field>
- <field name="category_id" ref="base.module_category_hidden"/>
- </record>
- </data>
- </odoo>
创建或继承 res.config.settings 视图
- <?xml version="1.0" encoding="utf-8"?>
- <odoo>
- <data>
- <record id="res_config_settings_view_form_inherit_roke_stock_1" model="ir.ui.view">
- <field name="name">res.config.settings.view.form.inherit.roke.stock</field>
- <field name="model">res.config.settings</field>
- <field name="priority" eval="30"/>
- <field name="inherit_id" ref="base.res_config_settings_view_form"/>
- <field name="arch" type="xml">
- <xpath expr="//div[@data-key='stock'][@data-string='Inventory']/div[1]" position="after">
- <div class="row mt16 o_settings_container">
- <div class="col-12 col-lg-6 o_setting_box"
- title="Allow Negative Inventory">
- <div class="o_setting_left_pane">
- <field name="group_stock_allow_negative_inventory"/>
- </div>
- <div class="o_setting_right_pane">
- <label for="group_stock_allow_negative_inventory"/>
- <div class="text-muted">
- Allow Negative Inventory
- </div>
- </div>
- </div>
- </div>
- </xpath>
- </field>
- </record>
- </data>
- </odoo>
使用此配置项时,判断组权限即可,举例如下
- @api.onchange('qty_done')
- def _onchange_qty_done_1(self):
- group_allow_negative_inventory_enabled = self.user_has_groups('roke_stock.group_allow_negative_inventory')
- pass
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。