【发布时间】:2018-03-08 10:31:30
【问题描述】:
您好,我正在尝试隐藏/显示操作(树视图)过滤器/分组依据字段选择部分中的一些字段。我找到了使用 fields_get 函数执行此操作的解决方案,但是我遇到的问题是,当您在菜单项之间切换时,字段不会更新。我的解决方案如下。
@api.model
def fields_get(self, allfields=None, attributes=None):
"""Extend to hide fields from custom search."""
# u'route_view': u'route_accounting'
# Fieldai kuriuos reikia rodyti
route_accounting_filter = ['last_adt', 'first_alt', 'carrier', 'cmr_receive_date',
'cmr_reg_no_1', 'cmr_req',
'cmr_send_date', 'send_seperate_documents',
'freight_customer', 'last_invoice_send_date',
'load_country_id', 'load_full_adr', 'last_relevant_invoice',
'payer', 'customer', 'other_po',
'purchase_order_route_loc', 'name', 'freight_so',
'trailer_id', 'truck_id', 'unload_country_id',
'unload_full_adr', 'billing_data', 'invoice_billing_no',
'cmr', 'cmr_copy_receive_date', 'debt',
'declaration', 'last_invoice_send_date', 'transportation_done',
'delivery_note', 'document_packet', 'documents_delayed_to_receive',
'transportation_done_date', 'last_invoice_send_date', 'cmr_reg_userr',
'cmr_reg_date', 'product_description'
]
route_accounting_group = ['name', 'last_adt', 'first_alt', 'carrier', 'cmr_reg_date'
'cmr_reg_userr', 'cmr_req', 'freight_customer', 'payer', 'load_country_id',
'trailer_id', 'truck_id', 'unload_country_id', 'product_route_id'
]
other_route_group = ['other_po_carrier', 'other_so_partner', 'other_po_description',
'other_po_truck', 'other_po_trailer', 'ferry_product', 'other_so_partner',
'other_po_carrier', 'other_po_description', 'other_po_truck', 'other_po_trailer',
'other_po_carrier_loading_time', 'other_po_carrier_unloading_time',
'last_relevant_bill_number'
]
other_route_filter = ['name', 'other_so', 'other_po',
'vendor_reference_other', 'transportation_done', 'ferry_product', 'name'
]
res = super(RouteData, self).fields_get(
allfields=allfields,
attributes=attributes
)
if 'route_view' in self.env.context and self.env.context['route_view'] == 'route_accounting':
print "ROUTE (ACCOUNTING VIEW))))"
for field in res:
if field not in route_accounting_filter:
res[field]['selectable'] = False
for field in res:
if field not in route_accounting_group:
res[field]['sortable'] = False
elif 'route_view' in self.env.context and self.env.context['route_view'] == 'route_other':
print "ROUTE (OTHER VIEW))))"
for field in res:
if field not in other_route_filter:
res[field]['selectable'] = False
for field in res:
if field not in other_route_group:
res[field]['sortable'] = False
return res
我的视图如图所示。基本上每个菜单项都有自己的操作,但来自同一个表,我相信出于这个原因,即使我的解决方案检查上下文有效(它打印出他在不同的视图中)他不会更新 Group By 中显示的字段/Filter (即使代码有效)。有没有我忘记的东西,或者可能有不同的解决方案可以轻松完成此任务? (如果不用JS就好了)
【问题讨论】:
-
一个好问题
标签: python odoo odoo-10 odoo-view