Query
Query
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,
where true
and purchase.id = 5