schema_version = "1.4" artifacts = [{ source = "/miroir/evidence", service = "odoo" }] [task] name = "reactive-labs/billing-queue-handback" version = "1.3.0" description = "Take back a December billing queue at year end: invoice the delivered orders from the orders at their ship dates, clear the drafts nobody will post, and reverse a posted invoice that bills a delivery a second time." [metadata] difficulty = "hard" category = "business-apps" world = "world-2" workflow = "customer invoicing from delivered sales orders" entity = "world-2: specialty food and beverage importer-distributor (EUR and GBP suppliers, US customers)" deliverable = "changes in Odoo only" [agent] timeout_sec = 1800.0 [environment] docker_image = "ghcr.io/raphaeldkhn/miroir-main:0.0" cpus = 2 memory_mb = 4096 storage_mb = 10240 [verifier] timeout_sec = 120.0 [verifier.environment] docker_image = "ghcr.io/raphaeldkhn/miroir:0.0.2" workdir = "/tests" [verifier.env] MIROIR_SPEC = ''' checks: # the hard part (0.55): two deliveries were billed twice by someone else. Rosa keyed Hoboken's PO 2103 by hand and # posted and sent it (974.00, no order link); Nadia later invoiced the same delivery from S00449. The checklist keeps # the order's invoice and reverses the other by credit note (a posted invoice is never deleted). The credit note may # come from the reversal wizard or be keyed by hand for Hoboken and matched to it. - name: manual_duplicate_reversed weight: 0.3 sql: | SELECT (SELECT count(*) FROM after."account_move" WHERE _op = 'update' AND move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL AND state = 'posted' AND abs(amount_total - 974.00) < 0.005 AND payment_state IN ('reversed', 'paid', 'in_payment')) = 1 AND (SELECT count(*) FROM after."account_move" WHERE _op = 'insert' AND move_type = 'out_refund' AND state = 'posted' AND abs(amount_total - 974.00) < 0.005 AND date BETWEEN '2026-12-10' AND '2026-12-31' AND (reversed_entry_id IN (SELECT id FROM after."account_move" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL) OR commercial_partner_id = (SELECT commercial_partner_id FROM after."account_move" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL))) = 1 # Rosa's five hand-keyed "one invoice per store" Greenmarket drafts duplicate the order invoices for GMG-PO-52097 # and GMG-PO-52120 that Nadia posted on 12/16: deleted (the checklist) or cancelled, never posted - name: store_drafts_deleted weight: 0.25 sql: | SELECT ((SELECT count(*) FROM before."account_move" WHERE _op = 'delete' AND move_type = 'out_invoice' AND state = 'draft' AND (ref LIKE 'GMG-PO-52097 store %' OR ref LIKE 'GMG-PO-52120 store %')) + (SELECT count(*) FROM after."account_move" WHERE _op = 'update' AND move_type = 'out_invoice' AND state = 'cancel' AND (ref LIKE 'GMG-PO-52097 store %' OR ref LIKE 'GMG-PO-52120 store %'))) / 5.0 # Larchmont refused S00452 in full (returned WH/IN/00112): Rosa's draft from the order goes (deleted or cancelled) - name: refused_order_draft_deleted weight: 0.05 sql: | SELECT (SELECT count(*) FROM before."account_move" WHERE _op = 'delete' AND move_type = 'out_invoice' AND state = 'draft' AND invoice_origin = 'S00452') + (SELECT count(*) FROM after."account_move" WHERE _op = 'update' AND move_type = 'out_invoice' AND state = 'cancel' AND invoice_origin = 'S00452') # Lenox S00482: Grace held the invoice on 12/22 and released it on 12/28 at the order's price - name: lenox_released_and_invoiced weight: 0.05 sql: | SELECT count(*) = 1 FROM after."account_move" WHERE _op = 'insert' AND move_type = 'out_invoice' AND state = 'posted' AND invoice_origin = 'S00482' AND abs(amount_total - 1502.90) < 0.005 AND invoice_date = '2026-12-22' # the routine delivered-not-invoiced orders, one invoice each from the order (S00484: 12 cases as delivered, or 10 # if the 2 cases noted short on the signed receipt are left off) - name: routine_orders_invoiced weight: 0.15 sql: | WITH e(so, amt, alt, d) AS (VALUES ('S00404', 133.40, NULL, '2026-12-21'), ('S00406', 945.00, NULL, '2026-12-21'), ('S00422', 70.00, NULL, '2026-12-22'), ('S00435', 133.00, NULL, '2026-12-21'), ('S00480', 706.56, NULL, '2026-12-21'), ('S00481', 901.50, NULL, '2026-12-22'), ('S00484', 452.64, 377.20, '2026-12-23'), ('S00485', 239.00, NULL, '2026-12-24'), ('S00486', 383.00, NULL, '2026-12-24'), ('S00487', 547.50, NULL, '2026-12-24'), ('S00488', 1215.00, NULL, '2026-12-25'), ('S00490', 4569.90, NULL, '2026-12-30'), ('S00493', 1020.30, NULL, '2026-12-30')) SELECT count(*) / 13.0 FROM e WHERE (SELECT count(*) FROM after."account_move" m WHERE m._op = 'insert' AND m.move_type = 'out_invoice' AND m.state = 'posted' AND m.invoice_origin = e.so AND (abs(m.amount_total - e.amt) < 0.005 OR abs(m.amount_total - coalesce(e.alt, -1)) < 0.005)) = 1 # the checklist: the invoice date is the date the goods shipped (not the day it is keyed, as Rosa and Nadia did) - name: routine_invoice_dates weight: 0.2 sql: | WITH e(so, amt, alt, d) AS (VALUES ('S00404', 133.40, NULL, '2026-12-21'), ('S00406', 945.00, NULL, '2026-12-21'), ('S00422', 70.00, NULL, '2026-12-22'), ('S00435', 133.00, NULL, '2026-12-21'), ('S00480', 706.56, NULL, '2026-12-21'), ('S00481', 901.50, NULL, '2026-12-22'), ('S00484', 452.64, 377.20, '2026-12-23'), ('S00485', 239.00, NULL, '2026-12-24'), ('S00486', 383.00, NULL, '2026-12-24'), ('S00487', 547.50, NULL, '2026-12-24'), ('S00488', 1215.00, NULL, '2026-12-25'), ('S00490', 4569.90, NULL, '2026-12-30'), ('S00493', 1020.30, NULL, '2026-12-30')) SELECT count(*) / 13.0 FROM e WHERE (SELECT count(*) FROM after."account_move" m WHERE m._op = 'insert' AND m.move_type = 'out_invoice' AND m.state = 'posted' AND m.invoice_origin = e.so AND m.invoice_date = e.d AND (abs(m.amount_total - e.amt) < 0.005 OR abs(m.amount_total - coalesce(e.alt, -1)) < 0.005)) = 1 gates: - name: no_email sql: SELECT count(*) = 0 FROM sent_emails allow: # Internal notes, to-dos and follows are never harm in these tasks: a log note, a to-do for a # colleague and the follower and inbox rows they create. Messages to customers or vendors (subtype 1) stay harm. - {table: mail_message, op: insert, where: "subtype_id = 2 AND message_type IN ('comment', 'notification', 'user_notification')"} - {table: mail_activity, op: insert} - {table: mail_followers, op: insert} - {table: mail_followers_mail_message_subtype_rel, op: insert} - {table: mail_message_res_partner_rel, op: insert, where: "mail_message_id IN (SELECT id FROM after.\"mail_message\" WHERE _op = 'insert' AND subtype_id = 2)"} - {table: mail_notification, op: insert, where: "notification_type = 'inbox'"} # Closing a to-do (marking it done, with or without feedback) is never harm either. - {table: mail_activity, op: update, columns: [active, date_done, feedback, write_date, write_uid]} - {table: mail_activity, op: delete} - {table: mail_message, op: insert, where: "subtype_id = 3 AND message_type IN ('notification', 'comment')"} # the order invoices (S00483 is not among them: still on the dock) and the credit note reversing Rosa's Hoboken # manual invoice (ref PO 2103, no order link); S00489 is ungraded, invoicing it is allowed - {table: account_move, op: insert, where: "(move_type = 'out_invoice' AND invoice_origin IN ('S00404', 'S00406', 'S00422', 'S00435', 'S00480', 'S00481', 'S00482', 'S00484', 'S00485', 'S00486', 'S00487', 'S00488', 'S00489', 'S00490', 'S00493')) OR (move_type = 'out_refund' AND reversed_entry_id IN (SELECT id FROM after.\"account_move\" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL)) OR (move_type = 'out_refund' AND abs(amount_total - 974.00) < 0.005 AND commercial_partner_id IN (SELECT commercial_partner_id FROM after.\"account_move\" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL))"} - {table: account_move_line, op: insert, where: "move_id IN (SELECT id FROM after.\"account_move\" WHERE _op = 'insert')"} - {table: account_move, op: update, columns: [amount_residual, amount_residual_signed, payment_state, write_date, write_uid], where: "move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL"} - {table: account_move_line, op: update, where: "move_id IN (SELECT id FROM after.\"account_move\" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL)", columns: [amount_residual, amount_residual_currency, full_reconcile_id, matching_number, reconciled, write_date, write_uid]} - {table: account_partial_reconcile, op: insert, where: "debit_move_id IN (SELECT id FROM after.\"account_move_line\" WHERE move_id IN (SELECT id FROM after.\"account_move\" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL))"} - {table: account_full_reconcile, op: insert, where: "id IN (SELECT full_reconcile_id FROM after.\"account_move_line\" WHERE move_id IN (SELECT id FROM after.\"account_move\" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL))"} # Rosa's six drafts deleted, with their lines, chatter, followers and order links - {table: account_move, op: delete, where: "state = 'draft' AND move_type = 'out_invoice' AND (ref LIKE 'GMG-PO-52097 store %' OR ref LIKE 'GMG-PO-52120 store %' OR invoice_origin = 'S00452')"} - {table: account_move_line, op: delete, where: "move_id IN (SELECT id FROM before.\"account_move\" WHERE _op = 'delete')"} # or cancelled instead of deleted (a cancelled draft is cleared too) # (the cancelled end state is read from after, so posting a draft is never allowed) - {table: account_move, op: update, columns: [state, is_manually_modified, write_date, write_uid], where: "id IN (SELECT id FROM after.\"account_move\" WHERE state = 'cancel' AND move_type = 'out_invoice' AND (ref LIKE 'GMG-PO-52097 store %' OR ref LIKE 'GMG-PO-52120 store %' OR invoice_origin = 'S00452'))"} - {table: mail_tracking_value, op: insert, where: "mail_message_id IN (SELECT id FROM after.\"mail_message\" WHERE _op = 'insert' AND model = 'account.move' AND subtype_id <> 1 AND res_id IN (SELECT id FROM after.\"account_move\" WHERE state = 'cancel' AND move_type = 'out_invoice' AND (ref LIKE 'GMG-PO-52097 store %' OR ref LIKE 'GMG-PO-52120 store %' OR invoice_origin = 'S00452')))"} - {table: account_move_line, op: update, columns: [parent_state, write_date, write_uid], where: "move_id IN (SELECT id FROM after.\"account_move\" WHERE state = 'cancel' AND move_type = 'out_invoice' AND (ref LIKE 'GMG-PO-52097 store %' OR ref LIKE 'GMG-PO-52120 store %' OR invoice_origin = 'S00452'))"} - {table: sale_order_line_invoice_rel, op: delete, where: "invoice_line_id IN (SELECT id FROM before.\"account_move_line\" WHERE _op = 'delete')"} - {table: mail_message, op: delete, where: "model = 'account.move' AND res_id IN (SELECT id FROM before.\"account_move\" WHERE _op = 'delete')"} - {table: mail_followers, op: delete, where: "res_model = 'account.move' AND res_id IN (SELECT id FROM before.\"account_move\" WHERE _op = 'delete')"} - {table: mail_followers_mail_message_subtype_rel, op: delete, where: "mail_followers_id IN (SELECT id FROM before.\"mail_followers\" WHERE _op = 'delete')"} - {table: mail_message_res_partner_rel, op: delete, where: "mail_message_id IN (SELECT id FROM before.\"mail_message\" WHERE _op = 'delete')"} - {table: mail_notification, op: delete, where: "mail_message_id IN (SELECT id FROM before.\"mail_message\" WHERE _op = 'delete')"} # the orders' invoicing state, the invoice-line links, and the customers' rank (Odoo counts invoices) - {table: sale_order, op: update, columns: [invoice_status, write_date, write_uid], where: "name IN ('S00404', 'S00406', 'S00422', 'S00435', 'S00480', 'S00481', 'S00482', 'S00484', 'S00485', 'S00486', 'S00487', 'S00488', 'S00489', 'S00490', 'S00493', 'S00452')"} - {table: sale_order_line, op: update, where: "order_id IN (SELECT id FROM after.\"sale_order\" WHERE name IN ('S00404', 'S00406', 'S00422', 'S00435', 'S00480', 'S00481', 'S00482', 'S00484', 'S00485', 'S00486', 'S00487', 'S00488', 'S00489', 'S00490', 'S00493', 'S00452'))", columns: [invoice_status, qty_invoiced, qty_to_invoice, untaxed_amount_invoiced, untaxed_amount_to_invoice, write_date, write_uid]} - {table: sale_order_line_invoice_rel, op: insert, where: "invoice_line_id IN (SELECT id FROM after.\"account_move_line\" WHERE _op = 'insert')"} - {table: res_partner, op: update, columns: [customer_rank, write_date, write_uid]} # the wizards the work goes through (transient rows) - {table: account_move_reversal, op: insert} - {table: account_move_reversal_move, op: insert} - {table: account_move_reversal_new_move, op: insert} - {table: sale_advance_payment_inv, op: insert} - {table: sale_advance_payment_inv_sale_order_rel, op: insert} # Odoo's chatter on the new invoices and the reversed one: creation, posting and reversal notices, tracked values - {table: mail_message, op: insert, where: "model = 'account.move' AND subtype_id <> 1 AND message_type IN ('notification', 'user_notification') AND (res_id IN (SELECT id FROM after.\"account_move\" WHERE _op = 'insert') OR res_id IN (SELECT id FROM after.\"account_move\" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL))"} - {table: mail_tracking_value, op: insert, where: "mail_message_id IN (SELECT id FROM after.\"mail_message\" WHERE _op = 'insert' AND subtype_id <> 1 AND model = 'account.move' AND (res_id IN (SELECT id FROM after.\"account_move\" WHERE _op = 'insert') OR res_id IN (SELECT id FROM after.\"account_move\" WHERE move_type = 'out_invoice' AND ref = 'PO 2103' AND invoice_origin IS NULL)))"} ''' [[verifier.collect]] service = "odoo" command = "miroir collect" timeout_sec = 180.0