0% found this document useful (0 votes)
5 views

Query

Uploaded by

natthakit.2203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Query

Uploaded by

natthakit.2203
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

select

purchase.department_id2,
(select name from res_company where id = 1) as company,
(select phone from res_company where id = 1) as phone,
purchase.phone as dep_phone,
purchase.text_at,
purchase.po_number,
purchase.date_approve,
purchase.title,
-- category.name,
purchase.sent_to,
(select count(id) from purchase_order_line where order_id = purchase.id) as
po_line,
purchase.amount_total,
(select sum(price_total) from purchase_order_line where order_id = purchase.id) as
po_line_amount_total,
budget_money.name ->> 'th_TH' as budget_money_name,
budget.budget_year,
purchase_method.name as purchase_method_name,
partner.name as partner_name,
product_tem.default_code as product_code,
product_tem.name ->> 'th_TH' as product_name,
product_uom.name ->> 'th_TH' as product_uom_name,
purchase_line.product_qty,
purchase_line.price_unit,
purchase_line.price_total,
(
select distinct price_unit
from purchase_order_line
where true
and state in ('purchase','done')
and product_id = product.id
and partner_id = partner.id
and date_planned < purchase_line.date_planned
) as last_purchase_price,
(
select distinct date_planned
from purchase_order_line
where true
and state in ('purchase','done')
and product_id = product.id
and partner_id = partner.id
and date_planned < purchase_line.date_planned
) as last_purchase_date,
purchase.amount_untaxed,
purchase.amount_tax,
purchase.date_exp,

(select name from


get_user_info('officer',coalesce(purchase.officer_id,0),coalesce(purchase.officer_j
obtitle,0))) as officer_name,
(select position from
get_user_info('officer',coalesce(purchase.officer_id,0),coalesce(purchase.officer_j
obtitle,0))) as officer_position,

(select name from


get_user_info('officer',coalesce(purchase.chief_officer_id,0),coalesce(purchase.chi
ef_jobtitle,0))) as officer_name2,
(select position from
get_user_info('officer',coalesce(purchase.chief_officer_id,0),coalesce(purchase.chi
ef_jobtitle,0))) as officer_position2,

(select name from


get_user_info('officer',coalesce(purchase.chief_approval_officer_id,0),coalesce(pur
chase.approval_jobtitle,0))) as officer_name3,
(select position from
get_user_info('officer',coalesce(purchase.chief_approval_officer_id,0),coalesce(pur
chase.approval_jobtitle,0))) as officer_position3,

(select name from


get_user_info('user',coalesce(purchase.user_committee,0),coalesce(purchase.user_com
mittee_position,0))) as user_name,
(select position from
get_user_info('user',coalesce(purchase.user_committee,0),coalesce(purchase.user_com
mittee_position,0))) as user_position,

(select name from


get_user_info('user',coalesce(purchase.user_committee2,0),coalesce(purchase.user_co
mmittee_position2,0))) as user_name2,
(select position from
get_user_info('user',coalesce(purchase.user_committee2,0),coalesce(purchase.user_co
mmittee_position2,0))) as user_position2,

(select name from


get_user_info('user',coalesce(purchase.user_committee3,0),coalesce(purchase.user_co
mmittee_position3,0))) as user_name3,
(select position from
get_user_info('user',coalesce(purchase.user_committee3,0),coalesce(purchase.user_co
mmittee_position3,0))) as user_position3

from purchase_order purchase


left join purchase_order_line purchase_line on purchase_line.order_id = purchase.id
left join product_product product on product.id = purchase_line.product_id
left join product_template product_tem on product_tem.id = product.product_tmpl_id
left join product_category category on category.id = purchase.category_id
left join ss_purchase_request_line purchase_re_line on purchase_re_line.id =
purchase_line.pr_line_id
left join ss_purchase_request purchase_re on purchase_re.id =
purchase_re_line.pr_id
left join ss_budget_line budget_line on budget_line.id =
purchase_re_line.budget_line_id
left join ss_budget budget on budget.id = budget_line.budget_id
left join ss_budget_money_type budget_money on budget_money.id =
budget.money_type_id
left join ss_purchase_method purchase_method on purchase_method.id =
purchase.purchase_method_id
left join res_partner partner on partner.id = purchase.partner_id
left join uom_uom product_uom on product_uom.id = purchase_line.product_uom

where true
and purchase.id = 5

You might also like