odoo12 通过python代码控制xml界面,更改字段属性(fields_view_get方法使用)
Posted pywjh
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于odoo12 通过python代码控制xml界面,更改字段属性(fields_view_get方法使用)的主要内容,如果未能解决你的问题,请参考以下文章
odoo12 通过一个字段控制另一个Many2one字段的domain