With this query, I'm getting an error
ERROR: missing FROM-clause entry for table "inv"
LINE 1: update stock_picking set invoice_status = inv.date_invoice
My goal is to set stock_picking posting_date to inv.date_invoice if it meets all conditions, is it possible with SQL?
update stock_picking set posting_date = inv.date_invoice
where id in
(
SELECT DISTINCT sp.id
FROM stock_picking sp
INNER JOIN stock_move sm ON sp.id = sm.picking_id
INNER JOIN sale_order_line sol ON sm.sale_line_id = sol.id
INNER JOIN sale_order so ON sol.order_id = so.id
INNER JOIN sale_order_invoice_rel so_inv_rel on so.id = so_inv_rel.order_id
INNER JOIN account_invoice inv on so_inv_rel.invoice_id = inv.id
WHERE
sp.posting_date != inv.date_invoice
and sm.posting_date != inv.date_invoice
and sp.state = 'done'
and inv.state in ('open', 'paid')
)