• 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
  • 相关阅读:
    go 从入门到精通(二)基本数据类型和操作符
    python爬虫番外篇(一)进程,线程的初步了解
    Go从入门到精通(一)go语言初识
    python爬虫从入门到放弃(九)之 实例爬取上海高级人民法院网开庭公告数据
    python爬虫从入门到放弃(八)之 Selenium库的使用
    python爬虫从入门到放弃(七)之 PyQuery库的使用
    python爬虫从入门到放弃(六)之 BeautifulSoup库的使用
    python爬虫从入门到放弃(五)之 正则的基本使用
    python爬虫从入门到放弃(三)之 Urllib库的基本使用
    openstack网络基本概念(转)
  • 原文地址:https://www.cnblogs.com/pywjh/p/13474644.html
Copyright © 2020-2023  润新知