如何根据条件在树视图的同一列中显示字段或其他字段?
示例 我想设置一个子帐户列 当选择现金账户时,要选择合作伙伴。 当它是一家银行时,我想指定一个子银行账户。
我希望它们位于凭证行树视图中的子帐户列下。
答案 0 :(得分:1)
一种方法是创建一个数据库视图,您可以利用SQL选择,连接和条件选择的强大功能。
这将解决您的问题,甚至可以为您提供更多的动力和控制力。
下面是我编写的代码片段,用于获取仓库中物料移动的报告:
class warehouse_report_material_movement(osv.osv):
_name = 'warehouse.report.material.movement'
def init(self,cr):
tools.sql.drop_view_if_exists(cr,'warehouse_report_material_movement')
cr.execute('''
CREATE OR REPLACE VIEW warehouse_report_material_movement as(
select row_number() OVER () AS id, mat.name as material_name,
case
when (o.order_type ='3' and o.destination_warehouse_id::int =w.id) then material_qty*-1
else
material_qty
end as material_qty,
case
when o.order_type ='0' then 'Request'
when o.order_type ='1' then 'Addition'
when o.order_type ='2' then 'Issue'
when (o.order_type ='3' and o.warehouse_id::int =w.id) then '(+)Internal Move'
when (o.order_type ='3' and o.destination_warehouse_id::int =w.id) then '(-)Internal Move'
when o.order_type ='4' then 'Return'
end as order_type,
w.name as warehouse_name,
o.date::date as order_date,
o.create_date::date as record_date,
r.login as user_name
from warehouse_order_line ol
inner join moe_base_material mat on ol.material_id=mat.id
inner join moe_warehouse_order o on ol.order_id=o.id
inner join moe_warehouse_warehouse w on (o.warehouse_id=w.id or o.destination_warehouse_id=w.id)
left join res_users r on o.create_uid=r.id
)
''')

希望这会有所帮助:)