当'type'为'outgoing'(交付 - 销售订单)时,有没有办法可以在many2one字段(lot_id)中删除'创建和编辑'?
编辑:
修改:
@api.model
def fields_view_get(self, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(stock_transfer_details, self).fields_view_get(view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
#codes here
if view_type == 'form' and is_outgoing == 'outgoing':
doc = etree.XML(res['arch'])
for node in doc.xpath("//field[@name='lot_id']"):
node.set('no_create', "true")
node.set('no_create_edit', "true")
setup_modifiers(node, res['fields']['lot_id'])
res['arch'] = etree.tostring(doc)
return res
stock_transfer_details.xml(原创)
<record id="view_stock_enter_transfer_details" model="ir.ui.view">
<field name="name">Enter transfer details</field>
<field name="model">stock.transfer_details</field>
<field name="arch" type="xml">
<form string="Transfer details" version="7">
<field name="picking_source_location_id" invisible="True"/>
<field name="picking_destination_location_id" invisible="True"/>
<group string="Products To Move">
<div class="oe_grey" groups="stock.group_tracking_lot">
Setting a product and a source package means that the product will be taken
out of the package.
</div>
</group>
<group>
<field name="item_ids"
context="{'default_sourceloc_id':picking_source_location_id,
'default_destinationloc_id':picking_destination_location_id}" nolabel="1">
<tree string="Inventory Details" editable="bottom" >
<field name="package_id" groups="stock.group_tracking_lot"/>
<field name="product_id" required="True" context="{'uom':product_uom_id}" on_change="product_id_change(product_id,product_uom_id,context)"/>
<field name="quantity"/>
<button name="split_quantities" string="Split" type="object" icon="STOCK_PREFERENCES" attrs="{'invisible': [('quantity', '=', 1)]}"/>
<field name="product_uom_id" options="{"no_open": True}" groups="product.group_uom"/>
<field name="sourceloc_id" domain="[('id', 'child_of', parent.picking_source_location_id)]"/>
<field name="destinationloc_id" domain="[('id', 'child_of', parent.picking_destination_location_id)]"/>
<field name="result_package_id" groups="stock.group_tracking_lot" context="{'location_id': destinationloc_id}"/>
<button name="put_in_pack" string="Pack" type="object" icon="terp-product" attrs="{'invisible': [('result_package_id', '!=', False)]}" groups="stock.group_tracking_lot"/>
<field name="lot_id" groups="stock.group_production_lot" domain="[('product_id','=?', product_id)]" context="{'product_id': product_id}"/>
</tree>
</field>
</group>....
仍然无法正常工作。如何在树视图中找到lot_id
字段?
答案 0 :(得分:2)
many2one小部件(默认)
选项:您可以使用此小部件的其他可能选项。
示例:强>
<field name="field_name" options="{'no_quick_create': True, 'no_create_edit' : True}"/>
中引用它
Alessandro Ruffolo建议你采取正确的方式。
答案 1 :(得分:1)
当调用表单时(例如进入操作),传递类型(传入/传出)然后覆盖fields_view_get以修改字段lot_id添加<我将改变模型的上下文em> options 属性为@ user00000341表示,仅当type为'outgoing'时。
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = super(material_paper, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
type = context.get('type', False)
if view_type == 'form' and type == 'outgoing':
doc = etree.XML(res['fields']['item_ids']['views']['tree']['arch'])
update = False
for field in doc.xpath("//field[@name='lot_id']"):
field.attrib['options'] = "{'no_create_edit': True}"
update = True
if update:
res['fields']['item_ids']['views']['tree']['arch'] = etree.tostring(doc)
return res
答案 2 :(得分:0)
尝试这个
<field name="many2one field name" options="{'no_create': True}"/>
答案 3 :(得分:0)
我知道这是一个老问题,但亚历山德罗在回答正确时的答案并没有真正解释这里的问题。
字段视图get是一种方法,它将立即获取树形式所需的几乎所有可能的视图。问题是当您检查arch
返回的fields_view_get
时,您会看到item_ids
是一个简单的字段,并且没有附加树视图。
原因是所有子视图都插入到返回值的fields
属性中的各自字段中。这也是一种递归方法,因此每个子字段可以附加任意数量的子视图。
Allessandro的答案可能无法工作的原因之一是视图是否已经加载到树中的其他位置。虽然看res['fields']['item_ids']['views']['tree']['arch']
应该有效。在更复杂的情况下,视图可能先前已在其他地方加载。在这些情况下,您必须检查所有字段/视图/树子树,以更改与要使用lxml扩展的字段匹配的任何字段。