【问题标题】:show a field or another in tree view based on condition根据条件在树视图中显示一个字段或另一个字段
【发布时间】:2014-11-12 12:13:18
【问题描述】:

如何根据条件在树视图的同一列中显示一个字段或另一个字段?

示例 我要设置子账户栏目 当它是一个现金帐户选择t要选择一个合作伙伴。 当它是一家银行时,我想指定它的一个子银行账户。

我希望它们位于凭证行树形视图中的子帐户列下方。

【问题讨论】:

  • 你能举个例子吗?
  • 感谢您的关心。我刚刚更新了问题。

标签: treeview openerp openerp-7


【解决方案1】:

一种方法是创建一个数据库视图,您可以在其中利用 SQL 选择、连接和条件选择的强大功能。

这将解决你的问题,甚至给你更多的权力和控制。

下面是我为获取仓库中物料移动报告而编写的代码的 sn-p:

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
                 )
                ''')

希望这会有所帮助:)

【讨论】:

  • 我正在查看帐户凭证中的列表视图,其中显示帐户凭证行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-07-20
  • 1970-01-01
  • 2013-05-08
  • 2021-02-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多