admin管理员组

文章数量:829169

python 筛选 加字段

你好,我正在尝试隐藏/显示一些字段在操作(树状视图)筛选/分组按字段选择部分。我找到了用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

我的观点如图所示。基本上每个菜单项都有自己的操作,但都来自同一个表,因此我相信即使我的解决方案检查上下文有效(它打印出他在不同的视图中),他也不会更新groupby/Filter中显示的字段(即使代码也能工作)。有没有什么东西我忘了,或者可能有不同的解决方法来轻松完成?(如果不用JS就好了)

本文标签: python 筛选 加字段