kerolos
kerolos

Reputation: 147

show a field or another in tree view based on condition

How can I show a field or another field in the same column of a tree view based on a condition?

example I want to set a sub-account column when it is a cash account selected t want to select a partner. when it is a bank i want to specify one of its children bank accounts.

I want them to be just under the sub-account column in the tree view of voucher line.

Upvotes: 0

Views: 678

Answers (1)

user3259659
user3259659

Reputation: 77

One way is to create a database view where you can leverage the power of SQL selects, joins and conditional selection.

This will solve your problem and even give you more power and control.

Below is a snippet of a code I've written to get a report of material movements in a warehouse:

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

Hope this helps :)

Upvotes: 1

Related Questions