zoukankan      html  css  js  c++  java
  • odoo12 通过python代码控制xml界面,更改字段属性(fields_view_get方法使用)

    odoo12 通过python代码控制xml界面,更改字段属性(fields_view_get方法使用)

       @api.multi
        def get_required_module_list(self) -> list:
            """
            此方法用来设置,哪些模型可以将签字功能做成必输
            可继承修改,增加更多的模型签字必输
            """
            return [self._module]
    
        @api.model
        def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
            """控制对应模型审批时签字字段的必输"""
            result = super(FrReimbursedApprovalWizard, self).fields_view_get(view_id, view_type, toolbar, submenu)
            required_module_list = self.get_required_module_list()
            if self._module in required_module_list:
                doc = etree.XML(result['arch'])
                for node in doc.xpath(r"//field[@name='fr_signature']"):
                    node.set('required', '1')
                    setup_modifiers(node, result['fields']['fr_signature'])
                result['arch'] = etree.tostring(doc, encoding='unicode')
            return result
    from lxml import etree
    
    from odoo.osv.orm import setup_modifiers
    
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
            #override of fields_view_get in order to replace the name field to product template
            if context is None:
                context={}
            res = super(product_product, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
            #check the current user in group_product_variant
            group_id = self.pool['ir.model.data'].get_object_reference(cr, uid, 'product', 'group_product_variant')[1]
            obj = self.pool.get('res.groups').browse(cr, uid, group_id, context=context)
            doc = etree.XML(res['arch'])
            if view_type == 'form':
                if obj and uid in [x.id for x in obj.users]:
                    for node in doc.xpath("//field[@name='name']"):
                        node.set('invisible', '1')
                        node.set('required', '0')
                        setup_modifiers(node, res['fields']['name'])     #这行必须要有
                    for node in doc.xpath("//label[@string='Product Name']"):
                        node.set('string','Product Template')
                else:
                    for node in doc.xpath("//field[@name='product_tmpl_id']"):
                        node.set('required','0')
                        setup_modifiers(node, res['fields']['product_tmpl_id'])     #这行必须要有
                    for node in doc.xpath("//field[@name='name']"):
                        node.set('invisible', '0')
                        setup_modifiers(node, res['fields']['name'])     #这行必须要有
                    for node in doc.xpath("//label[@string='Product Template']"):
                        node.set('string','Product Name')
            res['arch'] = etree.tostring(doc)
            return res
  • 相关阅读:
    光猫改桥接,默认的超级管理员密码。
    Vmware+爱快软路由单机校园网多拨实现带宽叠加[测试用](非普遍性)
    魔百和破解教程
    用SSH工具XShell连接谷歌云 root用户或普通用户
    MySQL优化技巧【持续更新】
    Navicat常用快捷键
    IDEA实用插件Lombok
    Redis数据类型及命令
    Java代码优化总结(持续更新)
    Spring---AOP注解开发&jdbc模板&Spring事务管理
  • 原文地址:https://www.cnblogs.com/pywjh/p/13474644.html
Copyright © 2011-2022 走看看