This question has been flagged
3069 Views

I'm pulling data from the dB to determine the cogs for the month of August.  So far I pulled all SO's that resulted in invoices but the cost for each invoice comes up null presumably because the cost changes constantly.


How should I handle this?

Avatar
Discard

What query are you using?

Author

Thanks. Well it's kinda long but here it goes: SELECT so."name", f."number" Factura, fl.origin, fl."name" Producto, fl.price_unit Precio_Unitario, (sl.margin * fl.quantity) margen, (fl.price_subtotal - (sl.margin * fl.quantity)) costo, fl.quantity Cantidad, fl.price_subtotal SubTotal, sl.margin FROM res_partner so RIGHT JOIN account_invoice f ON so."id" = f.partner_id RIGHT JOIN account_invoice_line fl ON f."id" = fl.invoice_id INNER JOIN sale_order_line_invoice_rel vr ON vr.order_line_id = fl."id" INNER JOIN sale_order_line sl ON sl."id" = vr.order_line_id INNER JOIN sale_order s ON sl.order_id = s."id" LEFT JOIN stock_picking sp ON sp.origin = s."name" LEFT JOIN stock_move mo ON sp."id" = mo.picking_id WHERE f."type" = 'out_invoice' AND ( f.date_invoice BETWEEN '20150801' AND '20150830' ) GROUP BY so."name", f."number", fl.origin, fl."name", fl.price_unit, sl.price_unit, fl.quantity, fl.price_subtotal, sl.margin ORDER BY f."number"