我有一个字段是M2o,和O2m相反。我试图像这样在O2m类中显示M2o字段,并在树视图中显示所有O2m字段。但是我需要隐藏一个列是基于ir.config_parameter的
from odoo import models, fields, api
class AbcXyz(models.Model):
_name='abc.xyz'
b_ids=fields.One2many('xyz.abc','a_id',string="Xyz")
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(AbcXyz, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
if view_type=='form' and self.b_ids:
for line in self.b_ids:
is_applying_view = eval(self.env['ir.config_parameter'].sudo().get_param('test_module.is_applying_k_qty'))
doc = etree.XML(res['arch'])
if is_applying_view:
for node in doc.xpath("//field[@name='line.k_qty']"):
node.set('invisible', '0')
else:
for node in doc.xpath("//field[@name='line.cartoon_qty']"):
node.set('invisible', '1')
return res
class XyzAbc(models.Model)
_name='xyz.abc'
@api.multi
def get_default_k_qty_visible(self):
return eval(self.env['ir.config_parameter'].sudo().get_param('test_module.is_applying_k_qty'))
a_id=fields.Many2one('abc.xyz',string="ABC")
<!---other fields--->
k_qty=fields.Integer(string="Cartoon Qty", default=0)
is_k_qty_visible = fields.Boolean(string="Is K Qty Visible", compute=get_default_cartoon_qty_visible, store=True)基于is_k_qty_visible,我试图隐藏k_qty列。
<record id="abc_form_view" model="ir.ui.view">
<field name="name">abc.form.view</field>
<field name="model">abc.xyz</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="ABC Process">
<notebook>
<page string="K Qty">
<field name="b_ids" nolabel='1' mode="tree">
<tree>
<field name="k_qty" attrs="{'invisible':[('is_k_qty_visible','!=',True)]}" />
</tree>
</field>
</page>
</notebook>
</form>
</field>
<record>但这对我没用。
发布于 2019-07-03 09:42:48
这不是这个问题的答案。我分享了一些信息。
此代码用于在one2many(树)中隐藏odoo11中的字段
< field name="my_field“attrs={‘column_无形’:('parent.field_name','=',False)}”/>“
这种类型的代码只在条件下才能给出“父”。
我认为这种类型的代码也会在odoo12中工作。
https://stackoverflow.com/questions/56863917
复制相似问题