当前位置:   article > 正文

odoo 增加自定义配置项 二 group_odoo 自定义配置参数

odoo 自定义配置参数

这种配置项适合的场景在于个人化的场景,用户A可能会选择这一项,用户B可能不会选择这一项。

继承 res.config.settings 模型,增加配置项字段,关联到一个 group 上

  1. # -*- coding: utf-8 -*-#
  2. # -------------------------------------------------------------------------------
  3. # Name: roke_res_config_settings
  4. # Author: CAO.T.F
  5. # Date: 2019/4/20
  6. # Description: 增加 是否允许负库存出库 配置项
  7. # -------------------------------------------------------------------------------
  8. from odoo import api, fields, models
  9. class ResConfigSettings(models.TransientModel):
  10. _inherit = 'res.config.settings'
  11. group_stock_allow_negative_inventory = fields.Boolean("Allow Negative Inventory",
  12. implied_group='roke_stock.group_allow_negative_inventory')

创建 group

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <odoo>
  3. <data noupdate="0">
  4. <!-- 是否允许出库 -->
  5. <record id="group_allow_negative_inventory" model="res.groups">
  6. <field name="name">是否允许出库</field>
  7. <field name="category_id" ref="base.module_category_hidden"/>
  8. </record>
  9. </data>
  10. </odoo>

创建或继承 res.config.settings 视图

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <odoo>
  3. <data>
  4. <record id="res_config_settings_view_form_inherit_roke_stock_1" model="ir.ui.view">
  5. <field name="name">res.config.settings.view.form.inherit.roke.stock</field>
  6. <field name="model">res.config.settings</field>
  7. <field name="priority" eval="30"/>
  8. <field name="inherit_id" ref="base.res_config_settings_view_form"/>
  9. <field name="arch" type="xml">
  10. <xpath expr="//div[@data-key='stock'][@data-string='Inventory']/div[1]" position="after">
  11. <div class="row mt16 o_settings_container">
  12. <div class="col-12 col-lg-6 o_setting_box"
  13. title="Allow Negative Inventory">
  14. <div class="o_setting_left_pane">
  15. <field name="group_stock_allow_negative_inventory"/>
  16. </div>
  17. <div class="o_setting_right_pane">
  18. <label for="group_stock_allow_negative_inventory"/>
  19. <div class="text-muted">
  20. Allow Negative Inventory
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </xpath>
  26. </field>
  27. </record>
  28. </data>
  29. </odoo>

使用此配置项时,判断组权限即可,举例如下

  1. @api.onchange('qty_done')
  2. def _onchange_qty_done_1(self):
  3. group_allow_negative_inventory_enabled = self.user_has_groups('roke_stock.group_allow_negative_inventory')
  4. pass

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/230845
推荐阅读
相关标签
  

闽ICP备14008679号