| pairs: | |
| - id: L1-001 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: How many products do we have in total? | |
| gold_sql: 'SELECT COUNT(*) AS product_count FROM product_product; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-002 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: List all warehouses with their internal codes. | |
| gold_sql: 'SELECT id, name, code FROM stock_warehouse ORDER BY name; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-003 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders have been confirmed? | |
| gold_sql: 'SELECT COUNT(*) AS confirmed_orders | |
| FROM sale_order | |
| WHERE state IN (''sale'',''done''); | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-004 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: Show the largest sale order by amount. | |
| gold_sql: 'SELECT id, name, amount_total | |
| FROM sale_order | |
| ORDER BY amount_total DESC NULLS LAST | |
| LIMIT 1; | |
| ' | |
| tags: | |
| - ranking | |
| - id: L1-005 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many posted journal entries do we have? | |
| gold_sql: 'SELECT COUNT(*) AS posted_moves | |
| FROM account_move | |
| WHERE state = ''posted''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-006 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: List all purchase orders and their statuses. | |
| gold_sql: 'SELECT id, name, state, amount_total | |
| FROM purchase_order | |
| ORDER BY id; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-007 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many stock pickings are in the done state? | |
| gold_sql: 'SELECT COUNT(*) AS completed_pickings | |
| FROM stock_picking | |
| WHERE state = ''done''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-008 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the total quantity in stock across all locations? | |
| gold_sql: 'SELECT SUM(quantity) AS total_quantity FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - sum | |
| - id: L1-009 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many distinct customers have placed orders? | |
| gold_sql: 'SELECT COUNT(DISTINCT partner_id) AS unique_customers | |
| FROM sale_order; | |
| ' | |
| tags: | |
| - aggregate | |
| - distinct | |
| - id: L1-010 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List the active currencies. | |
| gold_sql: 'SELECT id, name, symbol FROM res_currency WHERE active = true ORDER BY | |
| name; | |
| ' | |
| tags: | |
| - listing | |
| - filter | |
| - id: L2-001 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: List products with their on-hand quantities. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, COALESCE(SUM(sq.quantity), 0) | |
| AS on_hand | |
| FROM product_product pp | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| LEFT JOIN stock_quant sq ON sq.product_id = pp.id | |
| GROUP BY pp.id, pt.name | |
| ORDER BY on_hand DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-002 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show every warehouse with its number of internal locations. | |
| gold_sql: "SELECT w.name AS warehouse, COUNT(l.id) AS internal_locations\nFROM stock_warehouse\ | |
| \ w\nLEFT JOIN stock_location l\n ON l.location_id = w.view_location_id AND l.usage\ | |
| \ = 'internal'\nGROUP BY w.id, w.name\nORDER BY w.name;\n" | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-003 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List sale orders with the customer name. | |
| gold_sql: 'SELECT so.id, so.name, rp.name AS customer, so.amount_total | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-004 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Show each customer's total revenue from sale orders. | |
| gold_sql: 'SELECT rp.name AS customer, SUM(so.amount_total) AS total_revenue | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY rp.id, rp.name | |
| ORDER BY total_revenue DESC NULLS LAST; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-005 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: List purchase orders with the supplier name. | |
| gold_sql: 'SELECT po.id, po.name, rp.name AS supplier, po.amount_total | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-006 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show pickings with their carrier. | |
| gold_sql: 'SELECT sp.id, sp.name, dc.name AS carrier, sp.state | |
| FROM stock_picking sp | |
| LEFT JOIN delivery_carrier dc ON dc.id = sp.carrier_id | |
| ORDER BY sp.id; | |
| ' | |
| tags: | |
| - join | |
| - left_join | |
| - id: L2-007 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Show posted journal entries with their company. | |
| gold_sql: 'SELECT am.id, am.name, rc.name AS company, am.amount_total | |
| FROM account_move am | |
| JOIN res_company rc ON rc.id = am.company_id | |
| WHERE am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-008 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List invoices with their payment state and customer. | |
| gold_sql: "SELECT am.name AS invoice, rp.name AS customer,\n am.payment_state,\ | |
| \ am.amount_total\nFROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\n\ | |
| WHERE am.move_type = 'out_invoice' AND am.state = 'posted'\nORDER BY am.id;\n" | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-009 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show products with their internal category. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, pc.complete_name AS category | |
| FROM product_template pt | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| ORDER BY pc.complete_name, pt.name; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-010 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Count the pickings per warehouse. | |
| gold_sql: 'SELECT w.name AS warehouse, COUNT(sp.id) AS picking_count | |
| FROM stock_picking sp | |
| JOIN stock_picking_type pt ON pt.id = sp.picking_type_id | |
| JOIN stock_warehouse w ON w.id = pt.warehouse_id | |
| GROUP BY w.id, w.name | |
| ORDER BY picking_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L3-001 | |
| level: 3 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Compare total revenue and order count by customer this year. | |
| gold_sql: "SELECT rp.name AS customer,\n COUNT(so.id) AS order_count,\n \ | |
| \ SUM(so.amount_total) AS total_revenue\nFROM sale_order so\nJOIN res_partner\ | |
| \ rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\nORDER BY total_revenue\ | |
| \ DESC NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - aggregate | |
| - id: L3-002 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - demand | |
| nl: List products with both their on-hand quantity and total units sold this year. | |
| gold_sql: "WITH stock AS (\n SELECT product_id, SUM(quantity) AS on_hand FROM stock_quant\ | |
| \ GROUP BY product_id\n), sold AS (\n SELECT sol.product_id, SUM(sol.product_uom_qty)\ | |
| \ AS units_sold\n FROM sale_order_line sol\n JOIN sale_order so ON so.id = sol.order_id\n\ | |
| \ WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY sol.product_id\n)\nSELECT pt.name->>'en_US' AS product,\n\ | |
| \ COALESCE(s.on_hand, 0) AS on_hand,\n COALESCE(sd.units_sold, 0)\ | |
| \ AS units_sold\nFROM product_product pp\nJOIN product_template pt ON pt.id =\ | |
| \ pp.product_tmpl_id\nLEFT JOIN stock s ON s.product_id = pp.id\nLEFT JOIN sold\ | |
| \ sd ON sd.product_id = pp.id\nORDER BY product;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - cte | |
| - id: L3-003 | |
| level: 3 | |
| domains: | |
| - logistics | |
| - finance | |
| nl: Show purchase order total value by supplier for orders confirmed this year. | |
| gold_sql: "SELECT rp.name AS supplier, SUM(po.amount_total) AS total_value\nFROM\ | |
| \ purchase_order po\nJOIN res_partner rp ON rp.id = po.partner_id\nWHERE po.state\ | |
| \ IN ('purchase','done')\n AND po.date_order >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rp.id, rp.name\nORDER BY total_value DESC NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - id: L3-004 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - logistics | |
| nl: List products with both incoming and outgoing move volume this year. | |
| gold_sql: "SELECT pt.name->>'en_US' AS product,\n SUM(CASE WHEN ldst.usage\ | |
| \ = 'internal' AND lsrc.usage <> 'internal'\n THEN sm.product_qty\ | |
| \ ELSE 0 END) AS incoming_qty,\n SUM(CASE WHEN ldst.usage <> 'internal'\ | |
| \ AND lsrc.usage = 'internal'\n THEN sm.product_qty ELSE 0 END)\ | |
| \ AS outgoing_qty\nFROM stock_move sm\nJOIN product_product pp ON pp.id = sm.product_id\n\ | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id\nJOIN stock_location lsrc\ | |
| \ ON lsrc.id = sm.location_id\nJOIN stock_location ldst ON ldst.id = sm.location_dest_id\n\ | |
| WHERE sm.state = 'done'\n AND sm.date >= date_trunc('year', NOW())\nGROUP BY\ | |
| \ pt.name\nORDER BY product;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - case_when | |
| - id: L3-005 | |
| level: 3 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Show monthly revenue trend for this year. | |
| gold_sql: "SELECT date_trunc('month', so.date_order) AS month,\n SUM(so.amount_total)\ | |
| \ AS revenue\nFROM sale_order so\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY 1\nORDER BY 1;\n" | |
| tags: | |
| - temporal | |
| - group_by_date | |
| - id: L3-006 | |
| level: 3 | |
| domains: | |
| - demand | |
| - logistics | |
| nl: How many sale orders confirmed last 90 days got delivered? | |
| gold_sql: "SELECT COUNT(DISTINCT so.id) AS delivered_orders\nFROM sale_order so\n\ | |
| JOIN stock_picking sp ON sp.sale_id = so.id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= NOW() - INTERVAL '90 days'\n AND sp.state = 'done';\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - rolling | |
| - id: L3-007 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - finance | |
| nl: Show inventory valuation by product category. | |
| gold_sql: "SELECT pc.complete_name AS category,\n SUM(svl.remaining_value)\ | |
| \ AS inventory_value\nFROM stock_valuation_layer svl\nJOIN product_product pp\ | |
| \ ON pp.id = svl.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE svl.remaining_qty > 0\n\ | |
| GROUP BY pc.complete_name\nORDER BY inventory_value DESC NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - aggregate | |
| - id: L3-008 | |
| level: 3 | |
| domains: | |
| - demand | |
| - logistics | |
| nl: Show top 10 products by units sold this year. | |
| gold_sql: "SELECT pt.name->>'en_US' AS product, SUM(sol.product_uom_qty) AS units_sold\n\ | |
| FROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW())\n\ | |
| GROUP BY pt.name\nORDER BY units_sold DESC NULLS LAST\nLIMIT 10;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - ranking | |
| - id: L3-009 | |
| level: 3 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Compare confirmed sales versus invoiced revenue this year. | |
| gold_sql: "WITH sales AS (\n SELECT SUM(amount_total) AS confirmed_sales FROM sale_order\n\ | |
| \ WHERE state IN ('sale','done')\n AND date_order >= date_trunc('year', NOW())\n\ | |
| ), invoiced AS (\n SELECT SUM(amount_total_signed) AS invoiced_revenue FROM account_move\n\ | |
| \ WHERE move_type = 'out_invoice' AND state = 'posted'\n AND date >= date_trunc('year',\ | |
| \ NOW())\n)\nSELECT confirmed_sales, invoiced_revenue\nFROM sales CROSS JOIN invoiced;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - cte | |
| - cross_join | |
| - id: L3-010 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - logistics | |
| nl: Show number of pickings per warehouse last 30 days. | |
| gold_sql: 'SELECT w.name AS warehouse, COUNT(sp.id) AS picking_count | |
| FROM stock_picking sp | |
| JOIN stock_picking_type pt ON pt.id = sp.picking_type_id | |
| JOIN stock_warehouse w ON w.id = pt.warehouse_id | |
| WHERE sp.scheduled_date >= NOW() - INTERVAL ''30 days'' | |
| GROUP BY w.id, w.name | |
| ORDER BY picking_count DESC; | |
| ' | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - rolling | |
| - id: L3-011 | |
| level: 3 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Show this month's total sales and number of unique customers. | |
| gold_sql: "SELECT COUNT(DISTINCT partner_id) AS unique_customers,\n SUM(amount_total)\ | |
| \ AS total_sales\nFROM sale_order\nWHERE state IN ('sale','done')\n AND date_order\ | |
| \ >= date_trunc('month', NOW());\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - aggregate | |
| - id: L3-012 | |
| level: 3 | |
| domains: | |
| - demand | |
| - finance | |
| nl: Show year-to-date sales by company. | |
| gold_sql: "SELECT rc.name AS company,\n COUNT(so.id) AS order_count,\n \ | |
| \ SUM(so.amount_total) AS ytd_sales\nFROM sale_order so\nJOIN res_company rc\ | |
| \ ON rc.id = so.company_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY rc.id, rc.name\nORDER BY ytd_sales DESC\ | |
| \ NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - ytd | |
| - id: L3-013 | |
| level: 3 | |
| domains: | |
| - logistics | |
| - inventory | |
| nl: Show on-hand quantity by warehouse and product category. | |
| gold_sql: "SELECT w.name AS warehouse, pc.complete_name AS category,\n SUM(sq.quantity)\ | |
| \ AS on_hand\nFROM stock_quant sq\nJOIN stock_location l ON l.id = sq.location_id\n\ | |
| JOIN stock_warehouse w ON w.view_location_id = l.location_id\nJOIN product_product\ | |
| \ pp ON pp.id = sq.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE l.usage = 'internal'\n\ | |
| GROUP BY w.name, pc.complete_name\nORDER BY w.name, on_hand DESC NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - group_by_two | |
| - id: L3-014 | |
| level: 3 | |
| domains: | |
| - finance | |
| - demand | |
| nl: What is the average order value this quarter? | |
| gold_sql: "SELECT AVG(amount_total) AS avg_order_value\nFROM sale_order\nWHERE state\ | |
| \ IN ('sale','done')\n AND date_order >= date_trunc('quarter', NOW());\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - average | |
| - id: L3-015 | |
| level: 3 | |
| domains: | |
| - demand | |
| - logistics | |
| nl: Show how many sale orders this month have not yet shipped. | |
| gold_sql: "SELECT COUNT(DISTINCT so.id) AS pending_shipments\nFROM sale_order so\n\ | |
| LEFT JOIN stock_picking sp\n ON sp.sale_id = so.id AND sp.state = 'done'\nWHERE\ | |
| \ so.state IN ('sale','done')\n AND so.date_order >= date_trunc('month', NOW())\n\ | |
| \ AND sp.id IS NULL;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - anti_join | |
| - id: L4-001 | |
| level: 4 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Compute total invoiced revenue converted to company currency. | |
| gold_sql: "SELECT rc.name AS company,\n SUM(am.amount_total_signed) AS revenue_company_currency\n\ | |
| FROM account_move am\nJOIN res_company rc ON rc.id = am.company_id\nWHERE am.move_type\ | |
| \ = 'out_invoice' AND am.state = 'posted'\nGROUP BY rc.id, rc.name\nORDER BY revenue_company_currency\ | |
| \ DESC NULLS LAST;\n" | |
| tags: | |
| - federation_stub | |
| - currency | |
| - id: L4-002 | |
| level: 4 | |
| domains: | |
| - inventory | |
| - finance | |
| nl: 'Show landed inventory value: stock valuation plus average procurement cost.' | |
| gold_sql: "WITH valuation AS (\n SELECT product_id, SUM(remaining_value) AS book_value\n\ | |
| \ FROM stock_valuation_layer\n WHERE remaining_qty > 0\n GROUP BY product_id\n\ | |
| ), avg_cost AS (\n SELECT pol.product_id, AVG(pol.price_unit) AS avg_unit_cost\n\ | |
| \ FROM purchase_order_line pol\n JOIN purchase_order po ON po.id = pol.order_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n GROUP BY pol.product_id\n)\nSELECT\ | |
| \ pt.name->>'en_US' AS product,\n COALESCE(v.book_value, 0) AS book_value,\n\ | |
| \ COALESCE(c.avg_unit_cost, 0) AS avg_unit_cost\nFROM product_product pp\n\ | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id\nLEFT JOIN valuation v\ | |
| \ ON v.product_id = pp.id\nLEFT JOIN avg_cost c ON c.product_id = pp.id\nORDER\ | |
| \ BY book_value DESC NULLS LAST\nLIMIT 50;\n" | |
| tags: | |
| - federation_stub | |
| - cte_dual | |
| - id: L4-003 | |
| level: 4 | |
| domains: | |
| - demand | |
| - logistics | |
| - finance | |
| nl: Show sales, fulfilment time, and gross margin by product this year. | |
| gold_sql: "WITH sales AS (\n SELECT sol.product_id,\n SUM(sol.product_uom_qty)\ | |
| \ AS units_sold,\n SUM(sol.price_subtotal) AS revenue\n FROM sale_order_line\ | |
| \ sol\n JOIN sale_order so ON so.id = sol.order_id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY sol.product_id\n\ | |
| )\nSELECT pt.name->>'en_US' AS product,\n s.units_sold, s.revenue\nFROM\ | |
| \ product_product pp\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN sales s ON s.product_id = pp.id\nORDER BY revenue DESC NULLS LAST\nLIMIT\ | |
| \ 20;\n" | |
| tags: | |
| - federation_stub | |
| - multi_domain | |
| - id: L4-004 | |
| level: 4 | |
| domains: | |
| - inventory | |
| - demand | |
| nl: Show stock turn ratio (units sold YTD / average on-hand) by product. | |
| gold_sql: "WITH stock AS (\n SELECT product_id, AVG(quantity) AS avg_on_hand\n\ | |
| \ FROM stock_quant GROUP BY product_id\n), sold AS (\n SELECT sol.product_id,\ | |
| \ SUM(sol.product_uom_qty) AS units_sold\n FROM sale_order_line sol\n JOIN sale_order\ | |
| \ so ON so.id = sol.order_id\n WHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\n GROUP BY sol.product_id\n)\nSELECT pt.name->>'en_US'\ | |
| \ AS product,\n sd.units_sold, st.avg_on_hand,\n CASE WHEN st.avg_on_hand\ | |
| \ > 0\n THEN sd.units_sold / st.avg_on_hand ELSE NULL END AS turn_ratio\n\ | |
| FROM product_product pp\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN stock st ON st.product_id = pp.id\nJOIN sold sd ON sd.product_id = pp.id\n\ | |
| ORDER BY turn_ratio DESC NULLS LAST\nLIMIT 20;\n" | |
| tags: | |
| - federation_stub | |
| - derived_metric | |
| - id: L4-005 | |
| level: 4 | |
| domains: | |
| - logistics | |
| - finance | |
| nl: Show total spend per supplier with their company breakdown. | |
| gold_sql: "SELECT rp.name AS supplier, rc.name AS company,\n SUM(po.amount_total)\ | |
| \ AS spend\nFROM purchase_order po\nJOIN res_partner rp ON rp.id = po.partner_id\n\ | |
| JOIN res_company rc ON rc.id = po.company_id\nWHERE po.state IN ('purchase','done')\n\ | |
| GROUP BY rp.id, rp.name, rc.id, rc.name\nORDER BY spend DESC NULLS LAST;\n" | |
| tags: | |
| - federation_stub | |
| - group_by_two | |
| - id: L5-001 | |
| level: 5 | |
| domains: | |
| - inventory | |
| - demand | |
| nl: Identify products at risk of stock-out (on-hand below average monthly demand). | |
| gold_sql: "WITH demand_per_month AS (\n SELECT sol.product_id,\n SUM(sol.product_uom_qty)\ | |
| \ / NULLIF(GREATEST(1,\n EXTRACT(MONTH FROM NOW())::int), 0) AS avg_monthly_demand\n\ | |
| \ FROM sale_order_line sol\n JOIN sale_order so ON so.id = sol.order_id\n WHERE\ | |
| \ so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW())\n\ | |
| \ GROUP BY sol.product_id\n), stock AS (\n SELECT product_id, SUM(quantity)\ | |
| \ AS on_hand\n FROM stock_quant GROUP BY product_id\n)\nSELECT pt.name->>'en_US'\ | |
| \ AS product,\n COALESCE(s.on_hand, 0) AS on_hand,\n COALESCE(d.avg_monthly_demand,\ | |
| \ 0) AS avg_monthly_demand\nFROM product_product pp\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nLEFT JOIN stock s ON s.product_id = pp.id\nLEFT\ | |
| \ JOIN demand_per_month d ON d.product_id = pp.id\nWHERE COALESCE(d.avg_monthly_demand,\ | |
| \ 0) > 0\n AND COALESCE(s.on_hand, 0) < d.avg_monthly_demand\nORDER BY avg_monthly_demand\ | |
| \ DESC NULLS LAST;\n" | |
| tags: | |
| - predictive | |
| - risk | |
| - id: L5-002 | |
| level: 5 | |
| domains: | |
| - demand | |
| - finance | |
| nl: Project this year's revenue by extrapolating the current monthly average to | |
| a full year. | |
| gold_sql: "WITH ytd AS (\n SELECT SUM(amount_total) AS ytd_revenue,\n GREATEST(1,\ | |
| \ EXTRACT(MONTH FROM NOW())::int) AS months_elapsed\n FROM sale_order\n WHERE\ | |
| \ state IN ('sale','done')\n AND date_order >= date_trunc('year', NOW())\n\ | |
| )\nSELECT ytd_revenue,\n months_elapsed,\n ROUND( (ytd_revenue / months_elapsed)\ | |
| \ * 12 ) AS projected_annual\nFROM ytd;\n" | |
| tags: | |
| - predictive | |
| - projection | |
| - id: L5-003 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Find the most valuable customer segment based on order frequency and total revenue. | |
| gold_sql: "SELECT rp.name AS customer,\n COUNT(so.id) AS order_count,\n \ | |
| \ SUM(so.amount_total) AS total_revenue,\n AVG(so.amount_total) AS avg_order_value\n\ | |
| FROM sale_order so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state\ | |
| \ IN ('sale','done')\nGROUP BY rp.id, rp.name\nHAVING COUNT(so.id) > 0\nORDER\ | |
| \ BY total_revenue DESC NULLS LAST\nLIMIT 5;\n" | |
| tags: | |
| - predictive | |
| - segmentation | |
| - id: L5-004 | |
| level: 5 | |
| domains: | |
| - logistics | |
| - inventory | |
| nl: Which products have the longest supplier delivery times historically? | |
| gold_sql: "SELECT pt.name->>'en_US' AS product,\n rp.name AS supplier,\n \ | |
| \ COUNT(*) AS observations\nFROM purchase_order_line pol\nJOIN purchase_order\ | |
| \ po ON po.id = pol.order_id\nJOIN res_partner rp ON rp.id = po.partner_id\nJOIN\ | |
| \ product_product pp ON pp.id = pol.product_id\nJOIN product_template pt ON pt.id\ | |
| \ = pp.product_tmpl_id\nWHERE po.state IN ('purchase','done')\nGROUP BY pt.name,\ | |
| \ rp.name\nORDER BY observations DESC NULLS LAST\nLIMIT 10;\n" | |
| tags: | |
| - predictive | |
| - historical | |
| - id: L5-005 | |
| level: 5 | |
| domains: | |
| - finance | |
| - demand | |
| - inventory | |
| nl: Identify products with high revenue but low inventory turn. | |
| gold_sql: "WITH revenue AS (\n SELECT sol.product_id, SUM(sol.price_subtotal) AS\ | |
| \ revenue\n FROM sale_order_line sol\n JOIN sale_order so ON so.id = sol.order_id\n\ | |
| \ WHERE so.state IN ('sale','done')\n GROUP BY sol.product_id\n), on_hand AS\ | |
| \ (\n SELECT product_id, SUM(quantity) AS qty FROM stock_quant GROUP BY product_id\n\ | |
| )\nSELECT pt.name->>'en_US' AS product,\n r.revenue, h.qty\nFROM product_product\ | |
| \ pp\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\nJOIN revenue r ON\ | |
| \ r.product_id = pp.id\nLEFT JOIN on_hand h ON h.product_id = pp.id\nWHERE r.revenue\ | |
| \ IS NOT NULL\nORDER BY r.revenue DESC NULLS LAST\nLIMIT 10;\n" | |
| tags: | |
| - predictive | |
| - three_domain | |
| - id: L6-001 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show top customers by revenue this year. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY revenue DESC NULLS LAST;\n" | |
| - nl: Only the top 5. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY revenue DESC NULLS LAST\nLIMIT 5;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-002 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: Show on-hand quantity by product. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, SUM(sq.quantity) AS on_hand | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.name | |
| ORDER BY on_hand DESC NULLS LAST; | |
| ' | |
| - nl: Just the ones with quantity over 10. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, SUM(sq.quantity) AS on_hand | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.name | |
| HAVING SUM(sq.quantity) > 10 | |
| ORDER BY on_hand DESC NULLS LAST; | |
| ' | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-003 | |
| level: 6 | |
| domains: | |
| - finance | |
| - demand | |
| turns: | |
| - nl: Show total revenue this quarter. | |
| gold_sql: "SELECT SUM(amount_total) AS total_revenue\nFROM sale_order\nWHERE state\ | |
| \ IN ('sale','done')\n AND date_order >= date_trunc('quarter', NOW());\n" | |
| - nl: Compare with the same quarter last year. | |
| gold_sql: "SELECT\n SUM(CASE WHEN date_order >= date_trunc('quarter', NOW())\n\ | |
| \ THEN amount_total ELSE 0 END) AS current_quarter,\n SUM(CASE WHEN\ | |
| \ date_order >= date_trunc('quarter', NOW()) - INTERVAL '1 year'\n \ | |
| \ AND date_order < date_trunc('quarter', NOW()) - INTERVAL '1 year' + INTERVAL\ | |
| \ '3 months'\n THEN amount_total ELSE 0 END) AS same_quarter_last_year\n\ | |
| FROM sale_order\nWHERE state IN ('sale','done');\n" | |
| tags: | |
| - multi_turn | |
| - comparison | |
| - yoy | |
| - id: L6-004 | |
| level: 6 | |
| domains: | |
| - logistics | |
| turns: | |
| - nl: List purchase orders this year. | |
| gold_sql: 'SELECT id, name, amount_total, state | |
| FROM purchase_order | |
| WHERE date_order >= date_trunc(''year'', NOW()) | |
| ORDER BY id; | |
| ' | |
| - nl: Only the confirmed ones. | |
| gold_sql: "SELECT id, name, amount_total, state\nFROM purchase_order\nWHERE date_order\ | |
| \ >= date_trunc('year', NOW())\n AND state IN ('purchase','done')\nORDER BY\ | |
| \ id;\n" | |
| - nl: Sort by amount descending. | |
| gold_sql: "SELECT id, name, amount_total, state\nFROM purchase_order\nWHERE date_order\ | |
| \ >= date_trunc('year', NOW())\n AND state IN ('purchase','done')\nORDER BY\ | |
| \ amount_total DESC NULLS LAST;\n" | |
| tags: | |
| - multi_turn | |
| - three_turn | |
| - id: L6-005 | |
| level: 6 | |
| domains: | |
| - inventory | |
| - demand | |
| turns: | |
| - nl: Show products with their total revenue this year. | |
| gold_sql: "SELECT pt.name->>'en_US' AS product, SUM(sol.price_subtotal) AS revenue\n\ | |
| FROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pt.name\nORDER BY revenue DESC NULLS LAST;\n" | |
| - nl: Add their current stock quantity. | |
| gold_sql: "WITH rev AS (\n SELECT pp.id AS product_id, pt.name->>'en_US' AS product,\n\ | |
| \ SUM(sol.price_subtotal) AS revenue\n FROM sale_order_line sol\n \ | |
| \ JOIN sale_order so ON so.id = sol.order_id\n JOIN product_product pp ON pp.id\ | |
| \ = sol.product_id\n JOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| \ WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY pp.id, pt.name\n)\nSELECT r.product, r.revenue, COALESCE(SUM(sq.quantity),\ | |
| \ 0) AS on_hand\nFROM rev r\nLEFT JOIN stock_quant sq ON sq.product_id = r.product_id\n\ | |
| GROUP BY r.product, r.revenue\nORDER BY r.revenue DESC NULLS LAST;\n" | |
| tags: | |
| - multi_turn | |
| - augmentation | |
| - id: L1-011 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: Show the top 5 most expensive products by list price. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, pt.list_price | |
| FROM product_template pt | |
| WHERE pt.list_price IS NOT NULL | |
| ORDER BY pt.list_price DESC NULLS LAST | |
| LIMIT 5; | |
| ' | |
| tags: | |
| - ranking | |
| - listing | |
| - id: L1-012 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many purchase orders are in draft state? | |
| gold_sql: 'SELECT COUNT(*) AS draft_pos | |
| FROM purchase_order | |
| WHERE state = ''draft''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-013 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: List all internal stock locations. | |
| gold_sql: 'SELECT id, name, complete_name | |
| FROM stock_location | |
| WHERE usage = ''internal'' | |
| ORDER BY complete_name; | |
| ' | |
| tags: | |
| - listing | |
| - filter | |
| - id: L1-014 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: How many active product templates do we have? | |
| gold_sql: 'SELECT COUNT(*) AS active_templates | |
| FROM product_template | |
| WHERE active = true; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-015 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: Count distinct companies that have posted journal entries. | |
| gold_sql: 'SELECT COUNT(DISTINCT company_id) AS active_companies | |
| FROM account_move | |
| WHERE state = ''posted''; | |
| ' | |
| tags: | |
| - aggregate | |
| - distinct | |
| - id: L1-016 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many stock moves are still in waiting state? | |
| gold_sql: 'SELECT COUNT(*) AS waiting_moves | |
| FROM stock_move | |
| WHERE state = ''waiting''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-017 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: What is the total quantity sold across all sale order lines? | |
| gold_sql: 'SELECT COALESCE(SUM(product_uom_qty), 0) AS total_units_sold | |
| FROM sale_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - sum | |
| - id: L1-018 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count purchase orders confirmed this month. | |
| gold_sql: "SELECT COUNT(*) AS confirmed_pos_this_month\nFROM purchase_order\nWHERE\ | |
| \ state IN ('purchase','done')\n AND date_order >= date_trunc('month', NOW());\n" | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L1-019 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: List the 5 largest sale orders by amount this year. | |
| gold_sql: "SELECT id, name, amount_total\nFROM sale_order\nWHERE state IN ('sale','done')\n\ | |
| \ AND date_order >= date_trunc('year', NOW())\nORDER BY amount_total DESC NULLS\ | |
| \ LAST\nLIMIT 5;\n" | |
| tags: | |
| - ranking | |
| - temporal | |
| - id: L1-020 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List companies and their currency symbols. | |
| gold_sql: 'SELECT rc.name AS company, cur.symbol AS currency_symbol | |
| FROM res_company rc | |
| JOIN res_currency cur ON cur.id = rc.currency_id | |
| ORDER BY rc.name; | |
| ' | |
| tags: | |
| - listing | |
| - id: L2-011 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show products with their default unit of measure. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, u.name->>''en_US'' AS uom | |
| FROM product_template pt | |
| JOIN uom_uom u ON u.id = pt.uom_id | |
| ORDER BY pt.name; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-012 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List sale orders with their line count. | |
| gold_sql: 'SELECT so.id, so.name, COUNT(sol.id) AS line_count | |
| FROM sale_order so | |
| LEFT JOIN sale_order_line sol ON sol.order_id = so.id | |
| GROUP BY so.id, so.name | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-013 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show pickings with their source and destination location. | |
| gold_sql: "SELECT sp.id, sp.name,\n lsrc.complete_name AS source_location,\n\ | |
| \ ldst.complete_name AS dest_location\nFROM stock_picking sp\nJOIN stock_location\ | |
| \ lsrc ON lsrc.id = sp.location_id\nJOIN stock_location ldst ON ldst.id = sp.location_dest_id\n\ | |
| ORDER BY sp.id\nLIMIT 50;\n" | |
| tags: | |
| - join | |
| - multi_join | |
| - id: L2-014 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List invoices with their currency code. | |
| gold_sql: "SELECT am.name AS invoice, cur.name AS currency, am.amount_total\nFROM\ | |
| \ account_move am\nJOIN res_currency cur ON cur.id = am.currency_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\nORDER BY am.id;\n" | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-015 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show product categories with their template count. | |
| gold_sql: "SELECT pc.complete_name AS category,\n COUNT(pt.id) AS template_count\n\ | |
| FROM product_category pc\nLEFT JOIN product_template pt ON pt.categ_id = pc.id\n\ | |
| GROUP BY pc.id, pc.complete_name\nORDER BY template_count DESC NULLS LAST;\n" | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-016 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Show sale orders with their salesperson name. | |
| gold_sql: 'SELECT so.id, so.name, rp.name AS salesperson, so.amount_total | |
| FROM sale_order so | |
| LEFT JOIN res_users ru ON ru.id = so.user_id | |
| LEFT JOIN res_partner rp ON rp.id = ru.partner_id | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - multi_join | |
| - id: L2-017 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: List purchase order lines with the product name and quantity. | |
| gold_sql: "SELECT po.name AS purchase_order,\n pt.name->>'en_US' AS product,\n\ | |
| \ pol.product_qty,\n pol.price_unit\nFROM purchase_order_line pol\n\ | |
| JOIN purchase_order po ON po.id = pol.order_id\nJOIN product_product pp ON pp.id\ | |
| \ = pol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\nORDER\ | |
| \ BY po.id, pol.id;\n" | |
| tags: | |
| - join | |
| - multi_join | |
| - id: L2-018 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Show account moves with their line count and total. | |
| gold_sql: "SELECT am.id, am.name,\n COUNT(aml.id) AS line_count,\n am.amount_total\n\ | |
| FROM account_move am\nLEFT JOIN account_move_line aml ON aml.move_id = am.id\n\ | |
| WHERE am.state = 'posted'\nGROUP BY am.id, am.name, am.amount_total\nORDER BY\ | |
| \ am.id\nLIMIT 50;\n" | |
| tags: | |
| - join | |
| - aggregate | |
| - filter | |
| - id: L2-019 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show products that have reordering rules defined. | |
| gold_sql: 'SELECT DISTINCT pt.name->>''en_US'' AS product, owr.product_min_qty, | |
| owr.product_max_qty | |
| FROM stock_warehouse_orderpoint owr | |
| JOIN product_product pp ON pp.id = owr.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| ORDER BY product; | |
| ' | |
| tags: | |
| - join | |
| - distinct | |
| - id: L2-020 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List sale orders with their pricelist. | |
| gold_sql: 'SELECT so.id, so.name, pl.name AS pricelist | |
| FROM sale_order so | |
| JOIN product_pricelist pl ON pl.id = so.pricelist_id | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L3-016 | |
| level: 3 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Compare revenue this quarter versus last quarter. | |
| gold_sql: "SELECT\n SUM(CASE WHEN date_order >= date_trunc('quarter', NOW())\n\ | |
| \ THEN amount_total ELSE 0 END) AS current_quarter,\n SUM(CASE WHEN\ | |
| \ date_order >= date_trunc('quarter', NOW()) - INTERVAL '3 months'\n \ | |
| \ AND date_order < date_trunc('quarter', NOW())\n THEN amount_total\ | |
| \ ELSE 0 END) AS prior_quarter\nFROM sale_order\nWHERE state IN ('sale','done');\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - qoq | |
| - case_when | |
| - id: L3-017 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - logistics | |
| nl: Show products with their on-hand quantity and any reorder min/max thresholds. | |
| gold_sql: "WITH stock AS (\n SELECT product_id, SUM(quantity) AS on_hand\n FROM\ | |
| \ stock_quant GROUP BY product_id\n), rules AS (\n SELECT product_id,\n \ | |
| \ MAX(product_min_qty) AS reorder_min,\n MAX(product_max_qty) AS reorder_max\n\ | |
| \ FROM stock_warehouse_orderpoint\n GROUP BY product_id\n)\nSELECT pt.name->>'en_US'\ | |
| \ AS product,\n COALESCE(s.on_hand, 0) AS on_hand,\n r.reorder_min,\ | |
| \ r.reorder_max\nFROM product_product pp\nJOIN product_template pt ON pt.id =\ | |
| \ pp.product_tmpl_id\nLEFT JOIN stock s ON s.product_id = pp.id\nLEFT JOIN rules\ | |
| \ r ON r.product_id = pp.id\nORDER BY product;\n" | |
| tags: | |
| - cross_domain | |
| - cte | |
| - id: L3-018 | |
| level: 3 | |
| domains: | |
| - demand | |
| - finance | |
| nl: Show outstanding invoiced amount by customer for posted invoices. | |
| gold_sql: "SELECT rp.name AS customer,\n SUM(am.amount_residual) AS outstanding\n\ | |
| FROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\n AND am.amount_residual > 0\nGROUP\ | |
| \ BY rp.id, rp.name\nORDER BY outstanding DESC NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - aggregate | |
| - id: L3-019 | |
| level: 3 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Show top 10 products by revenue in the last 30 days. | |
| gold_sql: "SELECT pt.name->>'en_US' AS product,\n SUM(sol.price_subtotal)\ | |
| \ AS revenue\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt ON\ | |
| \ pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= NOW() - INTERVAL '30 days'\nGROUP BY pt.name\nORDER BY revenue DESC NULLS\ | |
| \ LAST\nLIMIT 10;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - rolling | |
| - ranking | |
| - id: L3-020 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - demand | |
| nl: Show products ordered this month alongside their current stock level. | |
| gold_sql: "WITH ordered AS (\n SELECT sol.product_id, SUM(sol.product_uom_qty)\ | |
| \ AS units_ordered\n FROM sale_order_line sol\n JOIN sale_order so ON so.id\ | |
| \ = sol.order_id\n WHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ date_trunc('month', NOW())\n GROUP BY sol.product_id\n), stock AS (\n SELECT\ | |
| \ product_id, SUM(quantity) AS on_hand\n FROM stock_quant GROUP BY product_id\n\ | |
| )\nSELECT pt.name->>'en_US' AS product,\n o.units_ordered,\n COALESCE(s.on_hand,\ | |
| \ 0) AS on_hand\nFROM ordered o\nJOIN product_product pp ON pp.id = o.product_id\n\ | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id\nLEFT JOIN stock s ON s.product_id\ | |
| \ = pp.id\nORDER BY o.units_ordered DESC NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - cte | |
| - id: L3-021 | |
| level: 3 | |
| domains: | |
| - logistics | |
| - demand | |
| nl: Show sale orders shipped within 7 days of confirmation this year. | |
| gold_sql: "SELECT so.id, so.name, so.date_order, MIN(sp.date_done) AS shipped_at\n\ | |
| FROM sale_order so\nJOIN stock_picking sp ON sp.sale_id = so.id\nWHERE so.state\ | |
| \ IN ('sale','done')\n AND sp.state = 'done'\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY so.id, so.name, so.date_order\nHAVING MIN(sp.date_done) - so.date_order\ | |
| \ < INTERVAL '7 days'\nORDER BY so.id\nLIMIT 50;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - having | |
| - id: L3-022 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - finance | |
| nl: Show inventory value by warehouse using stock valuation. | |
| gold_sql: "SELECT w.name AS warehouse,\n SUM(svl.remaining_value) AS inventory_value\n\ | |
| FROM stock_valuation_layer svl\nJOIN stock_quant sq ON sq.product_id = svl.product_id\n\ | |
| JOIN stock_location l ON l.id = sq.location_id\nJOIN stock_warehouse w ON w.view_location_id\ | |
| \ = l.location_id\nWHERE svl.remaining_qty > 0\n AND l.usage = 'internal'\nGROUP\ | |
| \ BY w.id, w.name\nORDER BY inventory_value DESC NULLS LAST;\n" | |
| tags: | |
| - cross_domain | |
| - aggregate | |
| - id: L3-023 | |
| level: 3 | |
| domains: | |
| - finance | |
| - logistics | |
| nl: Compare confirmed purchase value with paid supplier invoices this year. | |
| gold_sql: "WITH pos AS (\n SELECT SUM(amount_total) AS po_value\n FROM purchase_order\n\ | |
| \ WHERE state IN ('purchase','done')\n AND date_order >= date_trunc('year',\ | |
| \ NOW())\n), invs AS (\n SELECT SUM(amount_total) AS supplier_invoiced\n FROM\ | |
| \ account_move\n WHERE move_type = 'in_invoice'\n AND state = 'posted'\n \ | |
| \ AND date >= date_trunc('year', NOW())\n)\nSELECT pos.po_value, invs.supplier_invoiced\n\ | |
| FROM pos CROSS JOIN invs;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - cte | |
| - cross_join | |
| - id: L3-024 | |
| level: 3 | |
| domains: | |
| - demand | |
| - finance | |
| nl: Show revenue by sales team this year. | |
| gold_sql: "SELECT COALESCE(t.name->>'en_US', 'Unassigned') AS sales_team,\n \ | |
| \ SUM(so.amount_total) AS revenue\nFROM sale_order so\nLEFT JOIN crm_team t\ | |
| \ ON t.id = so.team_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY t.id, t.name\nORDER BY revenue DESC NULLS\ | |
| \ LAST;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - left_join | |
| - id: L3-025 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - demand | |
| nl: List products that have never been sold. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product | |
| FROM product_product pp | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| LEFT JOIN sale_order_line sol ON sol.product_id = pp.id | |
| WHERE sol.id IS NULL | |
| ORDER BY product; | |
| ' | |
| tags: | |
| - cross_domain | |
| - anti_join | |
| - id: L3-026 | |
| level: 3 | |
| domains: | |
| - logistics | |
| - finance | |
| nl: Show monthly purchase spend trend this year. | |
| gold_sql: "SELECT date_trunc('month', po.date_order) AS month,\n SUM(po.amount_total)\ | |
| \ AS spend\nFROM purchase_order po\nWHERE po.state IN ('purchase','done')\n AND\ | |
| \ po.date_order >= date_trunc('year', NOW())\nGROUP BY 1\nORDER BY 1;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - group_by_date | |
| - id: L3-027 | |
| level: 3 | |
| domains: | |
| - demand | |
| - logistics | |
| nl: What percentage of confirmed sale orders this year were fully shipped? | |
| gold_sql: "WITH conf AS (\n SELECT COUNT(*) AS total\n FROM sale_order\n WHERE\ | |
| \ state IN ('sale','done')\n AND date_order >= date_trunc('year', NOW())\n\ | |
| ), shipped AS (\n SELECT COUNT(DISTINCT so.id) AS shipped\n FROM sale_order\ | |
| \ so\n JOIN stock_picking sp ON sp.sale_id = so.id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n AND sp.state = 'done'\n\ | |
| )\nSELECT conf.total, shipped.shipped,\n ROUND(100.0 * shipped.shipped /\ | |
| \ NULLIF(conf.total, 0), 2) AS pct_shipped\nFROM conf CROSS JOIN shipped;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - cte | |
| - derived_metric | |
| - id: L3-028 | |
| level: 3 | |
| domains: | |
| - finance | |
| - inventory | |
| nl: Show products with negative stock valuation entries. | |
| gold_sql: "SELECT pt.name->>'en_US' AS product,\n SUM(svl.value) AS net_valuation\n\ | |
| FROM stock_valuation_layer svl\nJOIN product_product pp ON pp.id = svl.product_id\n\ | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id\nGROUP BY pt.name\nHAVING\ | |
| \ SUM(svl.value) < 0\nORDER BY net_valuation;\n" | |
| tags: | |
| - cross_domain | |
| - having | |
| - anomaly | |
| - id: L3-029 | |
| level: 3 | |
| domains: | |
| - demand | |
| - finance | |
| nl: Identify customers with no order in the last 90 days but who ordered earlier | |
| this year. | |
| gold_sql: "SELECT rp.id, rp.name AS customer,\n MAX(so.date_order) AS last_order_date\n\ | |
| FROM sale_order so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state\ | |
| \ IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rp.id, rp.name\nHAVING MAX(so.date_order) < NOW() - INTERVAL '90 days'\n\ | |
| ORDER BY last_order_date;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - churn | |
| - id: L3-030 | |
| level: 3 | |
| domains: | |
| - inventory | |
| - logistics | |
| nl: Show count of products below 10 units on-hand by warehouse. | |
| gold_sql: "WITH stock_by_wh AS (\n SELECT w.id AS warehouse_id, w.name AS warehouse,\n\ | |
| \ sq.product_id, SUM(sq.quantity) AS on_hand\n FROM stock_quant sq\n\ | |
| \ JOIN stock_location l ON l.id = sq.location_id\n JOIN stock_warehouse w ON\ | |
| \ w.view_location_id = l.location_id\n WHERE l.usage = 'internal'\n GROUP BY\ | |
| \ w.id, w.name, sq.product_id\n)\nSELECT warehouse, COUNT(*) AS low_stock_products\n\ | |
| FROM stock_by_wh\nWHERE on_hand < 10\nGROUP BY warehouse_id, warehouse\nORDER\ | |
| \ BY low_stock_products DESC;\n" | |
| tags: | |
| - cross_domain | |
| - cte | |
| - threshold | |
| - id: L4-006 | |
| level: 4 | |
| domains: | |
| - finance | |
| - demand | |
| nl: 'Show gross margin per product: revenue minus average procurement cost this | |
| year.' | |
| gold_sql: "WITH rev AS (\n SELECT sol.product_id,\n SUM(sol.price_subtotal)\ | |
| \ AS revenue,\n SUM(sol.product_uom_qty) AS units\n FROM sale_order_line\ | |
| \ sol\n JOIN sale_order so ON so.id = sol.order_id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY sol.product_id\n\ | |
| ), cost AS (\n SELECT pol.product_id, AVG(pol.price_unit) AS avg_unit_cost\n\ | |
| \ FROM purchase_order_line pol\n JOIN purchase_order po ON po.id = pol.order_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n GROUP BY pol.product_id\n)\nSELECT\ | |
| \ pt.name->>'en_US' AS product,\n rev.revenue,\n rev.units * COALESCE(c.avg_unit_cost,\ | |
| \ 0) AS estimated_cost,\n rev.revenue - rev.units * COALESCE(c.avg_unit_cost,\ | |
| \ 0) AS gross_margin\nFROM rev\nLEFT JOIN cost c ON c.product_id = rev.product_id\n\ | |
| JOIN product_product pp ON pp.id = rev.product_id\nJOIN product_template pt ON\ | |
| \ pt.id = pp.product_tmpl_id\nORDER BY gross_margin DESC NULLS LAST\nLIMIT 20;\n" | |
| tags: | |
| - federation_stub | |
| - derived_metric | |
| - cte_dual | |
| - id: L4-007 | |
| level: 4 | |
| domains: | |
| - inventory | |
| - logistics | |
| nl: Show products with both incoming purchase volume and outgoing sale volume this | |
| year. | |
| gold_sql: "WITH inflow AS (\n SELECT pol.product_id, SUM(pol.product_qty) AS purchased\n\ | |
| \ FROM purchase_order_line pol\n JOIN purchase_order po ON po.id = pol.order_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n AND po.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY pol.product_id\n), outflow AS (\n SELECT sol.product_id,\ | |
| \ SUM(sol.product_uom_qty) AS sold\n FROM sale_order_line sol\n JOIN sale_order\ | |
| \ so ON so.id = sol.order_id\n WHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\n GROUP BY sol.product_id\n)\nSELECT pt.name->>'en_US'\ | |
| \ AS product,\n i.purchased, o.sold\nFROM inflow i\nJOIN outflow o ON o.product_id\ | |
| \ = i.product_id\nJOIN product_product pp ON pp.id = i.product_id\nJOIN product_template\ | |
| \ pt ON pt.id = pp.product_tmpl_id\nORDER BY (i.purchased + o.sold) DESC NULLS\ | |
| \ LAST\nLIMIT 20;\n" | |
| tags: | |
| - federation_stub | |
| - cte_dual | |
| - id: L4-008 | |
| level: 4 | |
| domains: | |
| - demand | |
| - finance | |
| - logistics | |
| nl: 'Show full order-to-cash cycle by customer: orders, invoices, paid amount this | |
| year.' | |
| gold_sql: "WITH orders AS (\n SELECT so.partner_id, SUM(so.amount_total) AS ordered\n\ | |
| \ FROM sale_order so\n WHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\n GROUP BY so.partner_id\n), invs AS (\n SELECT\ | |
| \ am.partner_id,\n SUM(am.amount_total) AS invoiced,\n SUM(am.amount_total\ | |
| \ - COALESCE(am.amount_residual, 0)) AS paid\n FROM account_move am\n WHERE\ | |
| \ am.move_type = 'out_invoice'\n AND am.state = 'posted'\n AND am.date >=\ | |
| \ date_trunc('year', NOW())\n GROUP BY am.partner_id\n)\nSELECT rp.name AS customer,\n\ | |
| \ COALESCE(orders.ordered, 0) AS ordered,\n COALESCE(invs.invoiced,\ | |
| \ 0) AS invoiced,\n COALESCE(invs.paid, 0) AS paid\nFROM res_partner rp\n\ | |
| LEFT JOIN orders ON orders.partner_id = rp.id\nLEFT JOIN invs ON invs.partner_id\ | |
| \ = rp.id\nWHERE orders.ordered IS NOT NULL OR invs.invoiced IS NOT NULL\nORDER\ | |
| \ BY ordered DESC NULLS LAST\nLIMIT 20;\n" | |
| tags: | |
| - federation_stub | |
| - three_domain | |
| - id: L4-009 | |
| level: 4 | |
| domains: | |
| - logistics | |
| - inventory | |
| nl: 'Show supplier delivery performance: count of POs and avg quantity received | |
| per supplier this year.' | |
| gold_sql: "SELECT rp.name AS supplier,\n COUNT(DISTINCT po.id) AS po_count,\n\ | |
| \ AVG(pol.product_qty) AS avg_qty_per_line\nFROM purchase_order po\nJOIN\ | |
| \ purchase_order_line pol ON pol.order_id = po.id\nJOIN res_partner rp ON rp.id\ | |
| \ = po.partner_id\nWHERE po.state IN ('purchase','done')\n AND po.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\nHAVING COUNT(DISTINCT\ | |
| \ po.id) >= 1\nORDER BY po_count DESC;\n" | |
| tags: | |
| - federation_stub | |
| - supplier_kpi | |
| - id: L4-010 | |
| level: 4 | |
| domains: | |
| - finance | |
| - inventory | |
| nl: Show inventory value aged by how recently the valuation layer was created. | |
| gold_sql: "SELECT\n CASE\n WHEN NOW() - svl.create_date < INTERVAL '30 days'\ | |
| \ THEN '0-30d'\n WHEN NOW() - svl.create_date < INTERVAL '90 days' THEN '30-90d'\n\ | |
| \ WHEN NOW() - svl.create_date < INTERVAL '180 days' THEN '90-180d'\n ELSE\ | |
| \ '180d+'\n END AS age_bucket,\n SUM(svl.remaining_value) AS value\nFROM stock_valuation_layer\ | |
| \ svl\nWHERE svl.remaining_qty > 0\nGROUP BY 1\nORDER BY 1;\n" | |
| tags: | |
| - federation_stub | |
| - aging | |
| - case_when | |
| - id: L5-006 | |
| level: 5 | |
| domains: | |
| - inventory | |
| - logistics | |
| nl: 'Recommend products to reorder: where current on-hand is below the reorder minimum.' | |
| gold_sql: "WITH stock AS (\n SELECT product_id, SUM(quantity) AS on_hand\n FROM\ | |
| \ stock_quant GROUP BY product_id\n), rules AS (\n SELECT product_id,\n \ | |
| \ MAX(product_min_qty) AS reorder_min,\n MAX(product_max_qty) AS reorder_max\n\ | |
| \ FROM stock_warehouse_orderpoint\n GROUP BY product_id\n)\nSELECT pt.name->>'en_US'\ | |
| \ AS product,\n COALESCE(s.on_hand, 0) AS on_hand,\n r.reorder_min,\n\ | |
| \ r.reorder_max,\n r.reorder_max - COALESCE(s.on_hand, 0) AS suggested_qty\n\ | |
| FROM rules r\nJOIN product_product pp ON pp.id = r.product_id\nJOIN product_template\ | |
| \ pt ON pt.id = pp.product_tmpl_id\nLEFT JOIN stock s ON s.product_id = pp.id\n\ | |
| WHERE COALESCE(s.on_hand, 0) < r.reorder_min\nORDER BY suggested_qty DESC NULLS\ | |
| \ LAST;\n" | |
| tags: | |
| - predictive | |
| - reorder | |
| - id: L5-007 | |
| level: 5 | |
| domains: | |
| - demand | |
| - finance | |
| nl: Forecast next month's revenue from the last 3 months' moving average. | |
| gold_sql: "WITH monthly AS (\n SELECT date_trunc('month', date_order) AS month,\n\ | |
| \ SUM(amount_total) AS revenue\n FROM sale_order\n WHERE state IN ('sale','done')\n\ | |
| \ AND date_order >= NOW() - INTERVAL '3 months'\n AND date_order < date_trunc('month',\ | |
| \ NOW())\n GROUP BY 1\n)\nSELECT AVG(revenue) AS forecast_next_month\nFROM monthly;\n" | |
| tags: | |
| - predictive | |
| - moving_average | |
| - id: L5-008 | |
| level: 5 | |
| domains: | |
| - logistics | |
| - inventory | |
| nl: Identify warehouses approaching capacity (highest aggregate on-hand). | |
| gold_sql: "SELECT w.name AS warehouse,\n SUM(sq.quantity) AS total_on_hand,\n\ | |
| \ COUNT(DISTINCT sq.product_id) AS distinct_products\nFROM stock_quant sq\n\ | |
| JOIN stock_location l ON l.id = sq.location_id\nJOIN stock_warehouse w ON w.view_location_id\ | |
| \ = l.location_id\nWHERE l.usage = 'internal'\nGROUP BY w.id, w.name\nORDER BY\ | |
| \ total_on_hand DESC NULLS LAST;\n" | |
| tags: | |
| - predictive | |
| - capacity | |
| - id: L5-009 | |
| level: 5 | |
| domains: | |
| - logistics | |
| - finance | |
| nl: 'Score supplier risk: suppliers with high spend but low order count this year.' | |
| gold_sql: "SELECT rp.name AS supplier,\n SUM(po.amount_total) AS spend,\n\ | |
| \ COUNT(po.id) AS order_count,\n SUM(po.amount_total) / NULLIF(COUNT(po.id),\ | |
| \ 0) AS avg_po_size\nFROM purchase_order po\nJOIN res_partner rp ON rp.id = po.partner_id\n\ | |
| WHERE po.state IN ('purchase','done')\n AND po.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY rp.id, rp.name\nHAVING SUM(po.amount_total) > 0\nORDER BY avg_po_size\ | |
| \ DESC NULLS LAST\nLIMIT 10;\n" | |
| tags: | |
| - predictive | |
| - supplier_risk | |
| - id: L5-010 | |
| level: 5 | |
| domains: | |
| - finance | |
| - demand | |
| nl: Show top-5 products by gross margin contribution this year. | |
| gold_sql: "WITH agg AS (\n SELECT sol.product_id,\n SUM(sol.price_subtotal)\ | |
| \ AS revenue,\n SUM(sol.product_uom_qty) AS units\n FROM sale_order_line\ | |
| \ sol\n JOIN sale_order so ON so.id = sol.order_id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY sol.product_id\n\ | |
| ), cost AS (\n SELECT pol.product_id, AVG(pol.price_unit) AS avg_unit_cost\n\ | |
| \ FROM purchase_order_line pol\n JOIN purchase_order po ON po.id = pol.order_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n GROUP BY pol.product_id\n)\nSELECT\ | |
| \ pt.name->>'en_US' AS product,\n agg.revenue - agg.units * COALESCE(c.avg_unit_cost,\ | |
| \ 0) AS gross_margin\nFROM agg\nLEFT JOIN cost c ON c.product_id = agg.product_id\n\ | |
| JOIN product_product pp ON pp.id = agg.product_id\nJOIN product_template pt ON\ | |
| \ pt.id = pp.product_tmpl_id\nORDER BY gross_margin DESC NULLS LAST\nLIMIT 5;\n" | |
| tags: | |
| - predictive | |
| - ranking | |
| - margin | |
| - id: L6-006 | |
| level: 6 | |
| domains: | |
| - logistics | |
| turns: | |
| - nl: Show count of pickings by warehouse. | |
| gold_sql: 'SELECT w.name AS warehouse, COUNT(sp.id) AS picking_count | |
| FROM stock_picking sp | |
| JOIN stock_picking_type pt ON pt.id = sp.picking_type_id | |
| JOIN stock_warehouse w ON w.id = pt.warehouse_id | |
| GROUP BY w.id, w.name | |
| ORDER BY picking_count DESC; | |
| ' | |
| - nl: Only those completed. | |
| gold_sql: 'SELECT w.name AS warehouse, COUNT(sp.id) AS picking_count | |
| FROM stock_picking sp | |
| JOIN stock_picking_type pt ON pt.id = sp.picking_type_id | |
| JOIN stock_warehouse w ON w.id = pt.warehouse_id | |
| WHERE sp.state = ''done'' | |
| GROUP BY w.id, w.name | |
| ORDER BY picking_count DESC; | |
| ' | |
| - nl: And only from this month. | |
| gold_sql: "SELECT w.name AS warehouse, COUNT(sp.id) AS picking_count\nFROM stock_picking\ | |
| \ sp\nJOIN stock_picking_type pt ON pt.id = sp.picking_type_id\nJOIN stock_warehouse\ | |
| \ w ON w.id = pt.warehouse_id\nWHERE sp.state = 'done'\n AND sp.date_done >=\ | |
| \ date_trunc('month', NOW())\nGROUP BY w.id, w.name\nORDER BY picking_count\ | |
| \ DESC;\n" | |
| tags: | |
| - multi_turn | |
| - refinement_chain | |
| - id: L6-007 | |
| level: 6 | |
| domains: | |
| - inventory | |
| - demand | |
| turns: | |
| - nl: Show products grouped by category. | |
| gold_sql: "SELECT pc.complete_name AS category,\n COUNT(pt.id) AS product_count\n\ | |
| FROM product_template pt\nJOIN product_category pc ON pc.id = pt.categ_id\n\ | |
| GROUP BY pc.id, pc.complete_name\nORDER BY product_count DESC;\n" | |
| - nl: Only categories with at least 5 products. | |
| gold_sql: "SELECT pc.complete_name AS category,\n COUNT(pt.id) AS product_count\n\ | |
| FROM product_template pt\nJOIN product_category pc ON pc.id = pt.categ_id\n\ | |
| GROUP BY pc.id, pc.complete_name\nHAVING COUNT(pt.id) >= 5\nORDER BY product_count\ | |
| \ DESC;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-008 | |
| level: 6 | |
| domains: | |
| - demand | |
| - finance | |
| turns: | |
| - nl: Show top customers by revenue. | |
| gold_sql: 'SELECT rp.name AS customer, SUM(so.amount_total) AS revenue | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY rp.id, rp.name | |
| ORDER BY revenue DESC NULLS LAST; | |
| ' | |
| - nl: Only this year. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY revenue DESC NULLS LAST;\n" | |
| - nl: Top 5 only. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY revenue DESC NULLS LAST\nLIMIT 5;\n" | |
| tags: | |
| - multi_turn | |
| - refinement_chain | |
| - id: L6-009 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: List all products. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product | |
| FROM product_template pt | |
| WHERE pt.active = true | |
| ORDER BY product; | |
| ' | |
| - nl: Just storables with on-hand stock. | |
| gold_sql: "SELECT pt.name->>'en_US' AS product,\n SUM(sq.quantity) AS on_hand\n\ | |
| FROM product_template pt\nJOIN product_product pp ON pp.product_tmpl_id = pt.id\n\ | |
| JOIN stock_quant sq ON sq.product_id = pp.id\nWHERE pt.active = true\n AND\ | |
| \ pt.type = 'product'\nGROUP BY pt.name\nHAVING SUM(sq.quantity) > 0\nORDER\ | |
| \ BY on_hand DESC NULLS LAST;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-010 | |
| level: 6 | |
| domains: | |
| - finance | |
| - demand | |
| turns: | |
| - nl: Show YTD revenue by company. | |
| gold_sql: "SELECT rc.name AS company,\n SUM(so.amount_total) AS ytd_revenue\n\ | |
| FROM sale_order so\nJOIN res_company rc ON rc.id = so.company_id\nWHERE so.state\ | |
| \ IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rc.id, rc.name\nORDER BY ytd_revenue DESC NULLS LAST;\n" | |
| - nl: Compare with last year same period. | |
| gold_sql: "SELECT rc.name AS company,\n SUM(CASE WHEN so.date_order >= date_trunc('year',\ | |
| \ NOW())\n THEN so.amount_total ELSE 0 END) AS ytd_current,\n\ | |
| \ SUM(CASE WHEN so.date_order >= date_trunc('year', NOW()) - INTERVAL\ | |
| \ '1 year'\n AND so.date_order < date_trunc('year', NOW())\n\ | |
| \ THEN so.amount_total ELSE 0 END) AS ytd_prior\nFROM sale_order\ | |
| \ so\nJOIN res_company rc ON rc.id = so.company_id\nWHERE so.state IN ('sale','done')\n\ | |
| GROUP BY rc.id, rc.name\nORDER BY ytd_current DESC NULLS LAST;\n" | |
| tags: | |
| - multi_turn | |
| - comparison | |
| - yoy | |
| - id: L1-021 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many accounts are there in the system? | |
| gold_sql: 'SELECT COUNT(*) AS total_accounts FROM account_account; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-022 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: What are the names of all the partners? | |
| gold_sql: 'SELECT name FROM res_partner ORDER BY name; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-023 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many journal entries are associated with each company? | |
| gold_sql: 'SELECT company_id, COUNT(*) AS journal_entry_count FROM account_move | |
| GROUP BY company_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group | |
| - id: L1-024 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List all the journals and their types. | |
| gold_sql: 'SELECT id, type FROM account_journal ORDER BY id; | |
| ' | |
| tags: | |
| - listing | |
| - id: L2-021 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Show payment details for invoices with their partners. | |
| gold_sql: 'SELECT am.id AS invoice_id, rp.name AS partner, am.payment_state | |
| FROM account_move am | |
| JOIN res_partner rp ON rp.id = am.partner_id | |
| WHERE am.move_type = ''out_invoice'' AND am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-022 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List journal entries along with their account types. | |
| gold_sql: 'SELECT am.id AS entry_id, aa.name AS account_name, aa.account_type | |
| FROM account_move am | |
| JOIN account_move_line aml ON aml.move_id = am.id | |
| JOIN account_account aa ON aa.id = aml.account_id | |
| WHERE am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-023 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Retrieve the total amounts of invoices grouped by company. | |
| gold_sql: 'SELECT rc.name AS company, SUM(am.amount_total) AS total_invoiced | |
| FROM account_move am | |
| JOIN res_company rc ON rc.id = am.company_id | |
| WHERE am.move_type = ''out_invoice'' AND am.state = ''posted'' | |
| GROUP BY rc.name | |
| ORDER BY total_invoiced DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-024 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List invoices with their journal types and states. | |
| gold_sql: 'SELECT am.id AS invoice_id, aj.type AS journal_type, am.state | |
| FROM account_move am | |
| JOIN account_journal aj ON aj.id = am.journal_id | |
| WHERE am.move_type = ''out_invoice'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L3-031 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show the total quantity of products available for sale by warehouse, including | |
| both on-hand and reserved quantities. | |
| gold_sql: 'SELECT w.name AS warehouse, SUM(sq.quantity + sq.reserved_quantity) AS | |
| total_available | |
| FROM stock_quant sq | |
| JOIN stock_location l ON l.id = sq.location_id | |
| JOIN stock_warehouse w ON w.view_location_id = l.location_id | |
| GROUP BY w.name | |
| ORDER BY total_available DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregation | |
| - warehouse | |
| - id: L3-032 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Count the number of unique products that have been moved to a specific warehouse | |
| this quarter. | |
| gold_sql: "SELECT COUNT(DISTINCT sm.product_id) AS unique_product_count\nFROM stock_move\ | |
| \ sm\nJOIN stock_warehouse w ON w.id = sm.warehouse_id\nWHERE sm.state = 'done'\n\ | |
| \ AND sm.date >= date_trunc('quarter', NOW())\n AND w.id = (SELECT id FROM stock_warehouse\ | |
| \ WHERE name = 'Main Warehouse')\n;\n" | |
| tags: | |
| - inventory | |
| - temporal | |
| - aggregation | |
| - id: L1-025 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: What is the average price of products sold in sale orders? | |
| gold_sql: 'SELECT COALESCE(AVG(price_unit), 0) AS average_price | |
| FROM sale_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - average | |
| - id: L1-026 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders were created in the last month? | |
| gold_sql: 'SELECT COUNT(*) AS orders_last_month | |
| FROM sale_order | |
| WHERE create_date >= date_trunc(''month'', NOW() - interval ''1 month''); | |
| ' | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L1-027 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: List the total number of products sold in each sale order. | |
| gold_sql: 'SELECT order_id, SUM(product_uom_qty) AS total_products_sold | |
| FROM sale_order_line | |
| GROUP BY order_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group_by | |
| - id: L1-028 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: What is the maximum quantity of a single product sold in a sale order line? | |
| gold_sql: 'SELECT COALESCE(MAX(product_uom_qty), 0) AS max_quantity_sold | |
| FROM sale_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - max | |
| - id: L1-029 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the total number of purchase orders. | |
| gold_sql: 'SELECT COUNT(*) AS total_purchase_orders | |
| FROM purchase_order; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-030 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: List all stock pickings and their states. | |
| gold_sql: 'SELECT id, name, state | |
| FROM stock_picking | |
| ORDER BY id; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-031 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many purchase orders are in draft state? | |
| gold_sql: 'SELECT COUNT(*) AS draft_purchase_orders | |
| FROM purchase_order | |
| WHERE state = ''draft''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-032 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: List all stock moves with a specific product ID. | |
| gold_sql: 'SELECT id, product_id, state | |
| FROM stock_move | |
| WHERE product_id IS NOT NULL; | |
| ' | |
| tags: | |
| - listing | |
| - filter | |
| - id: L2-025 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Show the total quantity of products sold by each product category. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sol.product_uom_qty) AS total_quantity | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-026 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List each product and the total number sold across all orders. | |
| gold_sql: 'SELECT pp.default_code AS product_code, SUM(sol.product_uom_qty) AS total_sold | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN sale_order so ON so.id = sol.order_id | |
| WHERE so.state IN (''sale'', ''done'') | |
| GROUP BY pp.id, pp.default_code | |
| ORDER BY total_sold DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-027 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Calculate the average price of sold products for each customer. | |
| gold_sql: 'SELECT rp.name AS customer, AVG(sol.price_unit) AS average_price | |
| FROM sale_order_line sol | |
| JOIN sale_order so ON so.id = sol.order_id | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.state IN (''sale'', ''done'') | |
| GROUP BY rp.id, rp.name | |
| ORDER BY average_price DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-028 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Find the total revenue for each sales team from completed orders. | |
| gold_sql: 'SELECT ct.name AS sales_team, SUM(so.amount_total) AS total_revenue | |
| FROM sale_order so | |
| JOIN crm_team ct ON ct.id = so.team_id | |
| WHERE so.state IN (''sale'', ''done'') | |
| GROUP BY ct.id, ct.name | |
| ORDER BY total_revenue DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-029 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show purchase orders with their invoice count and partner names. | |
| gold_sql: 'SELECT po.id, po.name, po.invoice_count, rp.name AS partner_name | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-030 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: List stock moves with their picking names and quantities. | |
| gold_sql: 'SELECT sm.id, sm.sequence, sp.name AS picking_name, sm.product_qty | |
| FROM stock_move sm | |
| JOIN stock_picking sp ON sp.id = sm.picking_id | |
| ORDER BY sm.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L1-033 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: How many products are currently in stock? | |
| gold_sql: 'SELECT COUNT(*) AS total_products FROM stock_quant WHERE quantity > 0; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-034 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the total reserved quantity for all products? | |
| gold_sql: 'SELECT SUM(reserved_quantity) AS total_reserved FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - sum | |
| - id: L1-035 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: Show the total inventory quantity for each product. | |
| gold_sql: 'SELECT product_id, SUM(inventory_quantity) AS total_inventory FROM stock_quant | |
| GROUP BY product_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group | |
| - id: L2-031 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show each location with the total quantity of products stored. | |
| gold_sql: 'SELECT l.name AS location, COALESCE(SUM(sq.quantity), 0) AS total_quantity | |
| FROM stock_location l | |
| LEFT JOIN stock_quant sq ON sq.location_id = l.id | |
| GROUP BY l.id, l.name | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-032 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Display each warehouse along with the count of stock moves. | |
| gold_sql: 'SELECT w.name AS warehouse, COUNT(sm.id) AS stock_move_count | |
| FROM stock_warehouse w | |
| LEFT JOIN stock_move sm ON sm.warehouse_id = w.id | |
| GROUP BY w.id, w.name | |
| ORDER BY stock_move_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-033 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show products and the count of their associated stock picking entries. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, COUNT(sp.id) AS picking_count | |
| FROM product_product pp | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| LEFT JOIN stock_move sm ON sm.product_id = pp.id | |
| LEFT JOIN stock_picking sp ON sp.id = sm.picking_id | |
| GROUP BY pp.id, pt.name | |
| ORDER BY picking_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L3-033 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List the total quantity available for each product along with their respective | |
| storage locations. | |
| gold_sql: 'SELECT pp.default_code AS product_code, l.name AS location_name, SUM(sq.quantity) | |
| AS total_quantity | |
| FROM stock_quant sq | |
| JOIN stock_location l ON l.id = sq.location_id | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| GROUP BY pp.default_code, l.name | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-034 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show the total reserved quantity of products by warehouse. | |
| gold_sql: 'SELECT w.name AS warehouse, SUM(sq.reserved_quantity) AS total_reserved | |
| FROM stock_quant sq | |
| JOIN stock_location l ON l.id = sq.location_id | |
| JOIN stock_warehouse w ON w.view_location_id = l.location_id | |
| GROUP BY w.name | |
| ORDER BY total_reserved DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - group_by_two | |
| - id: L3-035 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the quantity differences for products in inventory across different locations. | |
| gold_sql: 'SELECT pp.default_code AS product_code, l.name AS location_name, SUM(sq.inventory_diff_quantity) | |
| AS quantity_difference | |
| FROM stock_quant sq | |
| JOIN stock_location l ON l.id = sq.location_id | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| GROUP BY pp.default_code, l.name | |
| HAVING SUM(sq.inventory_diff_quantity) != 0 | |
| ORDER BY quantity_difference DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-036 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Retrieve the product quantities that have been recorded recently by their inventory | |
| date. | |
| gold_sql: 'SELECT pp.default_code AS product_code, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| WHERE sq.inventory_date >= CURRENT_DATE - INTERVAL ''30 days'' | |
| GROUP BY pp.default_code | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-037 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Get the total number of purchase orders and average price subtotal for each | |
| product this year. | |
| gold_sql: "SELECT pp.default_code AS product_code, COUNT(po.id) AS total_orders,\ | |
| \ AVG(pol.price_subtotal) AS average_price\nFROM purchase_order po\nJOIN purchase_order_line\ | |
| \ pol ON po.id = pol.order_id\nJOIN product_product pp ON pol.product_id = pp.id\n\ | |
| WHERE po.state IN ('purchase', 'done')\n AND po.create_date >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pp.default_code;\n" | |
| tags: | |
| - logistics | |
| - aggregation | |
| - id: L3-038 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Identify the products with the highest total ordered quantity across all purchase | |
| orders this year. | |
| gold_sql: "SELECT pp.default_code AS product_code, SUM(pol.product_qty) AS total_ordered\n\ | |
| FROM purchase_order po\nJOIN purchase_order_line pol ON po.id = pol.order_id\n\ | |
| JOIN product_product pp ON pol.product_id = pp.id\nWHERE po.state IN ('purchase',\ | |
| \ 'done')\n AND po.create_date >= date_trunc('year', NOW())\nGROUP BY pp.default_code\n\ | |
| ORDER BY total_ordered DESC;\n" | |
| tags: | |
| - logistics | |
| - ranking | |
| - id: L2-034 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Display stock moves with their corresponding product names and quantities. | |
| gold_sql: 'SELECT sm.id, pp.default_code AS product_code, sm.product_qty | |
| FROM stock_move sm | |
| JOIN product_product pp ON pp.id = sm.product_id | |
| ORDER BY sm.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-035 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Get purchase orders and the names of the partners associated with them. | |
| gold_sql: 'SELECT po.id, po.name AS purchase_order_name, rp.name AS partner_name | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-036 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show purchase order lines with their respective product unit of measure and | |
| prices. | |
| gold_sql: 'SELECT pol.id, pol.product_qty, pol.price_unit, pu.name AS product_uom | |
| FROM purchase_order_line pol | |
| JOIN product_product pp ON pp.id = pol.product_id | |
| JOIN uom_uom pu ON pu.id = pol.product_uom | |
| ORDER BY pol.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L1-036 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List all account types available in the system. | |
| gold_sql: 'SELECT DISTINCT account_type FROM account_account; | |
| ' | |
| tags: | |
| - listing | |
| - distinct | |
| - id: L1-037 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: Count the number of payment entries in the account_move table. | |
| gold_sql: 'SELECT COUNT(*) AS payment_count | |
| FROM account_move | |
| WHERE payment_id IS NOT NULL; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-038 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List the names of all partners with a valid VAT number. | |
| gold_sql: 'SELECT name FROM res_partner WHERE vat IS NOT NULL AND vat <> ''''; | |
| ' | |
| tags: | |
| - listing | |
| - filter | |
| - id: L2-037 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Show journal entries along with their associated partners. | |
| gold_sql: 'SELECT am.id, rp.name AS partner_name | |
| FROM account_move am | |
| JOIN res_partner rp ON rp.id = am.partner_id | |
| WHERE am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-038 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List all journal entries with their corresponding account types. | |
| gold_sql: 'SELECT am.id, aa.account_type | |
| FROM account_move am | |
| JOIN account_move_line aml ON aml.move_id = am.id | |
| JOIN account_account aa ON aa.id = aml.account_id | |
| WHERE am.state = ''posted'' | |
| GROUP BY am.id, aa.account_type | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-039 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Retrieve invoices with their journal types and amounts. | |
| gold_sql: 'SELECT am.id, aj.type AS journal_type, am.amount_total | |
| FROM account_move am | |
| JOIN account_journal aj ON aj.id = am.journal_id | |
| WHERE am.move_type = ''out_invoice'' AND am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-040 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List invoice amounts grouped by their company names. | |
| gold_sql: 'SELECT rc.name AS company_name, SUM(am.amount_total) AS total_amount | |
| FROM account_move am | |
| JOIN res_company rc ON rc.id = am.company_id | |
| WHERE am.move_type = ''out_invoice'' AND am.state = ''posted'' | |
| GROUP BY rc.name | |
| ORDER BY total_amount DESC; | |
| ' | |
| tags: | |
| - join | |
| - group by | |
| - id: L3-039 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Show the total quantity of products ordered by each supplier this year. | |
| gold_sql: 'SELECT rp.name AS supplier_name, SUM(pol.product_qty) AS total_ordered | |
| FROM purchase_order_line pol | |
| JOIN purchase_order po ON po.id = pol.order_id | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| WHERE po.create_date >= date_trunc(''year'', NOW()) | |
| GROUP BY rp.name; | |
| ' | |
| tags: | |
| - logistics | |
| - temporal | |
| - group_by | |
| - id: L1-039 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders were created in the last month? | |
| gold_sql: 'SELECT COUNT(*) AS orders_last_month | |
| FROM sale_order | |
| WHERE create_date >= NOW() - INTERVAL ''1 month''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-040 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders are associated with each campaign? | |
| gold_sql: 'SELECT campaign_id, COUNT(*) AS campaign_orders | |
| FROM sale_order | |
| GROUP BY campaign_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group by | |
| - id: L1-041 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the total reserved quantity for all products in stock? | |
| gold_sql: 'SELECT SUM(reserved_quantity) AS total_reserved_quantity FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - sum | |
| - id: L1-042 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the maximum inventory quantity recorded for any product? | |
| gold_sql: 'SELECT MAX(inventory_quantity) AS max_inventory_quantity FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - max | |
| - id: L1-043 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: List all products with their default codes. | |
| gold_sql: 'SELECT id, default_code FROM product_product ORDER BY default_code; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-044 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the number of purchase orders associated with each partner. | |
| gold_sql: 'SELECT partner_id, COUNT(*) AS order_count | |
| FROM purchase_order | |
| GROUP BY partner_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group | |
| - id: L1-045 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: List all purchase orders with their corresponding invoice counts. | |
| gold_sql: 'SELECT id, name, invoice_count | |
| FROM purchase_order | |
| ORDER BY id; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-046 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many purchase orders are currently in a done state? | |
| gold_sql: 'SELECT COUNT(*) AS done_pos | |
| FROM purchase_order | |
| WHERE state = ''done''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-047 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the total number of purchase orders in each state. | |
| gold_sql: 'SELECT state, COUNT(*) AS total_orders | |
| FROM purchase_order | |
| GROUP BY state; | |
| ' | |
| tags: | |
| - aggregate | |
| - group | |
| - id: L2-041 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Show the total quantity of products sold per customer. | |
| gold_sql: 'SELECT rp.name AS customer, SUM(sol.product_uom_qty) AS total_quantity | |
| FROM sale_order so | |
| JOIN sale_order_line sol ON sol.order_id = so.id | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY rp.id, rp.name | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-042 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Count the number of sale orders for each product category. | |
| gold_sql: 'SELECT pc.name AS category, COUNT(so.id) AS order_count | |
| FROM sale_order so | |
| JOIN sale_order_line sol ON sol.order_id = so.id | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY pc.id, pc.name | |
| ORDER BY order_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-043 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List sale orders along with the total price of their lines. | |
| gold_sql: 'SELECT so.id, so.name, SUM(sol.price_unit * sol.product_uom_qty) AS total_price | |
| FROM sale_order so | |
| JOIN sale_order_line sol ON sol.order_id = so.id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY so.id, so.name | |
| ORDER BY total_price DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-044 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: List all product categories with their total quantity in stock. | |
| gold_sql: 'SELECT pt.categ_id, SUM(sq.quantity) AS total_quantity | |
| FROM product_product pp | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| LEFT JOIN stock_quant sq ON sq.product_id = pp.id | |
| GROUP BY pt.categ_id | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-045 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show each warehouse and the total number of stock moves. | |
| gold_sql: 'SELECT w.id AS warehouse_id, COUNT(sm.id) AS total_moves | |
| FROM stock_warehouse w | |
| LEFT JOIN stock_move sm ON sm.warehouse_id = w.id | |
| GROUP BY w.id | |
| ORDER BY total_moves DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-046 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Display all products along with their reserved quantities. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, COALESCE(SUM(sq.reserved_quantity), | |
| 0) AS reserved_qty | |
| FROM product_product pp | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| LEFT JOIN stock_quant sq ON sq.product_id = pp.id | |
| GROUP BY pp.id, pt.name | |
| ORDER BY reserved_qty DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-047 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show the number of stock moves for each product in the inventory. | |
| gold_sql: 'SELECT pp.id AS product_id, COUNT(sm.id) AS move_count | |
| FROM product_product pp | |
| LEFT JOIN stock_move sm ON sm.product_id = pp.id | |
| GROUP BY pp.id | |
| ORDER BY move_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L3-040 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: List each product and the total quantity ordered across all purchase orders. | |
| gold_sql: 'SELECT pp.id AS product_id, SUM(pol.product_qty) AS total_ordered | |
| FROM purchase_order_line pol | |
| JOIN product_product pp ON pp.id = pol.product_id | |
| GROUP BY pp.id | |
| ORDER BY total_ordered DESC; | |
| ' | |
| tags: | |
| - aggregation | |
| - products | |
| - id: L3-041 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Find the total number of purchase orders and their states grouped by partner. | |
| gold_sql: 'SELECT rp.name AS partner_name, COUNT(po.id) AS order_count, po.state | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| GROUP BY rp.name, po.state | |
| ORDER BY order_count DESC; | |
| ' | |
| tags: | |
| - aggregation | |
| - partners | |
| - id: L3-042 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Show total quantity received by each product from purchase orders. | |
| gold_sql: 'SELECT pp.id AS product_id, SUM(pol.product_qty) AS total_received | |
| FROM purchase_order_line pol | |
| JOIN product_product pp ON pp.id = pol.product_id | |
| JOIN purchase_order po ON po.id = pol.order_id | |
| WHERE po.state IN (''purchase'', ''done'') | |
| GROUP BY pp.id | |
| ORDER BY total_received DESC; | |
| ' | |
| tags: | |
| - aggregation | |
| - products | |
| - id: L2-048 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Count the number of purchase orders per partner. | |
| gold_sql: 'SELECT rp.name AS partner_name, COUNT(po.id) AS order_count | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| GROUP BY rp.id, rp.name | |
| ORDER BY order_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-049 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show purchase orders along with their invoice count. | |
| gold_sql: 'SELECT po.id, po.name, po.invoice_count | |
| FROM purchase_order po | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - single_table | |
| - details | |
| - id: L2-050 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Count the number of stock moves per product. | |
| gold_sql: 'SELECT pp.default_code AS product_code, COUNT(sm.id) AS move_count | |
| FROM stock_move sm | |
| JOIN product_product pp ON pp.id = sm.product_id | |
| GROUP BY pp.id, pp.default_code | |
| ORDER BY move_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L3-043 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Find the total payments received from each customer in the last quarter. | |
| gold_sql: "SELECT rp.name AS customer_name,\n SUM(aml.credit) AS total_payments\n\ | |
| FROM account_move_line aml\nJOIN account_move am ON am.id = aml.move_id\nJOIN\ | |
| \ res_partner rp ON rp.id = am.partner_id\nWHERE am.move_type = 'out_invoice'\n\ | |
| \ AND am.state = 'posted'\n AND aml.date >= date_trunc('quarter', NOW()) - INTERVAL\ | |
| \ '3 months'\n AND aml.date < date_trunc('quarter', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY total_payments DESC;\n" | |
| tags: | |
| - aggregate | |
| - quarterly | |
| - payments | |
| - id: L3-044 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Get the average invoice amount for each customer this year. | |
| gold_sql: "SELECT rp.name AS customer_name,\n AVG(am.amount_total) AS average_invoice\n\ | |
| FROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\n AND am.date >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY rp.id, rp.name\nORDER BY average_invoice DESC;\n" | |
| tags: | |
| - aggregate | |
| - average | |
| - yearly | |
| - id: L3-045 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Show the total number of invoices by currency for this year. | |
| gold_sql: "SELECT rc.name AS currency_name,\n COUNT(am.id) AS total_invoices\n\ | |
| FROM account_move am\nJOIN res_currency rc ON rc.id = am.currency_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\n AND am.date >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY rc.id, rc.name\nORDER BY total_invoices DESC;\n" | |
| tags: | |
| - aggregate | |
| - currency | |
| - yearly | |
| - id: L3-046 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of products in stock grouped by warehouse. | |
| gold_sql: 'SELECT w.id AS warehouse_id, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN stock_location l ON l.id = sq.location_id | |
| JOIN stock_warehouse w ON w.view_location_id = l.location_id | |
| GROUP BY w.id | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-047 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show the average quantity of stock moves per product across all warehouses. | |
| gold_sql: 'SELECT sm.product_id, AVG(sm.quantity) AS average_quantity | |
| FROM stock_move sm | |
| JOIN stock_quant sq ON sm.product_id = sq.product_id | |
| GROUP BY sm.product_id; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L1-048 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders are there in total? | |
| gold_sql: 'SELECT COUNT(*) AS total_sale_orders | |
| FROM sale_order; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-049 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: Count the number of sale orders for each company. | |
| gold_sql: 'SELECT company_id, COUNT(*) AS order_count | |
| FROM sale_order | |
| GROUP BY company_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group | |
| - id: L1-050 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: Count the number of accounts with a specific account type. | |
| gold_sql: 'SELECT COUNT(*) AS account_count | |
| FROM account_account | |
| WHERE account_type = ''expense''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-051 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List all partners with their IDs and names. | |
| gold_sql: 'SELECT id, name FROM res_partner ORDER BY name; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-052 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many journals are there in the system? | |
| gold_sql: 'SELECT COUNT(*) AS journal_count | |
| FROM account_journal; | |
| ' | |
| tags: | |
| - aggregate | |
| - id: L1-053 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List the names of all companies. | |
| gold_sql: 'SELECT name FROM res_company ORDER BY name; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-054 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: How many stock moves have been recorded? | |
| gold_sql: 'SELECT COUNT(*) AS total_stock_moves FROM stock_move; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-055 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the maximum quantity of any product in stock? | |
| gold_sql: 'SELECT MAX(quantity) AS max_quantity FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - max | |
| - id: L1-056 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: How many stock locations are there? | |
| gold_sql: 'SELECT COUNT(*) AS total_locations FROM stock_location; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L2-051 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Show the total quantity of products sold per customer. | |
| gold_sql: 'SELECT rp.name AS customer, SUM(sol.product_uom_qty) AS total_quantity | |
| FROM sale_order_line sol | |
| JOIN sale_order so ON so.id = sol.order_id | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY rp.id, rp.name | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-052 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Get the number of sale orders per sales team. | |
| gold_sql: 'SELECT ct.name AS sales_team, COUNT(so.id) AS order_count | |
| FROM sale_order so | |
| JOIN crm_team ct ON ct.id = so.team_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY ct.id, ct.name | |
| ORDER BY order_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-053 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Display the total revenue generated from each product category. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sol.price_unit * sol.product_uom_qty) | |
| AS total_revenue | |
| FROM sale_order_line sol | |
| JOIN sale_order so ON so.id = sol.order_id | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_revenue DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-054 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List all account moves along with their associated journals and amounts. | |
| gold_sql: 'SELECT am.id, am.amount_total, aj.name AS journal_name | |
| FROM account_move am | |
| JOIN account_journal aj ON aj.id = am.journal_id | |
| WHERE am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-055 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Retrieve the total amount of account moves grouped by company. | |
| gold_sql: 'SELECT rc.name AS company, SUM(am.amount_total) AS total_amount | |
| FROM account_move am | |
| JOIN res_company rc ON rc.id = am.company_id | |
| WHERE am.state = ''posted'' | |
| GROUP BY rc.name | |
| ORDER BY total_amount DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-056 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Show the number of entries in each journal along with the journal names. | |
| gold_sql: 'SELECT aj.name AS journal_name, COUNT(am.id) AS entry_count | |
| FROM account_move am | |
| JOIN account_journal aj ON aj.id = am.journal_id | |
| WHERE am.state = ''posted'' | |
| GROUP BY aj.name | |
| ORDER BY entry_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-057 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Display account moves with their corresponding partners and payment states. | |
| gold_sql: 'SELECT am.id, rp.name AS partner_name, am.payment_state | |
| FROM account_move am | |
| JOIN res_partner rp ON rp.id = am.partner_id | |
| WHERE am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L3-048 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Find the average price of products sold in the last quarter. | |
| gold_sql: "SELECT AVG(sol.price_unit) AS average_price\nFROM sale_order_line sol\n\ | |
| JOIN sale_order so ON so.id = sol.order_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('quarter', NOW()) - INTERVAL '3 months'\n \ | |
| \ AND so.date_order < date_trunc('quarter', NOW());\n" | |
| tags: | |
| - demand | |
| - sales | |
| - average | |
| - id: L3-049 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: List the top 5 customers by total spending in the last year. | |
| gold_sql: "SELECT rp.id, rp.name AS customer_name, SUM(so.amount_total) AS total_spending\n\ | |
| FROM sale_order so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state\ | |
| \ IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW()) - INTERVAL\ | |
| \ '1 year'\nGROUP BY rp.id, rp.name\nORDER BY total_spending DESC\nLIMIT 5;\n" | |
| tags: | |
| - demand | |
| - customers | |
| - top_spenders | |
| - id: L3-050 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List products with total reserved quantity greater than 5, along with their | |
| inventory quantities. | |
| gold_sql: "WITH reserved AS (\n SELECT product_id, SUM(reserved_quantity) AS total_reserved\n\ | |
| \ FROM stock_quant\n GROUP BY product_id\n HAVING SUM(reserved_quantity) >\ | |
| \ 5\n) \nSELECT pp.id AS product_id, pp.default_code, sq.inventory_quantity\n\ | |
| FROM reserved r\nJOIN stock_quant sq ON sq.product_id = r.product_id\nJOIN product_product\ | |
| \ pp ON pp.id = r.product_id;\n" | |
| tags: | |
| - inventory | |
| - aggregate | |
| - cte | |
| - id: L3-051 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show the average quantity of products in stock, grouped by product ID. | |
| gold_sql: 'SELECT product_id, AVG(quantity) AS average_quantity | |
| FROM stock_quant | |
| GROUP BY product_id; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-052 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Retrieve products that have been moved to a specific location along with their | |
| move details. | |
| gold_sql: 'SELECT pp.id AS product_id, pp.default_code, sm.location_dest_id, COUNT(sm.id) | |
| AS move_count | |
| FROM stock_move sm | |
| JOIN product_product pp ON pp.id = sm.product_id | |
| WHERE sm.location_dest_id IS NOT NULL | |
| GROUP BY pp.id, pp.default_code, sm.location_dest_id; | |
| ' | |
| tags: | |
| - inventory | |
| - join | |
| - aggregate | |
| - id: L3-053 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: List the total quantity of products received from each supplier this year. | |
| gold_sql: "SELECT rp.name AS supplier_name, SUM(pol.product_qty) AS total_quantity_received\n\ | |
| FROM purchase_order_line pol\nJOIN purchase_order po ON po.id = pol.order_id\n\ | |
| JOIN res_partner rp ON rp.id = po.partner_id\nWHERE po.state IN ('purchase', 'done')\n\ | |
| \ AND po.date_order >= date_trunc('year', NOW())\nGROUP BY rp.name;\n" | |
| tags: | |
| - logistics | |
| - group_by_supplier | |
| - id: L3-054 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Retrieve the highest priced purchase order line for each product. | |
| gold_sql: 'SELECT pol.product_id, MAX(pol.price_unit) AS max_price | |
| FROM purchase_order_line pol | |
| GROUP BY pol.product_id; | |
| ' | |
| tags: | |
| - logistics | |
| - max_price | |
| - id: L1-057 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: What is the total quantity of products sold? | |
| gold_sql: 'SELECT SUM(product_uom_qty) AS total_quantity | |
| FROM sale_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - sum | |
| - id: L1-058 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many orders have been delivered? | |
| gold_sql: 'SELECT COUNT(*) AS delivered_orders | |
| FROM sale_order_line | |
| WHERE qty_delivered_method = ''delivered''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-059 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: What is the average price of products in sale orders? | |
| gold_sql: 'SELECT AVG(price_unit) AS average_price | |
| FROM sale_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - average | |
| - id: L1-060 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the number of purchase orders with invoices. | |
| gold_sql: 'SELECT COUNT(*) AS orders_with_invoices | |
| FROM purchase_order | |
| WHERE invoice_count > 0; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-061 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many stock pickings are in the done state? | |
| gold_sql: 'SELECT COUNT(*) AS done_pickings | |
| FROM stock_picking | |
| WHERE state = ''done''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-062 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the total number of purchase order lines. | |
| gold_sql: 'SELECT COUNT(*) AS total_order_lines | |
| FROM purchase_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-063 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many products are listed in stock moves? | |
| gold_sql: 'SELECT COUNT(DISTINCT product_id) AS unique_products_in_moves | |
| FROM stock_move; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L2-058 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Get the number of stock moves by warehouse and product. | |
| gold_sql: 'SELECT sw.id AS warehouse_id, sm.product_id, COUNT(sm.id) AS move_count | |
| FROM stock_move sm | |
| JOIN stock_warehouse sw ON sw.id = sm.warehouse_id | |
| GROUP BY sw.id, sm.product_id | |
| ORDER BY warehouse_id, move_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-059 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show the total reserved quantity for each product in stock. | |
| gold_sql: 'SELECT sm.product_id, SUM(sq.reserved_quantity) AS total_reserved | |
| FROM stock_quant sq | |
| JOIN stock_move sm ON sm.product_id = sq.product_id | |
| GROUP BY sm.product_id | |
| ORDER BY total_reserved DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-060 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Display the quantity of products in stock by location. | |
| gold_sql: 'SELECT sl.name, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| GROUP BY sl.name | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-061 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Count the number of stock moves per product. | |
| gold_sql: 'SELECT pp.id AS product_id, COUNT(sm.id) AS move_count | |
| FROM stock_move sm | |
| JOIN product_product pp ON pp.id = sm.product_id | |
| GROUP BY pp.id | |
| ORDER BY move_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-062 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show purchase orders with their invoice count. | |
| gold_sql: 'SELECT po.id, po.name, po.invoice_count | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-063 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: List stock pickings along with their destination. | |
| gold_sql: 'SELECT sp.id, sp.name, loc_dest.name AS destination | |
| FROM stock_picking sp | |
| JOIN stock_location loc_dest ON loc_dest.id = sp.location_dest_id | |
| ORDER BY sp.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-064 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Count purchase order lines by product. | |
| gold_sql: 'SELECT pl.product_id, COUNT(pl.id) AS line_count | |
| FROM purchase_order_line pl | |
| JOIN purchase_order po ON po.id = pl.order_id | |
| GROUP BY pl.product_id | |
| ORDER BY line_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L3-055 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: List all accounts with their total number of journal entries. | |
| gold_sql: 'SELECT aa.id, aa.name, COUNT(aml.id) AS total_entries | |
| FROM account_account aa | |
| LEFT JOIN account_move_line aml ON aml.account_id = aa.id | |
| GROUP BY aa.id, aa.name | |
| ORDER BY total_entries DESC; | |
| ' | |
| tags: | |
| - accounting | |
| - aggregate | |
| - id: L3-056 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Count the number of unique partners who made purchases in the last year, grouped | |
| by month. | |
| gold_sql: "SELECT DATE_TRUNC('month', so.date_order) AS month, COUNT(DISTINCT so.partner_id)\ | |
| \ AS unique_partners\nFROM sale_order so\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY month\nORDER BY month;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - grouping | |
| - id: L3-057 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Show the total quantity sold per product for the current year, including products | |
| with zero sales. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, COALESCE(SUM(sol.product_uom_qty), | |
| 0) AS total_quantity_sold | |
| FROM product_product pp | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| LEFT JOIN sale_order_line sol ON sol.product_id = pp.id | |
| LEFT JOIN sale_order so ON so.id = sol.order_id AND so.state IN (''sale'',''done'') | |
| WHERE (so.date_order IS NULL OR so.date_order >= date_trunc(''year'', NOW())) | |
| GROUP BY pt.name->>''en_US''; | |
| ' | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - aggregation | |
| - id: L3-058 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Show the total amount invoiced by each customer this year. | |
| gold_sql: "SELECT rp.name AS customer,\n SUM(am.amount_total) AS total_invoiced\n\ | |
| FROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\n AND am.date >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY rp.id, rp.name\nORDER BY total_invoiced DESC;\n" | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L3-059 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Which products have not been sold this year and how many are in stock? | |
| gold_sql: "SELECT pp.default_code AS product_code,\n SUM(sm.product_qty) AS\ | |
| \ stock_quantity\nFROM product_product pp\nLEFT JOIN stock_move sm ON sm.product_id\ | |
| \ = pp.id\nWHERE pp.id NOT IN (\n SELECT DISTINCT pol.product_id\n FROM purchase_order_line\ | |
| \ pol\n JOIN purchase_order po ON po.id = pol.order_id\n WHERE po.create_date\ | |
| \ >= date_trunc('year', NOW())\n)\nGROUP BY pp.default_code;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - anti_join | |
| - id: L5-011 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Analyze the average price per product for orders placed last quarter, grouped | |
| by supplier. | |
| gold_sql: "WITH order_prices AS (\n SELECT po.partner_id, pol.product_id, AVG(pol.price_subtotal\ | |
| \ / NULLIF(pol.product_qty, 0)) AS avg_price\n FROM purchase_order po\n JOIN\ | |
| \ purchase_order_line pol ON pol.order_id = po.id\n WHERE po.state IN ('purchase',\ | |
| \ 'done')\n AND po.date_order >= date_trunc('quarter', NOW()) - interval '3\ | |
| \ months'\n AND po.date_order < date_trunc('quarter', NOW())\n GROUP BY po.partner_id,\ | |
| \ pol.product_id\n)\nSELECT rp.name AS supplier,\n op.product_id,\n \ | |
| \ op.avg_price\nFROM order_prices op\nJOIN res_partner rp ON rp.id = op.partner_id\n\ | |
| ORDER BY supplier, product_id;\n" | |
| tags: | |
| - analysis | |
| - pricing | |
| - id: L5-012 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Identify suppliers with the highest order value and the least number of distinct | |
| products ordered in the last quarter. | |
| gold_sql: "WITH supplier_orders AS (\n SELECT po.partner_id,\n SUM(pol.price_subtotal)\ | |
| \ AS total_order_value,\n COUNT(DISTINCT pol.product_id) AS distinct_products\n\ | |
| \ FROM purchase_order po\n JOIN purchase_order_line pol ON pol.order_id = po.id\n\ | |
| \ WHERE po.state IN ('purchase', 'done')\n AND po.date_order >= date_trunc('quarter',\ | |
| \ NOW()) - interval '3 months'\n AND po.date_order < date_trunc('quarter',\ | |
| \ NOW())\n GROUP BY po.partner_id\n)\nSELECT rp.name AS supplier,\n so.total_order_value,\n\ | |
| \ so.distinct_products\nFROM supplier_orders so\nJOIN res_partner rp ON\ | |
| \ rp.id = so.partner_id\nORDER BY total_order_value DESC, distinct_products ASC;\n" | |
| tags: | |
| - analysis | |
| - supplier_performance | |
| - id: L1-064 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many journal entries are associated with a specific company? | |
| gold_sql: 'SELECT COUNT(*) AS company_journal_entries | |
| FROM account_move | |
| WHERE company_id IS NOT NULL; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-065 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many distinct partners are associated with journal entries? | |
| gold_sql: 'SELECT COUNT(DISTINCT partner_id) AS distinct_partners | |
| FROM account_move_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - distinct | |
| - id: L1-066 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: Count the number of journal entries by their type. | |
| gold_sql: 'SELECT type, COUNT(*) AS entry_count | |
| FROM account_journal | |
| GROUP BY type; | |
| ' | |
| tags: | |
| - aggregate | |
| - group_by | |
| - id: L1-067 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: How many stock moves are recorded in the system? | |
| gold_sql: 'SELECT COUNT(*) AS total_moves FROM stock_move; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-068 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: List all stock picking states available in the system. | |
| gold_sql: 'SELECT DISTINCT state FROM stock_picking; | |
| ' | |
| tags: | |
| - listing | |
| - distinct | |
| - id: L1-069 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the maximum inventory quantity recorded for any product? | |
| gold_sql: 'SELECT MAX(inventory_quantity) AS max_inventory FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - max | |
| - id: L2-065 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Show the total quantity of products sold per sale order. | |
| gold_sql: 'SELECT so.id, so.name, SUM(sol.product_uom_qty) AS total_quantity | |
| FROM sale_order so | |
| JOIN sale_order_line sol ON sol.order_id = so.id | |
| GROUP BY so.id, so.name | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-066 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Get the count of sale orders for each customer. | |
| gold_sql: 'SELECT rp.name AS customer, COUNT(so.id) AS sale_order_count | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| GROUP BY rp.id, rp.name | |
| ORDER BY sale_order_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L3-060 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Show total debits and credits for each account. | |
| gold_sql: "SELECT aa.name AS account,\n SUM(CASE WHEN aml.credit > 0 THEN\ | |
| \ aml.credit ELSE 0 END) AS total_credits,\n SUM(CASE WHEN aml.debit > 0\ | |
| \ THEN aml.debit ELSE 0 END) AS total_debits\nFROM account_account aa\nJOIN account_move_line\ | |
| \ aml ON aa.id = aml.account_id\nGROUP BY aa.id, aa.name\nORDER BY account;\n" | |
| tags: | |
| - aggregate | |
| - accounting | |
| - id: L3-061 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: List all partners with their total invoice amounts. | |
| gold_sql: "SELECT rp.name AS partner,\n SUM(am.amount_total) AS total_invoiced\n\ | |
| FROM res_partner rp\nJOIN account_move am ON rp.id = am.partner_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\nGROUP BY rp.id, rp.name\nORDER BY\ | |
| \ total_invoiced DESC;\n" | |
| tags: | |
| - cross_domain | |
| - aggregate | |
| - id: L3-062 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Show the total amount of invoices grouped by journal. | |
| gold_sql: "SELECT aj.code AS journal,\n SUM(am.amount_total) AS total_amount\n\ | |
| FROM account_journal aj\nJOIN account_move am ON aj.id = am.journal_id\nWHERE\ | |
| \ am.move_type = 'out_invoice'\n AND am.state = 'posted'\nGROUP BY aj.id, aj.code\n\ | |
| ORDER BY total_amount DESC;\n" | |
| tags: | |
| - cross_domain | |
| - aggregate | |
| - id: L3-063 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Find the average invoice amount by company. | |
| gold_sql: "SELECT rc.name AS company,\n AVG(am.amount_total) AS average_invoice\n\ | |
| FROM res_company rc\nJOIN account_move am ON rc.id = am.company_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\nGROUP BY rc.id, rc.name\nORDER BY\ | |
| \ average_invoice DESC;\n" | |
| tags: | |
| - cross_domain | |
| - aggregate | |
| - id: L3-064 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of products in stock grouped by location. | |
| gold_sql: "SELECT sl.name AS location,\n SUM(sq.quantity) AS total_quantity\n\ | |
| FROM stock_quant sq\nJOIN stock_location sl ON sl.id = sq.location_id\nGROUP BY\ | |
| \ sl.name\nORDER BY total_quantity DESC;\n" | |
| tags: | |
| - inventory | |
| - group_by | |
| - id: L3-065 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Get the list of products and their reserved quantities along with the respective | |
| picking states. | |
| gold_sql: "SELECT pp.id AS product_id,\n SUM(sq.reserved_quantity) AS total_reserved,\n\ | |
| \ sp.state AS picking_state\nFROM stock_quant sq\nJOIN product_product pp\ | |
| \ ON pp.id = sq.product_id\nJOIN stock_move_line sml ON sml.product_id = pp.id\n\ | |
| JOIN stock_picking sp ON sp.id = sml.picking_id\nGROUP BY pp.id, sp.state\nORDER\ | |
| \ BY total_reserved DESC;\n" | |
| tags: | |
| - inventory | |
| - join | |
| - id: L3-066 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show the average inventory quantity for each product across all warehouses. | |
| gold_sql: "SELECT pp.id AS product_id,\n AVG(sq.inventory_quantity) AS avg_inventory_quantity\n\ | |
| FROM stock_quant sq\nJOIN product_product pp ON pp.id = sq.product_id\nGROUP BY\ | |
| \ pp.id\nORDER BY avg_inventory_quantity DESC;\n" | |
| tags: | |
| - inventory | |
| - average | |
| - id: L3-067 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List products with their total inventory quantity and the latest inventory date. | |
| gold_sql: "SELECT pp.id AS product_id,\n SUM(sq.inventory_quantity) AS total_inventory,\n\ | |
| \ MAX(sq.inventory_date) AS latest_inventory_date\nFROM stock_quant sq\n\ | |
| JOIN product_product pp ON pp.id = sq.product_id\nGROUP BY pp.id\nORDER BY total_inventory\ | |
| \ DESC;\n" | |
| tags: | |
| - inventory | |
| - aggregation | |
| - id: L3-068 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Get the total number of purchase orders and their average invoice count by state. | |
| gold_sql: 'SELECT po.state, COUNT(po.id) AS total_orders, AVG(po.invoice_count) | |
| AS avg_invoice_count | |
| FROM purchase_order po | |
| GROUP BY po.state | |
| ORDER BY total_orders DESC; | |
| ' | |
| tags: | |
| - cross_domain | |
| - id: L3-069 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Show the total value of stock moves for products grouped by their destination | |
| locations. | |
| gold_sql: 'SELECT sm.location_dest_id, SUM(pol.price_subtotal) AS total_value | |
| FROM stock_move sm | |
| JOIN purchase_order_line pol ON pol.product_id = sm.product_id | |
| GROUP BY sm.location_dest_id | |
| ORDER BY total_value DESC; | |
| ' | |
| tags: | |
| - cross_domain | |
| - id: L4-011 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Show the total quantity sold and average price per unit for each product this | |
| year. | |
| gold_sql: "WITH sales AS (\n SELECT sol.product_id,\n SUM(sol.product_uom_qty)\ | |
| \ AS total_qty,\n AVG(sol.price_unit) AS avg_price\n FROM sale_order_line\ | |
| \ sol\n JOIN sale_order so ON so.id = sol.order_id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY sol.product_id\n\ | |
| )\nSELECT pt.name->>'en_US' AS product,\n s.total_qty, s.avg_price\nFROM\ | |
| \ product_product pp\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN sales s ON s.product_id = pp.id\nORDER BY total_qty DESC NULLS LAST\nLIMIT\ | |
| \ 20;\n" | |
| tags: | |
| - sales_analysis | |
| - product_performance | |
| - id: L4-012 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: List the number of orders and total revenue generated by each customer this | |
| year. | |
| gold_sql: "WITH customer_orders AS (\n SELECT so.partner_id,\n COUNT(so.id)\ | |
| \ AS order_count,\n SUM(so.amount_total) AS total_revenue\n FROM sale_order\ | |
| \ so\n WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY so.partner_id\n)\nSELECT rp.name AS customer,\n co.order_count,\ | |
| \ co.total_revenue\nFROM res_partner rp\nJOIN customer_orders co ON co.partner_id\ | |
| \ = rp.id\nORDER BY total_revenue DESC NULLS LAST\nLIMIT 20;\n" | |
| tags: | |
| - customer_insights | |
| - revenue_analysis | |
| - id: L4-013 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Calculate the total revenue and average order value for each sales team this | |
| year. | |
| gold_sql: "WITH team_sales AS (\n SELECT so.team_id,\n SUM(so.amount_total)\ | |
| \ AS total_revenue,\n AVG(so.amount_total) AS avg_order_value\n FROM\ | |
| \ sale_order so\n WHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ date_trunc('year', NOW())\n GROUP BY so.team_id\n)\nSELECT ct.name AS sales_team,\n\ | |
| \ ts.total_revenue, ts.avg_order_value\nFROM crm_team ct\nJOIN team_sales\ | |
| \ ts ON ts.team_id = ct.id\nORDER BY total_revenue DESC NULLS LAST\nLIMIT 20;\n" | |
| tags: | |
| - sales_performance | |
| - team_metrics | |
| - id: L4-014 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Show the total quantity of products in stock, grouped by the product ID. | |
| gold_sql: 'SELECT product_id, SUM(quantity) AS total_quantity | |
| FROM stock_quant | |
| GROUP BY product_id; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L4-015 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: List products with their total reserved quantity, ordered by product ID. | |
| gold_sql: 'SELECT product_id, SUM(reserved_quantity) AS total_reserved | |
| FROM stock_quant | |
| GROUP BY product_id | |
| ORDER BY product_id; | |
| ' | |
| tags: | |
| - inventory | |
| - reserved | |
| - id: L4-016 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Get the average inventory quantity of products across different locations. | |
| gold_sql: 'SELECT location_id, AVG(inventory_quantity) AS avg_inventory | |
| FROM stock_quant | |
| GROUP BY location_id; | |
| ' | |
| tags: | |
| - inventory | |
| - average | |
| - id: L4-017 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Show the total quantity of products by location, including only locations with | |
| stock. | |
| gold_sql: "WITH location_stock AS (\n SELECT location_id, SUM(quantity) AS total_quantity\n\ | |
| \ FROM stock_quant\n GROUP BY location_id\n)\nSELECT ls.location_id, ls.total_quantity\n\ | |
| FROM location_stock ls\nWHERE ls.total_quantity > 0;\n" | |
| tags: | |
| - inventory | |
| - location | |
| - id: L4-018 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Identify the most frequently purchased products and their total purchase count | |
| in the last year. | |
| gold_sql: "WITH product_count AS (\n SELECT pol.product_id, COUNT(pol.id) AS purchase_count\n\ | |
| \ FROM purchase_order_line pol\n JOIN purchase_order po ON po.id = pol.order_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n AND po.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY pol.product_id\n)\nSELECT pp.id AS product_id, pp.default_code,\ | |
| \ pc.purchase_count\nFROM product_count pc\nJOIN product_product pp ON pp.id =\ | |
| \ pc.product_id\nORDER BY pc.purchase_count DESC\nLIMIT 10;\n" | |
| tags: | |
| - logistics | |
| - cte | |
| - id: L4-019 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Retrieve the total number of purchase orders and the average invoice count per | |
| supplier for this year. | |
| gold_sql: "WITH supplier_orders AS (\n SELECT po.partner_id, COUNT(po.id) AS total_orders,\ | |
| \ AVG(po.invoice_count) AS avg_invoices\n FROM purchase_order po\n WHERE po.state\ | |
| \ IN ('purchase','done')\n AND po.date_order >= date_trunc('year', NOW())\n\ | |
| \ GROUP BY po.partner_id\n)\nSELECT rp.name AS supplier, so.total_orders, so.avg_invoices\n\ | |
| FROM supplier_orders so\nJOIN res_partner rp ON rp.id = so.partner_id\nORDER BY\ | |
| \ so.total_orders DESC;\n" | |
| tags: | |
| - logistics | |
| - cte | |
| - id: L5-013 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Calculate the total tax amount for each partner for the current fiscal year. | |
| gold_sql: "WITH tax_totals AS (\n SELECT aml.partner_id, SUM(aml.tax_line_id) AS\ | |
| \ total_tax\n FROM account_move_line aml\n JOIN account_move am ON am.id = aml.move_id\n\ | |
| \ WHERE am.date >= date_trunc('year', NOW())\n GROUP BY aml.partner_id\n)\n\ | |
| SELECT rp.name AS partner_name, tt.total_tax\nFROM tax_totals tt\nJOIN res_partner\ | |
| \ rp ON rp.id = tt.partner_id\nORDER BY tt.total_tax DESC;\n" | |
| tags: | |
| - finance | |
| - tax | |
| - id: L5-014 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Identify accounts with a balance above the average balance for all accounts. | |
| gold_sql: "WITH average_balance AS (\n SELECT AVG(balance) AS avg_balance\n FROM\ | |
| \ (\n SELECT SUM(aml.balance) AS balance\n FROM account_move_line aml\n\ | |
| \ GROUP BY aml.account_id\n ) AS account_balances\n), account_balances AS\ | |
| \ (\n SELECT aml.account_id, SUM(aml.balance) AS total_balance\n FROM account_move_line\ | |
| \ aml\n GROUP BY aml.account_id\n)\nSELECT aa.name AS account_name, ab.total_balance\n\ | |
| FROM account_balances ab\nJOIN average_balance av ON ab.total_balance > av.avg_balance\n\ | |
| JOIN account_account aa ON aa.id = ab.account_id\nORDER BY ab.total_balance DESC;\n" | |
| tags: | |
| - finance | |
| - balance | |
| - id: L5-015 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Determine the total quantity of products reserved per warehouse location. | |
| gold_sql: "WITH reserved AS (\n SELECT sq.location_id, SUM(sq.reserved_quantity)\ | |
| \ AS total_reserved\n FROM stock_quant sq\n GROUP BY sq.location_id\n)\nSELECT\ | |
| \ l.name AS location_name,\n r.total_reserved\nFROM reserved r\nJOIN stock_location\ | |
| \ l ON l.id = r.location_id\nORDER BY r.total_reserved DESC;\n" | |
| tags: | |
| - inventory | |
| - warehouse | |
| - id: L5-016 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Find the top 5 products with the highest inventory difference in stock. | |
| gold_sql: "SELECT pp.default_code AS product_code,\n sq.inventory_diff_quantity\n\ | |
| FROM stock_quant sq\nJOIN product_product pp ON pp.id = sq.product_id\nORDER BY\ | |
| \ sq.inventory_diff_quantity DESC\nLIMIT 5;\n" | |
| tags: | |
| - inventory | |
| - top_products | |
| - id: L5-017 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Identify locations with the highest total inventory across all products. | |
| gold_sql: "SELECT l.name AS location_name,\n SUM(sq.inventory_quantity) AS\ | |
| \ total_inventory\nFROM stock_quant sq\nJOIN stock_location l ON l.id = sq.location_id\n\ | |
| GROUP BY l.id, l.name\nORDER BY total_inventory DESC;\n" | |
| tags: | |
| - inventory | |
| - locations | |
| - id: L1-070 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: What is the total number of sale orders created this month? | |
| gold_sql: 'SELECT COUNT(*) AS total_orders | |
| FROM sale_order | |
| WHERE create_date >= date_trunc(''month'', NOW()); | |
| ' | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L1-071 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders are associated with each partner? | |
| gold_sql: 'SELECT partner_id, COUNT(*) AS order_count | |
| FROM sale_order | |
| GROUP BY partner_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group_by | |
| - id: L1-072 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: Count the number of sale orders per campaign. | |
| gold_sql: 'SELECT campaign_id, COUNT(*) AS campaign_order_count | |
| FROM sale_order | |
| GROUP BY campaign_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group_by | |
| - id: L2-067 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Retrieve all journal entries along with their associated company names. | |
| gold_sql: 'SELECT aj.id AS journal_id, aj.name AS journal_name, rc.name AS company_name | |
| FROM account_journal aj | |
| JOIN res_company rc ON rc.id = aj.company_id | |
| ORDER BY aj.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-068 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Find total amounts grouped by currency for all posted invoices. | |
| gold_sql: 'SELECT cur.name AS currency, SUM(am.amount_total) AS total_amount | |
| FROM account_move am | |
| JOIN res_currency cur ON cur.id = am.currency_id | |
| WHERE am.move_type = ''out_invoice'' AND am.state = ''posted'' | |
| GROUP BY cur.name | |
| ORDER BY total_amount DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-069 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List all partners with their invoice counts and total amounts. | |
| gold_sql: 'SELECT rp.name AS partner_name, COUNT(am.id) AS invoice_count, SUM(am.amount_total) | |
| AS total_invoiced | |
| FROM res_partner rp | |
| LEFT JOIN account_move am ON am.partner_id = rp.id | |
| WHERE am.move_type = ''out_invoice'' AND am.state = ''posted'' | |
| GROUP BY rp.name | |
| ORDER BY total_invoiced DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-070 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Show all accounts and their associated journal names. | |
| gold_sql: 'SELECT aa.id AS account_id, aa.name AS account_name, aj.name AS journal_name | |
| FROM account_account aa | |
| JOIN account_journal aj ON aj.default_account_id = aa.id | |
| ORDER BY aa.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-071 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show the quantity of each product along with its location. | |
| gold_sql: 'SELECT pp.default_code AS product_code, sl.name AS location_name, SUM(sq.quantity) | |
| AS quantity | |
| FROM product_product pp | |
| JOIN stock_quant sq ON pp.id = sq.product_id | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| GROUP BY pp.default_code, sl.name; | |
| ' | |
| tags: | |
| - join | |
| - group | |
| - id: L2-072 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Find the total reserved quantity of products in each location. | |
| gold_sql: 'SELECT sl.name AS location_name, SUM(sq.reserved_quantity) AS total_reserved_quantity | |
| FROM stock_location sl | |
| JOIN stock_quant sq ON sl.id = sq.location_id | |
| GROUP BY sl.name; | |
| ' | |
| tags: | |
| - join | |
| - group | |
| - id: L2-073 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Get the total inventory quantity of products for each company. | |
| gold_sql: 'SELECT sq.company_id, SUM(sq.inventory_quantity) AS total_inventory | |
| FROM stock_quant sq | |
| GROUP BY sq.company_id; | |
| ' | |
| tags: | |
| - group | |
| - id: L3-070 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: List the total quantity sold for each product in the last year. | |
| gold_sql: 'SELECT pp.id, pt.name->>''en_US'' AS product_name, SUM(sol.product_uom_qty) | |
| AS total_quantity | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN sale_order so ON so.id = sol.order_id | |
| WHERE so.date_order >= NOW() - INTERVAL ''1 year'' | |
| GROUP BY pp.id, pt.name->>''en_US''; | |
| ' | |
| tags: | |
| - sales | |
| - aggregation | |
| - id: L3-071 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Which customers have placed more than five orders in the last six months? | |
| gold_sql: 'SELECT rp.id, rp.name, COUNT(so.id) AS order_count | |
| FROM res_partner rp | |
| JOIN sale_order so ON so.partner_id = rp.id | |
| WHERE so.date_order >= NOW() - INTERVAL ''6 months'' | |
| GROUP BY rp.id, rp.name | |
| HAVING COUNT(so.id) > 5; | |
| ' | |
| tags: | |
| - customer_analysis | |
| - temporal | |
| - id: L3-072 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: How many unique customers made purchases in each month of the last year? | |
| gold_sql: 'SELECT DATE_TRUNC(''month'', so.date_order) AS month, COUNT(DISTINCT | |
| so.partner_id) AS unique_customers | |
| FROM sale_order so | |
| WHERE so.date_order >= NOW() - INTERVAL ''1 year'' | |
| GROUP BY month | |
| ORDER BY month; | |
| ' | |
| tags: | |
| - customer_analysis | |
| - temporal | |
| - aggregation | |
| - id: L5-018 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Calculate the total sales revenue for each product category this year. | |
| gold_sql: "WITH category_sales AS (\n SELECT pt.categ_id,\n SUM(sol.price_subtotal)\ | |
| \ AS total_revenue\n FROM sale_order_line sol\n JOIN sale_order so ON so.id\ | |
| \ = sol.order_id\n JOIN product_product pp ON pp.id = sol.product_id\n JOIN\ | |
| \ product_template pt ON pt.id = pp.product_tmpl_id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY pt.categ_id\n\ | |
| )\nSELECT pc.name AS category,\n cs.total_revenue\nFROM category_sales cs\n\ | |
| JOIN product_category pc ON pc.id = cs.categ_id\nORDER BY total_revenue DESC;\n" | |
| tags: | |
| - sales | |
| - revenue | |
| - id: L5-019 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: List products with total sales quantities exceeding the average for their category | |
| this year. | |
| gold_sql: "WITH category_totals AS (\n SELECT pt.categ_id,\n SUM(sol.product_uom_qty)\ | |
| \ AS total_quantity\n FROM sale_order_line sol\n JOIN sale_order so ON so.id\ | |
| \ = sol.order_id\n JOIN product_product pp ON pp.id = sol.product_id\n JOIN\ | |
| \ product_template pt ON pt.id = pp.product_tmpl_id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY pt.categ_id\n\ | |
| ), product_sales AS (\n SELECT pp.id AS product_id,\n SUM(sol.product_uom_qty)\ | |
| \ AS product_quantity,\n pt.categ_id\n FROM sale_order_line sol\n JOIN\ | |
| \ sale_order so ON so.id = sol.order_id\n JOIN product_product pp ON pp.id =\ | |
| \ sol.product_id\n JOIN product_template pt ON pt.id = pp.product_tmpl_id\n \ | |
| \ WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY pp.id, pt.categ_id\n)\nSELECT pt.name AS product,\n \ | |
| \ ps.product_quantity,\n ct.total_quantity\nFROM product_sales ps\nJOIN\ | |
| \ category_totals ct ON ct.categ_id = ps.categ_id\nJOIN product_product pp ON\ | |
| \ pp.id = ps.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE ps.product_quantity > ct.total_quantity / NULLIF((SELECT COUNT(DISTINCT\ | |
| \ categ_id) FROM product_template), 0);\n" | |
| tags: | |
| - sales | |
| - comparison | |
| - id: L5-020 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Identify the top 3 salespersons based on the total revenue generated this year. | |
| gold_sql: "WITH salesperson_revenue AS (\n SELECT so.user_id,\n SUM(so.amount_total)\ | |
| \ AS total_revenue\n FROM sale_order so\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY so.user_id\n)\n\ | |
| SELECT rp.name AS salesperson,\n sr.total_revenue\nFROM salesperson_revenue\ | |
| \ sr\nJOIN res_partner rp ON rp.id = sr.user_id\nORDER BY total_revenue DESC\n\ | |
| LIMIT 3;\n" | |
| tags: | |
| - sales | |
| - ranking | |
| - id: L5-021 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Determine the total number of purchase orders and average order amount per supplier | |
| for the last year. | |
| gold_sql: "WITH supplier_orders AS (SELECT partner_id,\n \ | |
| \ COUNT(id) AS total_orders,\n \ | |
| \ AVG(amount_total) AS avg_order_amount\n \ | |
| \ FROM purchase_order\n WHERE state IN\ | |
| \ ('purchase', 'done')\n AND date_order >=\ | |
| \ date_trunc('year', NOW()) - interval '1 year'\n \ | |
| \ GROUP BY partner_id)\nSELECT rp.name AS supplier,\n so.total_orders,\n\ | |
| \ so.avg_order_amount\nFROM supplier_orders so\nJOIN res_partner rp ON rp.id\ | |
| \ = so.partner_id\nORDER BY so.total_orders DESC;\n" | |
| tags: | |
| - financial | |
| - supplier | |
| - id: L1-073 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the number of stock moves for the current month. | |
| gold_sql: 'SELECT COUNT(*) AS stock_moves_this_month | |
| FROM stock_move | |
| WHERE create_date >= date_trunc(''month'', NOW()); | |
| ' | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L1-074 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many purchase order lines are in the draft state? | |
| gold_sql: 'SELECT COUNT(*) AS draft_order_lines | |
| FROM purchase_order_line | |
| WHERE state = ''draft''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-075 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: List all partners involved in purchase orders. | |
| gold_sql: 'SELECT DISTINCT partner_id | |
| FROM purchase_order; | |
| ' | |
| tags: | |
| - listing | |
| - distinct | |
| - id: L1-076 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the total number of stock pickings created today. | |
| gold_sql: 'SELECT COUNT(*) AS today_pickings | |
| FROM stock_picking | |
| WHERE create_date::date = CURRENT_DATE; | |
| ' | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L2-074 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List sale orders with their partner's invoice details. | |
| gold_sql: 'SELECT so.id, so.name, rp.name AS partner_name, rp.vat AS partner_vat | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_invoice_id | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-075 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Retrieve purchase orders along with their invoice count and state. | |
| gold_sql: 'SELECT po.id, po.invoice_count, po.state | |
| FROM purchase_order po | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-076 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: List stock moves with the associated product names and their quantities. | |
| gold_sql: 'SELECT sm.id, pp.default_code AS product_code, sm.product_uom, sm.product_qty | |
| FROM stock_move sm | |
| JOIN product_product pp ON pp.id = sm.product_id | |
| ORDER BY sm.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-077 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show all purchase order lines with their respective supplier names. | |
| gold_sql: 'SELECT pol.id, rp.name AS supplier, pol.product_qty | |
| FROM purchase_order_line pol | |
| JOIN purchase_order po ON po.id = pol.order_id | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| ORDER BY pol.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-078 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Get stock pickings with their destination addresses. | |
| gold_sql: 'SELECT sp.id, sp.name, rp.name AS destination_address | |
| FROM stock_picking sp | |
| JOIN res_partner rp ON rp.id = sp.partner_id | |
| ORDER BY sp.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L3-073 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Get the total invoice count for each product ordered this year. | |
| gold_sql: "SELECT pp.id AS product_id, COUNT(po.invoice_count) AS total_invoices\n\ | |
| FROM purchase_order po\nJOIN purchase_order_line pol ON pol.order_id = po.id\n\ | |
| JOIN product_product pp ON pp.id = pol.product_id\nWHERE po.state IN ('purchase',\ | |
| \ 'done')\n AND po.create_date >= date_trunc('year', NOW())\nGROUP BY pp.id\n\ | |
| ORDER BY total_invoices DESC;\n" | |
| tags: | |
| - logistics | |
| - temporal | |
| - aggregation | |
| - id: L3-074 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Show the average price per product for orders placed this year. | |
| gold_sql: "SELECT pp.id AS product_id, AVG(pol.price_unit) AS average_price\nFROM\ | |
| \ purchase_order po\nJOIN purchase_order_line pol ON pol.order_id = po.id\nJOIN\ | |
| \ product_product pp ON pp.id = pol.product_id\nWHERE po.state IN ('purchase',\ | |
| \ 'done')\n AND po.create_date >= date_trunc('year', NOW())\nGROUP BY pp.id\n\ | |
| ORDER BY average_price DESC;\n" | |
| tags: | |
| - logistics | |
| - temporal | |
| - aggregation | |
| - id: L4-020 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: List total payments received by company, including the number of invoices. | |
| gold_sql: "WITH payment_data AS (\n SELECT am.company_id, COUNT(am.id) AS invoice_count,\ | |
| \ SUM(am.amount_total) AS total_payments\n FROM account_move am\n WHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\n GROUP BY am.company_id\n)\n\ | |
| SELECT rc.name AS company, pd.invoice_count, pd.total_payments\nFROM res_company\ | |
| \ rc\nJOIN payment_data pd ON pd.company_id = rc.id\nORDER BY total_payments DESC\ | |
| \ NULLS LAST;\n" | |
| tags: | |
| - finance | |
| - company_summary | |
| - id: L4-021 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: Calculate the running total of invoices per customer for the last year. | |
| gold_sql: "WITH invoice_totals AS (\n SELECT am.partner_id, am.date, SUM(am.amount_total)\ | |
| \ AS total_invoice\n FROM account_move am\n WHERE am.move_type = 'out_invoice'\n\ | |
| \ AND am.state = 'posted'\n AND am.date >= date_trunc('year', NOW()) - interval\ | |
| \ '1 year'\n GROUP BY am.partner_id, am.date\n)\nSELECT rp.name AS customer,\ | |
| \ it.date,\n SUM(it.total_invoice) OVER (PARTITION BY it.partner_id ORDER\ | |
| \ BY it.date) AS running_total\nFROM res_partner rp\nJOIN invoice_totals it ON\ | |
| \ it.partner_id = rp.id\nORDER BY it.date;\n" | |
| tags: | |
| - finance | |
| - running_total | |
| - id: L4-022 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Find the top 5 products based on total quantity received this year. | |
| gold_sql: "WITH received AS (\n SELECT pol.product_id, SUM(pol.product_qty) AS\ | |
| \ total_received\n FROM purchase_order_line pol\n JOIN purchase_order po ON\ | |
| \ po.id = pol.order_id\n WHERE po.state IN ('purchase', 'done')\n AND po.date_order\ | |
| \ >= date_trunc('year', NOW())\n GROUP BY pol.product_id\n)\nSELECT pp.default_code\ | |
| \ AS product_code,\n r.total_received\nFROM received r\nJOIN product_product\ | |
| \ pp ON pp.id = r.product_id\nORDER BY r.total_received DESC\nLIMIT 5;\n" | |
| tags: | |
| - product_performance | |
| - top_products | |
| - id: L5-022 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Identify the accounts with the highest total balances and average balances over | |
| the last year. | |
| gold_sql: "WITH account_balances AS (\n SELECT account_id,\n SUM(debit\ | |
| \ - credit) AS total_balance,\n AVG(debit - credit) AS average_balance\n\ | |
| \ FROM account_move_line\n WHERE move_id IN (\n SELECT id FROM account_move\n\ | |
| \ WHERE date >= date_trunc('year', NOW())\n )\n GROUP BY account_id\n)\n\ | |
| SELECT account_id,\n total_balance,\n average_balance\nFROM account_balances\n\ | |
| ORDER BY total_balance DESC\nLIMIT 10;\n" | |
| tags: | |
| - financial | |
| - accounts | |
| - ranking | |
| - id: L5-023 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Determine the total revenue generated by each partner over the last six months | |
| and their average monthly revenue. | |
| gold_sql: "WITH partner_revenue AS (\n SELECT partner_id,\n SUM(amount_total)\ | |
| \ AS total_revenue\n FROM account_move\n WHERE date >= NOW() - INTERVAL '6 months'\n\ | |
| \ GROUP BY partner_id\n)\nSELECT partner_id,\n total_revenue,\n total_revenue\ | |
| \ / 6 AS average_monthly_revenue\nFROM partner_revenue;\n" | |
| tags: | |
| - financial | |
| - revenue | |
| - aggregation | |
| - id: L5-024 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: 'Analyze purchase orders by supplier: total quantity ordered and total value | |
| for each supplier this year.' | |
| gold_sql: "WITH order_summary AS (\n SELECT po.partner_id, \n SUM(pol.product_qty)\ | |
| \ AS total_quantity,\n SUM(pol.price_subtotal) AS total_value\n FROM\ | |
| \ purchase_order po\n JOIN purchase_order_line pol ON pol.order_id = po.id\n\ | |
| \ WHERE po.state IN ('purchase', 'done')\n AND po.create_date >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY po.partner_id\n)\nSELECT rp.name AS supplier,\n os.total_quantity,\n\ | |
| \ os.total_value\nFROM order_summary os\nJOIN res_partner rp ON rp.id =\ | |
| \ os.partner_id\nORDER BY os.total_value DESC;\n" | |
| tags: | |
| - analysis | |
| - supplier_performance | |
| - id: L5-025 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: 'Evaluate purchase order trends: average order value per month for this year.' | |
| gold_sql: "WITH monthly_avg AS (\n SELECT DATE_TRUNC('month', po.create_date) AS\ | |
| \ month,\n AVG(pol.price_subtotal) AS avg_order_value\n FROM purchase_order\ | |
| \ po\n JOIN purchase_order_line pol ON pol.order_id = po.id\n WHERE po.state\ | |
| \ IN ('purchase', 'done')\n AND po.create_date >= date_trunc('year', NOW())\n\ | |
| \ GROUP BY month\n)\nSELECT TO_CHAR(month, 'Month YYYY') AS month,\n avg_order_value\n\ | |
| FROM monthly_avg\nORDER BY month;\n" | |
| tags: | |
| - trend_analysis | |
| - order_value | |
| - id: L1-077 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: Count the number of invoices associated with each partner. | |
| gold_sql: 'SELECT partner_id, COUNT(*) AS invoice_count FROM account_move WHERE | |
| invoice_payment_term_id IS NOT NULL GROUP BY partner_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-078 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: Show the names of all companies with their corresponding IDs. | |
| gold_sql: 'SELECT id, name FROM res_company ORDER BY name; | |
| ' | |
| tags: | |
| - listing | |
| - id: L1-079 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many journal entries are associated with a specific company ID? | |
| gold_sql: 'SELECT COUNT(*) AS journal_entry_count FROM account_move WHERE company_id | |
| = 1; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-080 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the maximum reserved quantity of any stock item? | |
| gold_sql: 'SELECT MAX(reserved_quantity) AS max_reserved FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - max | |
| - id: L2-079 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Count the number of sale orders for each customer. | |
| gold_sql: 'SELECT rp.id, rp.name, COUNT(so.id) AS sale_order_count | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| GROUP BY rp.id, rp.name | |
| ORDER BY rp.id; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-080 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List sale orders with their associated campaign IDs and total amount. | |
| gold_sql: 'SELECT so.id, so.name, so.campaign_id, SUM(sol.price_unit * sol.product_uom_qty) | |
| AS total_amount | |
| FROM sale_order so | |
| JOIN sale_order_line sol ON sol.order_id = so.id | |
| GROUP BY so.id, so.name, so.campaign_id | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L4-023 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Calculate the average order value for each customer this year. | |
| gold_sql: "WITH customer_orders AS (\n SELECT so.partner_id, AVG(so.amount_total)\ | |
| \ AS avg_order_value\n FROM sale_order so\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY so.partner_id\n\ | |
| )\nSELECT rp.name AS customer,\n co.avg_order_value\nFROM res_partner rp\n\ | |
| JOIN customer_orders co ON co.partner_id = rp.id\nORDER BY avg_order_value DESC;\n" | |
| tags: | |
| - average_order_value | |
| - customer | |
| - id: L4-024 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Show the top 5 products based on the number of orders placed this year. | |
| gold_sql: "WITH product_orders AS (\n SELECT sol.product_id, COUNT(so.id) AS order_count\n\ | |
| \ FROM sale_order_line sol\n JOIN sale_order so ON so.id = sol.order_id\n WHERE\ | |
| \ so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW())\n\ | |
| \ GROUP BY sol.product_id\n)\nSELECT pp.default_code AS product_code,\n \ | |
| \ po.order_count\nFROM product_product pp\nJOIN product_orders po ON po.product_id\ | |
| \ = pp.id\nORDER BY order_count DESC\nLIMIT 5;\n" | |
| tags: | |
| - top_products | |
| - order_count | |
| - id: L4-025 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Identify the sales trends by customer for the last six months. | |
| gold_sql: "WITH monthly_sales AS (\n SELECT so.partner_id, DATE_TRUNC('month',\ | |
| \ so.date_order) AS month,\n SUM(so.amount_total) AS total_sales\n FROM\ | |
| \ sale_order so\n WHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ date_trunc('month', NOW()) - INTERVAL '6 months'\n GROUP BY so.partner_id,\ | |
| \ month\n)\nSELECT rp.name AS customer,\n ms.month,\n ms.total_sales\n\ | |
| FROM res_partner rp\nJOIN monthly_sales ms ON ms.partner_id = rp.id\nORDER BY\ | |
| \ month DESC;\n" | |
| tags: | |
| - sales_trends | |
| - customer | |
| - id: L4-026 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: List the average price and total quantity received for each product in purchase | |
| orders this year. | |
| gold_sql: "SELECT pp.id AS product_id,\n AVG(pol.price_unit) AS avg_price,\n\ | |
| \ SUM(pol.product_qty) AS total_qty_received\nFROM purchase_order po\nJOIN\ | |
| \ purchase_order_line pol ON pol.order_id = po.id\nJOIN product_product pp ON\ | |
| \ pp.id = pol.product_id\nWHERE po.state IN ('purchase','done')\n AND po.create_date\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pp.id\nORDER BY total_qty_received DESC;\n" | |
| tags: | |
| - product_performance | |
| - average_metrics | |
| - id: L4-027 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Calculate the total quantity received and average discount for each supplier | |
| this year. | |
| gold_sql: "SELECT rp.id AS supplier_id,\n SUM(pol.product_qty) AS total_qty_received,\n\ | |
| \ AVG(pol.discount) AS avg_discount\nFROM purchase_order po\nJOIN purchase_order_line\ | |
| \ pol ON pol.order_id = po.id\nJOIN res_partner rp ON rp.id = po.partner_id\n\ | |
| WHERE po.state IN ('purchase','done')\n AND po.create_date >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY rp.id\nORDER BY total_qty_received DESC;\n" | |
| tags: | |
| - supplier_performance | |
| - quantity_discount | |
| - id: L4-028 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Display the total number of purchase orders and average invoice count per customer | |
| this year. | |
| gold_sql: "SELECT rp.id AS customer_id,\n COUNT(po.id) AS total_orders,\n\ | |
| \ AVG(po.invoice_count) AS avg_invoice_count\nFROM purchase_order po\nJOIN\ | |
| \ res_partner rp ON rp.id = po.partner_id\nWHERE po.state IN ('purchase','done')\n\ | |
| \ AND po.create_date >= date_trunc('year', NOW())\nGROUP BY rp.id\nORDER BY total_orders\ | |
| \ DESC;\n" | |
| tags: | |
| - customer_kpi | |
| - purchase_orders | |
| - id: L5-026 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: List products with their total inventory quantities across all locations. | |
| gold_sql: "WITH total_inventory AS (\n SELECT product_id, SUM(inventory_quantity)\ | |
| \ AS total_qty\n FROM stock_quant\n GROUP BY product_id\n)\nSELECT pp.default_code\ | |
| \ AS product_code,\n ti.total_qty\nFROM total_inventory ti\nJOIN product_product\ | |
| \ pp ON pp.id = ti.product_id\nORDER BY ti.total_qty DESC;\n" | |
| tags: | |
| - inventory | |
| - aggregation | |
| - id: L5-027 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Calculate the average quantity of products reserved in stock across all warehouses. | |
| gold_sql: "WITH reserved_quantities AS (\n SELECT product_id, AVG(reserved_quantity)\ | |
| \ AS avg_reserved_qty\n FROM stock_quant\n GROUP BY product_id\n)\nSELECT pp.default_code\ | |
| \ AS product_code,\n rq.avg_reserved_qty\nFROM reserved_quantities rq\n\ | |
| JOIN product_product pp ON pp.id = rq.product_id\nORDER BY rq.avg_reserved_qty\ | |
| \ DESC;\n" | |
| tags: | |
| - inventory | |
| - average | |
| - id: L5-028 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Determine the total inventory difference for each product across all warehouses. | |
| gold_sql: "WITH inventory_differences AS (\n SELECT product_id, SUM(inventory_diff_quantity)\ | |
| \ AS total_diff\n FROM stock_quant\n GROUP BY product_id\n)\nSELECT pp.default_code\ | |
| \ AS product_code,\n id.total_diff\nFROM inventory_differences id\nJOIN\ | |
| \ product_product pp ON pp.id = id.product_id\nORDER BY id.total_diff DESC;\n" | |
| tags: | |
| - inventory | |
| - difference | |
| - id: L1-081 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many unique products were sold? | |
| gold_sql: 'SELECT COUNT(DISTINCT product_id) AS unique_products_sold | |
| FROM sale_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-082 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: What is the total quantity delivered for each sale order? | |
| gold_sql: 'SELECT order_id, COALESCE(SUM(product_uom_qty), 0) AS total_delivered | |
| FROM sale_order_line | |
| GROUP BY order_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group | |
| - id: L1-083 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: Show the total number of stock picking records. | |
| gold_sql: 'SELECT COUNT(*) AS picking_count FROM stock_picking; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L2-081 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: List all products and their total reserved quantities. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, COALESCE(SUM(sq.reserved_quantity), | |
| 0) AS total_reserved | |
| FROM product_product pp | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| LEFT JOIN stock_quant sq ON sq.product_id = pp.id | |
| GROUP BY pp.id, pt.name | |
| ORDER BY total_reserved DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-082 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Display the number of stock moves for each product. | |
| gold_sql: 'SELECT pp.id AS product_id, COALESCE(COUNT(sm.id), 0) AS stock_move_count | |
| FROM product_product pp | |
| LEFT JOIN stock_move sm ON sm.product_id = pp.id | |
| GROUP BY pp.id | |
| ORDER BY stock_move_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-083 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Retrieve each warehouse and the number of products it has in stock. | |
| gold_sql: 'SELECT w.name AS warehouse, COUNT(DISTINCT sq.product_id) AS product_count | |
| FROM stock_warehouse w | |
| LEFT JOIN stock_quant sq ON sq.location_id = w.wh_input_stock_loc_id | |
| GROUP BY w.id, w.name | |
| ORDER BY product_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L3-075 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Find the average price of products sold in the last year by product. | |
| gold_sql: "SELECT pp.id AS product_id, AVG(sol.price_unit) AS average_price\nFROM\ | |
| \ sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nWHERE so.state IN ('sale', 'done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pp.id\nORDER BY average_price DESC;\n" | |
| tags: | |
| - demand | |
| - temporal | |
| - aggregation | |
| - id: L3-076 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Determine the total revenue generated from orders for each partner this year. | |
| gold_sql: "SELECT rp.id AS partner_id, SUM(so.amount_total) AS total_revenue\nFROM\ | |
| \ sale_order so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state\ | |
| \ IN ('sale', 'done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rp.id\nORDER BY total_revenue DESC;\n" | |
| tags: | |
| - demand | |
| - temporal | |
| - aggregation | |
| - id: L3-077 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Show the total number of invoices and their average amount by company this year. | |
| gold_sql: "SELECT rc.name AS company,\n COUNT(am.id) AS invoice_count,\n \ | |
| \ AVG(am.amount_total) AS avg_invoice_amount\nFROM account_move am\nJOIN\ | |
| \ res_company rc ON rc.id = am.company_id\nWHERE am.move_type = 'out_invoice'\n\ | |
| \ AND am.state = 'posted'\n AND am.date >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rc.id, rc.name\nORDER BY avg_invoice_amount DESC;\n" | |
| tags: | |
| - finance | |
| - temporal | |
| - average | |
| - id: L3-078 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Compare total sales with total purchases for each partner this year. | |
| gold_sql: "SELECT rp.name AS partner,\n COALESCE(sales.total_sales, 0) AS\ | |
| \ total_sales,\n COALESCE(purchases.total_purchases, 0) AS total_purchases\n\ | |
| FROM res_partner rp\nLEFT JOIN (\n SELECT partner_id,\n SUM(amount_total)\ | |
| \ AS total_sales\n FROM account_move\n WHERE move_type = 'out_invoice'\n\ | |
| \ AND state = 'posted'\n AND date >= date_trunc('year', NOW())\n \ | |
| \ GROUP BY partner_id\n) sales ON sales.partner_id = rp.id\nLEFT JOIN (\n SELECT\ | |
| \ partner_id,\n SUM(amount_total) AS total_purchases\n FROM account_move\n\ | |
| \ WHERE move_type = 'in_invoice'\n AND state = 'posted'\n AND date\ | |
| \ >= date_trunc('year', NOW())\n GROUP BY partner_id\n) purchases ON purchases.partner_id\ | |
| \ = rp.id\nORDER BY partner;\n" | |
| tags: | |
| - finance | |
| - temporal | |
| - comparison | |
| - id: L3-079 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of products that are reserved in stock for each product | |
| ID. | |
| gold_sql: 'SELECT product_id, SUM(reserved_quantity) AS total_reserved | |
| FROM stock_quant | |
| GROUP BY product_id; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-080 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show the total quantity of products in stock along with their respective locations. | |
| gold_sql: 'SELECT sq.location_id, sq.product_id, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| GROUP BY sq.location_id, sq.product_id; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-081 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Find the average price per unit of products from suppliers for orders placed | |
| last year. | |
| gold_sql: "SELECT rp.name AS supplier, AVG(pol.price_unit) AS average_price\nFROM\ | |
| \ purchase_order_line pol\nJOIN purchase_order po ON po.id = pol.order_id\nJOIN\ | |
| \ res_partner rp ON rp.id = po.partner_id\nWHERE po.date_order >= date_trunc('year',\ | |
| \ NOW()) - INTERVAL '1 year'\n AND po.state IN ('purchase','done')\nGROUP BY\ | |
| \ rp.id, rp.name\nORDER BY average_price ASC;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - id: L3-082 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Display the total invoice count for each supplier for orders made in the last | |
| 6 months. | |
| gold_sql: "SELECT rp.name AS supplier, COUNT(po.invoice_count) AS total_invoices\n\ | |
| FROM purchase_order po\nJOIN res_partner rp ON rp.id = po.partner_id\nWHERE po.date_order\ | |
| \ >= NOW() - INTERVAL '6 months'\n AND po.state IN ('purchase','done')\nGROUP\ | |
| \ BY rp.id, rp.name\nORDER BY total_invoices DESC;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - id: L4-029 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: Identify the top 5 accounts by total balance as of today. | |
| gold_sql: "SELECT aa.name AS account,\n SUM(aml.balance) AS total_balance\n\ | |
| FROM account_account aa\nJOIN account_move_line aml ON aml.account_id = aa.id\n\ | |
| WHERE aml.date <= NOW()\nGROUP BY aa.id, aa.name\nORDER BY total_balance DESC\n\ | |
| LIMIT 5;\n" | |
| tags: | |
| - top_accounts | |
| - balance_summary | |
| - id: L4-030 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Calculate the average reserved quantity of products per location and rank them. | |
| gold_sql: "SELECT sl.name AS location_name,\n AVG(sq.reserved_quantity) AS\ | |
| \ avg_reserved_quantity,\n RANK() OVER (ORDER BY AVG(sq.reserved_quantity)\ | |
| \ DESC) AS rank\nFROM stock_quant sq\nJOIN stock_location sl ON sl.id = sq.location_id\n\ | |
| GROUP BY sl.name\nORDER BY rank;\n" | |
| tags: | |
| - inventory | |
| - average | |
| - id: L4-031 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Rank warehouse locations based on the total inventory difference quantity. | |
| gold_sql: "SELECT sl.name AS location_name,\n SUM(sq.inventory_diff_quantity)\ | |
| \ AS total_inventory_diff,\n RANK() OVER (ORDER BY SUM(sq.inventory_diff_quantity)\ | |
| \ DESC) AS rank\nFROM stock_quant sq\nJOIN stock_location sl ON sl.id = sq.location_id\n\ | |
| GROUP BY sl.name\nORDER BY rank;\n" | |
| tags: | |
| - inventory | |
| - warehouse | |
| - id: L5-029 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Identify the top 3 sales teams based on total revenue generated this year. | |
| gold_sql: "WITH team_revenue AS (\n SELECT ct.id AS team_id,\n SUM(sol.price_unit\ | |
| \ * sol.product_uom_qty) AS total_revenue\n FROM sale_order so\n JOIN sale_order_line\ | |
| \ sol ON so.id = sol.order_id\n JOIN crm_team ct ON ct.id = so.team_id\n WHERE\ | |
| \ so.state IN ('sale', 'done')\n AND so.date_order >= date_trunc('year', NOW())\n\ | |
| \ GROUP BY ct.id\n)\nSELECT ct.name AS team_name,\n tr.total_revenue\n\ | |
| FROM team_revenue tr\nJOIN crm_team ct ON ct.id = tr.team_id\nORDER BY total_revenue\ | |
| \ DESC\nLIMIT 3;\n" | |
| tags: | |
| - performance | |
| - sales | |
| - id: L5-030 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Analyze the sales trend by month for the last six months. | |
| gold_sql: "WITH monthly_sales AS (\n SELECT date_trunc('month', so.date_order)\ | |
| \ AS month,\n SUM(sol.price_unit * sol.product_uom_qty) AS total_sales\n\ | |
| \ FROM sale_order so\n JOIN sale_order_line sol ON so.id = sol.order_id\n WHERE\ | |
| \ so.state IN ('sale', 'done')\n AND so.date_order >= date_trunc('month', NOW())\ | |
| \ - INTERVAL '6 months'\n GROUP BY month\n)\nSELECT month,\n total_sales,\n\ | |
| \ LAG(total_sales) OVER (ORDER BY month) AS previous_month_sales\nFROM monthly_sales\n\ | |
| ORDER BY month;\n" | |
| tags: | |
| - trend | |
| - analysis | |
| - id: L5-031 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Determine the average payment terms for each partner this year. | |
| gold_sql: "WITH payment_terms AS (\n SELECT rp.id AS partner_id,\n AVG(am.invoice_payment_term_id)\ | |
| \ AS avg_payment_term\n FROM res_partner rp\n JOIN account_move am ON am.partner_id\ | |
| \ = rp.id\n WHERE am.date >= date_trunc('year', NOW())\n AND am.state = 'posted'\n\ | |
| \ GROUP BY rp.id\n)\nSELECT rp.name AS partner_name,\n pt.avg_payment_term\n\ | |
| FROM payment_terms pt\nJOIN res_partner rp ON rp.id = pt.partner_id;\n" | |
| tags: | |
| - finance | |
| - average | |
| - partner | |
| - id: L5-032 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Identify the top 3 partners with the highest total payments this year. | |
| gold_sql: "WITH total_payments AS (\n SELECT rp.id AS partner_id,\n SUM(am.amount_total)\ | |
| \ AS total_payment\n FROM account_move am\n JOIN res_partner rp ON rp.id = am.partner_id\n\ | |
| \ WHERE am.date >= date_trunc('year', NOW())\n AND am.state = 'posted'\n \ | |
| \ GROUP BY rp.id\n)\nSELECT rp.name AS partner_name,\n tp.total_payment\n\ | |
| FROM total_payments tp\nJOIN res_partner rp ON rp.id = tp.partner_id\nORDER BY\ | |
| \ tp.total_payment DESC\nLIMIT 3;\n" | |
| tags: | |
| - finance | |
| - payments | |
| - ranking | |
| - id: L5-033 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Which suppliers have the highest average order value this year? | |
| gold_sql: "WITH supplier_order_values AS (\n SELECT po.partner_id, AVG(po.amount_total)\ | |
| \ AS avg_order_value\n FROM purchase_order po\n WHERE po.state IN ('purchase',\ | |
| \ 'done')\n AND po.date_order >= date_trunc('year', NOW())\n GROUP BY\ | |
| \ po.partner_id\n)\nSELECT rp.name AS supplier, sov.avg_order_value\nFROM supplier_order_values\ | |
| \ sov\nJOIN res_partner rp ON rp.id = sov.partner_id\nORDER BY sov.avg_order_value\ | |
| \ DESC\nLIMIT 10;\n" | |
| tags: | |
| - supplier_performance | |
| - financial | |
| - id: L5-034 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Calculate the total spend by each supplier with a breakdown of order counts. | |
| gold_sql: "WITH supplier_spend AS (\n SELECT po.partner_id, SUM(po.amount_total)\ | |
| \ AS total_spend, COUNT(po.id) AS order_count\n FROM purchase_order po\n \ | |
| \ WHERE po.state IN ('purchase', 'done')\n GROUP BY po.partner_id\n)\nSELECT\ | |
| \ rp.name AS supplier, ss.total_spend, ss.order_count\nFROM supplier_spend ss\n\ | |
| JOIN res_partner rp ON rp.id = ss.partner_id\nORDER BY ss.total_spend DESC;\n" | |
| tags: | |
| - financial | |
| - supplier_analysis | |
| - id: L1-084 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: List all products with a quantity greater than zero. | |
| gold_sql: 'SELECT product_id, quantity | |
| FROM stock_quant | |
| WHERE quantity > 0; | |
| ' | |
| tags: | |
| - filter | |
| - inventory | |
| - id: L2-084 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List sale orders and their associated product categories. | |
| gold_sql: 'SELECT so.id, so.name, pc.name AS category_name | |
| FROM sale_order so | |
| JOIN sale_order_line sol ON sol.order_id = so.id | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-085 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Retrieve all journal entries along with their associated partners. | |
| gold_sql: 'SELECT am.id, am.name, rp.name AS partner_name | |
| FROM account_move am | |
| JOIN res_partner rp ON rp.id = am.partner_id | |
| WHERE am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-086 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List account moves with their journal type and company name. | |
| gold_sql: 'SELECT am.id, am.name, aj.type AS journal_type, rc.name AS company_name | |
| FROM account_move am | |
| JOIN account_journal aj ON aj.id = am.journal_id | |
| JOIN res_company rc ON rc.id = am.company_id | |
| WHERE am.state = ''posted'' | |
| ORDER BY am.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-087 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Show the total amount of account moves grouped by currency. | |
| gold_sql: 'SELECT rc.name AS currency, SUM(am.amount_total) AS total_amount | |
| FROM account_move am | |
| JOIN res_currency rc ON rc.id = am.currency_id | |
| WHERE am.state = ''posted'' | |
| GROUP BY rc.name | |
| ORDER BY total_amount DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-088 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: Get the count of account lines per partner in each company. | |
| gold_sql: 'SELECT rc.name AS company_name, rp.name AS partner_name, COUNT(aml.id) | |
| AS line_count | |
| FROM account_move_line aml | |
| JOIN account_move am ON am.id = aml.move_id | |
| JOIN res_partner rp ON rp.id = am.partner_id | |
| JOIN res_company rc ON rc.id = am.company_id | |
| WHERE am.state = ''posted'' | |
| GROUP BY rc.name, rp.name | |
| ORDER BY company_name, partner_name; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L4-032 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: Show the total amount invoiced by each customer along with their respective | |
| company names. | |
| gold_sql: "WITH invoiced_amount AS (\n SELECT am.partner_id, SUM(am.amount_total)\ | |
| \ AS total_invoiced\n FROM account_move am\n WHERE am.move_type = 'out_invoice'\n\ | |
| \ AND am.state = 'posted'\n GROUP BY am.partner_id\n)\nSELECT rp.name AS customer_name,\ | |
| \ rc.name AS company_name, COALESCE(ia.total_invoiced, 0) AS total_invoiced\n\ | |
| FROM res_partner rp\nJOIN res_company rc ON rc.id = rp.company_id\nLEFT JOIN invoiced_amount\ | |
| \ ia ON ia.partner_id = rp.id\nORDER BY total_invoiced DESC;\n" | |
| tags: | |
| - federation_stub | |
| - cte_single | |
| - id: L4-033 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: Calculate the average invoice amount for each partner this year, grouped by | |
| company. | |
| gold_sql: "WITH invoice_data AS (\n SELECT am.partner_id, am.company_id, AVG(am.amount_total)\ | |
| \ AS avg_invoice_amount\n FROM account_move am\n WHERE am.move_type = 'out_invoice'\n\ | |
| \ AND am.state = 'posted'\n AND am.date >= date_trunc('year', NOW())\n \ | |
| \ GROUP BY am.partner_id, am.company_id\n)\nSELECT rp.name AS partner_name, rc.name\ | |
| \ AS company_name, COALESCE(id.avg_invoice_amount, 0) AS avg_invoice\nFROM res_partner\ | |
| \ rp\nJOIN res_company rc ON rc.id = rp.company_id\nLEFT JOIN invoice_data id\ | |
| \ ON id.partner_id = rp.id AND id.company_id = rc.id\nORDER BY avg_invoice DESC;\n" | |
| tags: | |
| - federation_stub | |
| - cte_dual | |
| - id: L4-034 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: Show the maximum invoice amount for each partner along with their company names. | |
| gold_sql: "WITH max_invoices AS (\n SELECT am.partner_id, MAX(am.amount_total)\ | |
| \ AS max_invoice\n FROM account_move am\n WHERE am.move_type = 'out_invoice'\n\ | |
| \ AND am.state = 'posted'\n GROUP BY am.partner_id\n)\nSELECT rp.name AS partner_name,\ | |
| \ rc.name AS company_name, COALESCE(mi.max_invoice, 0) AS max_invoice_amount\n\ | |
| FROM res_partner rp\nJOIN res_company rc ON rc.id = rp.company_id\nLEFT JOIN max_invoices\ | |
| \ mi ON mi.partner_id = rp.id\nORDER BY max_invoice_amount DESC;\n" | |
| tags: | |
| - federation_stub | |
| - cte_dual | |
| - id: L1-085 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders are associated with each campaign? | |
| gold_sql: 'SELECT campaign_id, COUNT(*) AS orders_per_campaign | |
| FROM sale_order | |
| GROUP BY campaign_id; | |
| ' | |
| tags: | |
| - aggregate | |
| - group_by | |
| - id: L1-086 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many unique partners are associated with journal entries? | |
| gold_sql: 'SELECT COUNT(DISTINCT partner_id) AS unique_partners | |
| FROM account_move_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - distinct | |
| - id: L1-087 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: Count the number of accounts that are marked as deprecated. | |
| gold_sql: 'SELECT COUNT(*) AS deprecated_accounts | |
| FROM account_account | |
| WHERE deprecated = TRUE; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-088 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: How many unique products are in stock? | |
| gold_sql: 'SELECT COUNT(DISTINCT product_id) AS unique_products FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - count | |
| - id: L1-089 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: List all stock quantities for products in a specific location. | |
| gold_sql: 'SELECT product_id, quantity FROM stock_quant WHERE location_id IS NOT | |
| NULL; | |
| ' | |
| tags: | |
| - listing | |
| - filter | |
| - id: L1-090 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the minimum quantity available for any product? | |
| gold_sql: 'SELECT MIN(quantity) AS minimum_quantity FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - min | |
| - id: L1-091 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many stock moves are in transit? | |
| gold_sql: 'SELECT COUNT(*) AS in_transit_moves | |
| FROM stock_move | |
| WHERE state = ''in_transit''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-092 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the number of purchase orders with more than 1 invoice. | |
| gold_sql: 'SELECT COUNT(*) AS multiple_invoice_pos | |
| FROM purchase_order | |
| WHERE invoice_count > 1; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-093 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: How many products are being moved in total? | |
| gold_sql: 'SELECT SUM(product_qty) AS total_product_qty | |
| FROM purchase_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L1-094 | |
| level: 1 | |
| domains: | |
| - logistics | |
| nl: Count the number of stock pickings with priority high. | |
| gold_sql: 'SELECT COUNT(*) AS high_priority_pickings | |
| FROM stock_picking | |
| WHERE priority = ''high''; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L2-089 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Show the total number of sale orders per customer. | |
| gold_sql: 'SELECT rp.name AS customer, COUNT(so.id) AS total_orders | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| GROUP BY rp.id, rp.name | |
| ORDER BY total_orders DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-090 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Display the total revenue from sale orders by product category. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sol.price_unit * sol.product_uom_qty) | |
| AS total_revenue | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| JOIN sale_order so ON so.id = sol.order_id | |
| WHERE so.state IN (''sale'', ''done'') | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_revenue DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-091 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: Get the count of sale orders by sales team. | |
| gold_sql: 'SELECT ct.name AS sales_team, COUNT(so.id) AS order_count | |
| FROM sale_order so | |
| JOIN crm_team ct ON ct.id = so.team_id | |
| GROUP BY ct.id, ct.name | |
| ORDER BY order_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-092 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show the purchase orders along with the names of the partners. | |
| gold_sql: 'SELECT po.id, po.name, rp.name AS partner_name | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - join | |
| - multi_join | |
| - id: L2-093 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Count the number of stock moves for each product. | |
| gold_sql: 'SELECT pp.id, COUNT(sm.id) AS move_count | |
| FROM product_product pp | |
| LEFT JOIN stock_move sm ON sm.product_id = pp.id | |
| GROUP BY pp.id | |
| ORDER BY move_count DESC; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-094 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Show purchase orders with their invoice count and partner names. | |
| gold_sql: 'SELECT po.id, po.invoice_count, rp.name AS partner_name | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| ORDER BY po.id; | |
| ' | |
| tags: | |
| - join | |
| - multi_join | |
| - id: L3-083 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Find the total revenue generated from orders that were created in the last quarter. | |
| gold_sql: "SELECT SUM(sol.price_unit * sol.product_uom_qty) AS total_revenue\nFROM\ | |
| \ sale_order so\nJOIN sale_order_line sol ON so.id = sol.order_id\nWHERE so.date_order\ | |
| \ >= date_trunc('quarter', NOW()) - INTERVAL '3 months'\n AND so.date_order <\ | |
| \ date_trunc('quarter', NOW())\n AND so.state IN ('sale','done');\n" | |
| tags: | |
| - demand | |
| - temporal | |
| - revenue | |
| - id: L3-084 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Show the average quantity sold per order for each product in the last six months. | |
| gold_sql: "SELECT pp.id, pt.name, AVG(sol.product_uom_qty) AS avg_quantity\nFROM\ | |
| \ sale_order_line sol\nJOIN sale_order so ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON sol.product_id = pp.id\nJOIN product_template pt ON pp.product_tmpl_id\ | |
| \ = pt.id\nWHERE so.date_order >= date_trunc('month', NOW()) - INTERVAL '6 months'\n\ | |
| \ AND so.state IN ('sale','done')\nGROUP BY pp.id, pt.name;\n" | |
| tags: | |
| - demand | |
| - aggregation | |
| - temporal | |
| - id: L3-085 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Identify the top 5 customers by total order amount in the last year. | |
| gold_sql: "SELECT rp.id, rp.name, SUM(so.amount_total) AS total_amount\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON so.partner_id = rp.id\nWHERE so.date_order >= date_trunc('year',\ | |
| \ NOW()) - INTERVAL '1 year'\n AND so.state IN ('sale','done')\nGROUP BY rp.id,\ | |
| \ rp.name\nORDER BY total_amount DESC\nLIMIT 5;\n" | |
| tags: | |
| - demand | |
| - customer | |
| - temporal | |
| - id: L3-086 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Show the total amount of invoices grouped by currency. | |
| gold_sql: "SELECT rc.name AS currency_name,\n SUM(am.amount_total) AS total_invoices\n\ | |
| FROM account_move am\nJOIN res_currency rc ON rc.id = am.currency_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\nGROUP BY rc.name\nORDER BY total_invoices DESC;\n" | |
| tags: | |
| - aggregate | |
| - currency | |
| - id: L3-087 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Display the average invoice amount for each company. | |
| gold_sql: "SELECT rc.name AS company_name,\n AVG(am.amount_total) AS average_invoice\n\ | |
| FROM account_move am\nJOIN res_company rc ON rc.id = am.company_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\nGROUP BY rc.name\nORDER BY average_invoice DESC;\n" | |
| tags: | |
| - aggregate | |
| - company | |
| - id: L3-088 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the total reserved quantity for each product across all warehouses. | |
| gold_sql: 'SELECT pp.default_code AS product_code, SUM(sq.reserved_quantity) AS | |
| total_reserved | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| GROUP BY pp.default_code | |
| ORDER BY total_reserved DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregation | |
| - id: L3-089 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List all products with their total inventory quantity grouped by their storage | |
| category. | |
| gold_sql: 'SELECT pc.complete_name AS storage_category, pp.default_code AS product_code, | |
| SUM(sq.inventory_quantity) AS total_inventory | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| JOIN stock_warehouse w ON w.id = sl.warehouse_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| GROUP BY pc.complete_name, pp.default_code | |
| ORDER BY storage_category, total_inventory DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - group_by_two | |
| - id: L3-090 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Which products have been ordered but not yet delivered? | |
| gold_sql: "SELECT pp.default_code AS product_code,\n COUNT(po.id) AS pending_orders\n\ | |
| FROM purchase_order po\nJOIN purchase_order_line pol ON pol.order_id = po.id\n\ | |
| JOIN product_product pp ON pp.id = pol.product_id\nWHERE po.state <> 'done'\n\ | |
| GROUP BY pp.default_code;\n" | |
| tags: | |
| - logistics | |
| - pending_orders | |
| - id: L3-091 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: List the suppliers and the total invoice count for each. | |
| gold_sql: "SELECT rp.name AS supplier,\n COUNT(po.invoice_count) AS total_invoices\n\ | |
| FROM purchase_order po\nJOIN res_partner rp ON rp.id = po.partner_id\nGROUP BY\ | |
| \ rp.name;\n" | |
| tags: | |
| - logistics | |
| - supplier_invoices | |
| - id: L4-035 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Show the average order value by product category for this year. | |
| gold_sql: "WITH category_sales AS (\n SELECT pt.categ_id, AVG(so.amount_total)\ | |
| \ AS avg_order_value\n FROM sale_order so\n JOIN sale_order_line sol ON so.id\ | |
| \ = sol.order_id\n JOIN product_product pp ON sol.product_id = pp.id\n JOIN\ | |
| \ product_template pt ON pp.product_tmpl_id = pt.id\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY pt.categ_id\n\ | |
| )\nSELECT pc.name AS category,\n cs.avg_order_value\nFROM product_category\ | |
| \ pc\nJOIN category_sales cs ON cs.categ_id = pc.id\nORDER BY avg_order_value\ | |
| \ DESC NULLS LAST\nLIMIT 20;\n" | |
| tags: | |
| - category_analysis | |
| - financial_metrics | |
| - id: L4-036 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: List the average quantity of stock available in each location for the current | |
| month. | |
| gold_sql: "SELECT sl.name AS location,\n AVG(sq.quantity) AS avg_quantity\n\ | |
| FROM stock_quant sq\nJOIN stock_location sl ON sl.id = sq.location_id\nWHERE sq.inventory_date\ | |
| \ >= date_trunc('month', NOW())\nGROUP BY sl.id, sl.name\nORDER BY avg_quantity\ | |
| \ DESC;\n" | |
| tags: | |
| - inventory | |
| - location_performance | |
| - id: L4-037 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Identify the top 5 products with the highest reserved quantity this quarter. | |
| gold_sql: "SELECT pp.id AS product_id,\n pt.name->>'en_US' AS product_name,\n\ | |
| \ SUM(sq.reserved_quantity) AS total_reserved\nFROM stock_quant sq\nJOIN\ | |
| \ product_product pp ON pp.id = sq.product_id\nJOIN product_template pt ON pt.id\ | |
| \ = pp.product_tmpl_id\nWHERE sq.inventory_date >= date_trunc('quarter', NOW())\n\ | |
| GROUP BY pp.id, pt.name\nORDER BY total_reserved DESC\nLIMIT 5;\n" | |
| tags: | |
| - inventory | |
| - product_analysis | |
| - id: L4-038 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Calculate the average inventory difference for products across all warehouses | |
| for the last year. | |
| gold_sql: "SELECT pp.id AS product_id,\n pt.name->>'en_US' AS product_name,\n\ | |
| \ AVG(sq.inventory_diff_quantity) AS avg_inventory_diff\nFROM stock_quant\ | |
| \ sq\nJOIN product_product pp ON pp.id = sq.product_id\nJOIN product_template\ | |
| \ pt ON pt.id = pp.product_tmpl_id\nWHERE sq.inventory_date >= date_trunc('year',\ | |
| \ NOW()) - interval '1 year'\nGROUP BY pp.id, pt.name\nORDER BY avg_inventory_diff\ | |
| \ DESC;\n" | |
| tags: | |
| - inventory | |
| - yearly_analysis | |
| - id: L4-039 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: List the total quantity and average price per product received this year. | |
| gold_sql: "WITH received AS (\n SELECT sm.product_id, SUM(sm.product_qty) AS total_qty,\ | |
| \ AVG(pol.price_unit) AS avg_price\n FROM stock_move sm\n JOIN purchase_order_line\ | |
| \ pol ON pol.product_id = sm.product_id\n JOIN purchase_order po ON po.id = pol.order_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n AND po.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY sm.product_id\n)\nSELECT pp.default_code AS product_code,\ | |
| \ r.total_qty, r.avg_price\nFROM received r\nJOIN product_product pp ON pp.id\ | |
| \ = r.product_id\nORDER BY r.total_qty DESC;\n" | |
| tags: | |
| - product_performance | |
| - cte_aggregation | |
| - id: L4-040 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Show the average number of products received per purchase order this year. | |
| gold_sql: "WITH order_summary AS (\n SELECT po.id AS order_id, COUNT(pol.id) AS\ | |
| \ product_count\n FROM purchase_order po\n JOIN purchase_order_line pol ON pol.order_id\ | |
| \ = po.id\n WHERE po.state IN ('purchase','done')\n AND po.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY po.id\n)\nSELECT AVG(os.product_count) AS avg_products_received\n\ | |
| FROM order_summary os;\n" | |
| tags: | |
| - purchase_analysis | |
| - average_calculation | |
| - id: L4-041 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Identify the top suppliers based on the total quantity of products ordered this | |
| year. | |
| gold_sql: "WITH supplier_orders AS (\n SELECT po.partner_id, SUM(pol.product_qty)\ | |
| \ AS total_ordered\n FROM purchase_order po\n JOIN purchase_order_line pol ON\ | |
| \ pol.order_id = po.id\n WHERE po.state IN ('purchase','done')\n AND po.date_order\ | |
| \ >= date_trunc('year', NOW())\n GROUP BY po.partner_id\n)\nSELECT rp.name AS\ | |
| \ supplier_name, so.total_ordered\nFROM supplier_orders so\nJOIN res_partner rp\ | |
| \ ON rp.id = so.partner_id\nORDER BY so.total_ordered DESC;\n" | |
| tags: | |
| - supplier_analysis | |
| - order_volume | |
| - id: L5-035 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Determine the average order value for each sales team in the last year. | |
| gold_sql: "WITH team_order_value AS (\n SELECT st.id AS team_id,\n AVG(so.amount_total)\ | |
| \ AS avg_order_value\n FROM sale_order so\n JOIN crm_team st ON st.id = so.team_id\n\ | |
| \ WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW()) - INTERVAL '1 year'\n GROUP BY st.id\n)\nSELECT st.name AS sales_team,\n\ | |
| \ COALESCE(tov.avg_order_value, 0) AS avg_order_value\nFROM crm_team st\n\ | |
| LEFT JOIN team_order_value tov ON tov.team_id = st.id\nORDER BY avg_order_value\ | |
| \ DESC;\n" | |
| tags: | |
| - financial | |
| - team_performance | |
| - id: L5-036 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Identify top 5 customers by total revenue and order count over the past year. | |
| gold_sql: "WITH customer_revenue AS (\n SELECT rp.id AS customer_id,\n \ | |
| \ SUM(so.amount_total) AS total_revenue,\n COUNT(so.id) AS order_count\n\ | |
| \ FROM sale_order so\n JOIN res_partner rp ON rp.id = so.partner_id\n WHERE\ | |
| \ so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW())\ | |
| \ - INTERVAL '1 year'\n GROUP BY rp.id\n)\nSELECT rp.name AS customer,\n \ | |
| \ cr.total_revenue,\n cr.order_count\nFROM res_partner rp\nJOIN customer_revenue\ | |
| \ cr ON cr.customer_id = rp.id\nORDER BY cr.total_revenue DESC\nLIMIT 5;\n" | |
| tags: | |
| - predictive | |
| - customer_analysis | |
| - id: L5-037 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Analyze the sales performance of products in the last six months compared to | |
| the previous six months. | |
| gold_sql: "WITH sales_comparison AS (\n SELECT pp.id AS product_id,\n SUM(CASE\ | |
| \ WHEN so.date_order >= date_trunc('month', NOW()) - INTERVAL '6 months' THEN\ | |
| \ sol.product_uom_qty ELSE 0 END) AS last_six_months,\n SUM(CASE WHEN\ | |
| \ so.date_order < date_trunc('month', NOW()) - INTERVAL '6 months' THEN sol.product_uom_qty\ | |
| \ ELSE 0 END) AS previous_six_months\n FROM sale_order_line sol\n JOIN sale_order\ | |
| \ so ON so.id = sol.order_id\n JOIN product_product pp ON pp.id = sol.product_id\n\ | |
| \ WHERE so.state IN ('sale','done')\n GROUP BY pp.id\n)\nSELECT pt.name->>'en_US'\ | |
| \ AS product,\n sc.last_six_months,\n sc.previous_six_months\nFROM\ | |
| \ product_product pp\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN sales_comparison sc ON sc.product_id = pp.id\nORDER BY last_six_months DESC;\n" | |
| tags: | |
| - performance | |
| - product_analysis | |
| - id: L5-038 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Assess the total revenue generated by each product in the last six months. | |
| gold_sql: "WITH product_revenue AS (\n SELECT product_id, SUM(price_subtotal) AS\ | |
| \ total_revenue\n FROM account_move_line\n WHERE date >= NOW() - INTERVAL '6\ | |
| \ months'\n GROUP BY product_id\n)\nSELECT rp.name AS product_name, pr.total_revenue\n\ | |
| FROM product_revenue pr\nJOIN product_product pp ON pp.id = pr.product_id\nJOIN\ | |
| \ product_template rp ON rp.id = pp.product_tmpl_id\nORDER BY pr.total_revenue\ | |
| \ DESC;\n" | |
| tags: | |
| - financial | |
| - revenue | |
| - id: L5-039 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: What is the total quantity of products stored in each warehouse? | |
| gold_sql: "WITH warehouse_stock AS (\n SELECT sw.id AS warehouse_id,\n \ | |
| \ SUM(sq.quantity) AS total_quantity\n FROM stock_quant sq\n JOIN stock_warehouse\ | |
| \ sw ON sw.id = sq.company_id\n GROUP BY sw.id\n)\nSELECT sw.name AS warehouse_name,\n\ | |
| \ ws.total_quantity\nFROM warehouse_stock ws\nJOIN stock_warehouse sw ON\ | |
| \ sw.id = ws.warehouse_id\nORDER BY ws.total_quantity DESC;\n" | |
| tags: | |
| - inventory | |
| - warehouse | |
| - id: L5-040 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: List products with the highest reserved quantities in stock. | |
| gold_sql: "WITH reserved_stock AS (\n SELECT product_id,\n SUM(reserved_quantity)\ | |
| \ AS total_reserved\n FROM stock_quant\n GROUP BY product_id\n)\nSELECT pp.id\ | |
| \ AS product_id,\n pt.name->>'en_US' AS product_name,\n rs.total_reserved\n\ | |
| FROM reserved_stock rs\nJOIN product_product pp ON pp.id = rs.product_id\nJOIN\ | |
| \ product_template pt ON pt.id = pp.product_tmpl_id\nORDER BY rs.total_reserved\ | |
| \ DESC;\n" | |
| tags: | |
| - inventory | |
| - reserved | |
| - id: L5-041 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Which products have the most inventory discrepancies recorded? | |
| gold_sql: "WITH inventory_discrepancies AS (\n SELECT product_id,\n COUNT(inventory_diff_quantity)\ | |
| \ AS discrepancy_count\n FROM stock_quant\n WHERE inventory_diff_quantity <>\ | |
| \ 0\n GROUP BY product_id\n)\nSELECT pp.id AS product_id,\n pt.name->>'en_US'\ | |
| \ AS product_name,\n id.discrepancy_count\nFROM inventory_discrepancies\ | |
| \ id\nJOIN product_product pp ON pp.id = id.product_id\nJOIN product_template\ | |
| \ pt ON pt.id = pp.product_tmpl_id\nORDER BY id.discrepancy_count DESC;\n" | |
| tags: | |
| - inventory | |
| - discrepancy | |
| - id: L5-042 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Analyze the average delivery time for each supplier over the last year. | |
| gold_sql: "WITH delivery_times AS (\n SELECT po.partner_id,\n AVG(EXTRACT(EPOCH\ | |
| \ FROM (sp.scheduled_date - po.date_order)) / 3600) AS avg_delivery_time\n \ | |
| \ FROM purchase_order po\n JOIN stock_picking sp ON sp.origin = po.name\n \ | |
| \ WHERE po.date_order >= NOW() - INTERVAL '1 year'\n GROUP BY po.partner_id\n\ | |
| )\nSELECT rp.name AS supplier, dt.avg_delivery_time\nFROM delivery_times dt\n\ | |
| JOIN res_partner rp ON rp.id = dt.partner_id\nORDER BY dt.avg_delivery_time DESC;\n" | |
| tags: | |
| - analysis | |
| - supplier_performance | |
| - id: L5-043 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Identify the top three products with the highest total spend from suppliers | |
| this year. | |
| gold_sql: "WITH product_spend AS (\n SELECT pol.product_id,\n SUM(pol.price_subtotal)\ | |
| \ AS total_spend\n FROM purchase_order_line pol\n JOIN purchase_order po\ | |
| \ ON po.id = pol.order_id\n WHERE po.date_order >= date_trunc('year', NOW())\n\ | |
| \ GROUP BY pol.product_id\n)\nSELECT pp.default_code AS product_code, ps.total_spend\n\ | |
| FROM product_spend ps\nJOIN product_product pp ON pp.id = ps.product_id\nORDER\ | |
| \ BY ps.total_spend DESC\nLIMIT 3;\n" | |
| tags: | |
| - spend_analysis | |
| - top_products | |
| - id: L5-044 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: Assess the total number of purchase orders by state for each supplier in the | |
| last six months. | |
| gold_sql: "WITH order_counts AS (\n SELECT po.partner_id,\n po.state,\n\ | |
| \ COUNT(po.id) AS order_count\n FROM purchase_order po\n WHERE\ | |
| \ po.date_order >= NOW() - INTERVAL '6 months'\n GROUP BY po.partner_id, po.state\n\ | |
| )\nSELECT rp.name AS supplier, oc.state, oc.order_count\nFROM order_counts oc\n\ | |
| JOIN res_partner rp ON rp.id = oc.partner_id\nORDER BY rp.name, oc.state;\n" | |
| tags: | |
| - order_analysis | |
| - supplier_insights | |
| - id: L1-095 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders were created? | |
| gold_sql: 'SELECT COUNT(*) AS total_orders | |
| FROM sale_order; | |
| ' | |
| tags: | |
| - aggregate | |
| - id: L1-096 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many distinct products have been sold? | |
| gold_sql: 'SELECT COUNT(DISTINCT product_id) AS unique_products | |
| FROM sale_order_line; | |
| ' | |
| tags: | |
| - aggregate | |
| - distinct | |
| - id: L1-097 | |
| level: 1 | |
| domains: | |
| - demand | |
| nl: How many sale orders are in the 'draft' state? | |
| gold_sql: 'SELECT COUNT(*) AS draft_orders | |
| FROM sale_order | |
| WHERE state = ''draft''; | |
| ' | |
| tags: | |
| - aggregate | |
| - state | |
| - id: L2-095 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: List the quantities of products in stock across different locations. | |
| gold_sql: 'SELECT pp.default_code AS product_code, sl.name AS location, SUM(sq.quantity) | |
| AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| GROUP BY pp.default_code, sl.name | |
| ORDER BY pp.default_code, sl.name; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-096 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Show the total reserved quantity of products by warehouse. | |
| gold_sql: 'SELECT sw.id AS warehouse_id, SUM(sq.reserved_quantity) AS total_reserved | |
| FROM stock_quant sq | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| JOIN stock_warehouse sw ON sw.id = sl.warehouse_id | |
| GROUP BY sw.id | |
| ORDER BY sw.id; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L2-097 | |
| level: 2 | |
| domains: | |
| - inventory | |
| nl: Get the list of products and their total inventory quantity, grouped by product. | |
| gold_sql: 'SELECT pp.default_code AS product_code, SUM(sq.inventory_quantity) AS | |
| total_inventory | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| GROUP BY pp.default_code | |
| ORDER BY pp.default_code; | |
| ' | |
| tags: | |
| - join | |
| - aggregate | |
| - id: L4-042 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Determine the number of unique customers who made purchases this year. | |
| gold_sql: "WITH unique_customers AS (\n SELECT DISTINCT so.partner_id\n FROM sale_order\ | |
| \ so\n WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n)\nSELECT COUNT(*) AS unique_customer_count\nFROM unique_customers;\n" | |
| tags: | |
| - customer_analysis | |
| - unique_count | |
| - id: L4-043 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Find the top 10 products by total quantity sold this year. | |
| gold_sql: "WITH sold_products AS (\n SELECT sol.product_id, SUM(sol.product_uom_qty)\ | |
| \ AS total_qty\n FROM sale_order_line sol\n JOIN sale_order so ON so.id = sol.order_id\n\ | |
| \ WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY sol.product_id\n)\nSELECT pp.id AS product_id,\n pp.default_code,\n\ | |
| \ sp.total_qty\nFROM sold_products sp\nJOIN product_product pp ON pp.id\ | |
| \ = sp.product_id\nORDER BY sp.total_qty DESC\nLIMIT 10;\n" | |
| tags: | |
| - product_sales | |
| - top_products | |
| - id: L4-044 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Show the average order value per customer for completed orders this month. | |
| gold_sql: "WITH order_values AS (\n SELECT so.partner_id, SUM(sol.price_subtotal)\ | |
| \ AS order_value\n FROM sale_order_line sol\n JOIN sale_order so ON so.id =\ | |
| \ sol.order_id\n WHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ date_trunc('month', NOW())\n GROUP BY so.partner_id\n)\nSELECT COUNT(DISTINCT\ | |
| \ partner_id) AS unique_customers,\n AVG(order_value) AS avg_order_value\n\ | |
| FROM order_values;\n" | |
| tags: | |
| - average_order_value | |
| - customer_analysis | |
| - id: L5-045 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Analyze the monthly cash flow for the current year by summing all account moves | |
| per month. | |
| gold_sql: "WITH monthly_cash_flow AS (\n SELECT date_trunc('month', am.create_date)\ | |
| \ AS month,\n SUM(am.amount_total) AS total_cash_flow\n FROM account_move\ | |
| \ am\n WHERE am.create_date >= date_trunc('year', NOW())\n GROUP BY month\n\ | |
| )\nSELECT month,\n total_cash_flow\nFROM monthly_cash_flow\nORDER BY month;\n" | |
| tags: | |
| - financial_analysis | |
| - cash_flow | |
| - id: L5-046 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Calculate the total amount of invoices grouped by currency for the current year. | |
| gold_sql: "WITH currency_invoices AS (\n SELECT am.currency_id,\n SUM(am.amount_total)\ | |
| \ AS total_invoiced\n FROM account_move am\n WHERE am.create_date >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY am.currency_id\n)\nSELECT ci.currency_id,\n ci.total_invoiced\n\ | |
| FROM currency_invoices ci\nORDER BY ci.total_invoiced DESC;\n" | |
| tags: | |
| - financial_analysis | |
| - currency | |
| - id: L1-098 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: List all journal entries for a specific company. | |
| gold_sql: 'SELECT * | |
| FROM account_move | |
| WHERE company_id = 1; | |
| ' | |
| tags: | |
| - listing | |
| - filter | |
| - id: L1-099 | |
| level: 1 | |
| domains: | |
| - finance | |
| nl: How many partners are registered? | |
| gold_sql: 'SELECT COUNT(*) AS total_partners | |
| FROM res_partner; | |
| ' | |
| tags: | |
| - aggregate | |
| - filter | |
| - id: L3-092 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Find the total number of transactions for each partner in the last quarter. | |
| gold_sql: "SELECT rp.id, rp.name, COUNT(aml.id) AS transaction_count\nFROM res_partner\ | |
| \ rp\nJOIN account_move_line aml ON rp.id = aml.partner_id\nJOIN account_move\ | |
| \ am ON aml.move_id = am.id\nWHERE am.date >= date_trunc('quarter', NOW()) - INTERVAL\ | |
| \ '3 months'\n AND am.date < date_trunc('quarter', NOW())\nGROUP BY rp.id, rp.name;\n" | |
| tags: | |
| - finance | |
| - aggregate | |
| - qoq | |
| - id: L3-093 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of products in stock for each warehouse. | |
| gold_sql: 'SELECT w.name AS warehouse, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN stock_location l ON l.id = sq.location_id | |
| JOIN stock_warehouse w ON w.view_location_id = l.location_id | |
| GROUP BY w.id, w.name | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-094 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List product quantities that are reserved in each location. | |
| gold_sql: 'SELECT l.name AS location, SUM(sq.reserved_quantity) AS total_reserved | |
| FROM stock_quant sq | |
| JOIN stock_location l ON l.id = sq.location_id | |
| GROUP BY l.id, l.name | |
| ORDER BY total_reserved DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-095 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Find the total quantity of products received from each supplier this year. | |
| gold_sql: "SELECT rp.name AS supplier, SUM(pol.product_qty) AS total_received\n\ | |
| FROM purchase_order_line pol\nJOIN purchase_order po ON po.id = pol.order_id\n\ | |
| JOIN res_partner rp ON rp.id = po.partner_id\nWHERE po.state IN ('purchase', 'done')\n\ | |
| \ AND po.create_date >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY total_received DESC;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - id: L3-096 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Identify products that have been ordered but have not been invoiced this year. | |
| gold_sql: 'SELECT pp.default_code AS product_code, SUM(pol.product_qty) AS total_ordered | |
| FROM purchase_order_line pol | |
| JOIN purchase_order po ON po.id = pol.order_id | |
| JOIN product_product pp ON pp.id = pol.product_id | |
| WHERE po.invoice_status = ''no'' AND po.create_date >= date_trunc(''year'', NOW()) | |
| GROUP BY pp.default_code | |
| HAVING SUM(pol.product_qty) > 0 | |
| ORDER BY total_ordered DESC; | |
| ' | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - having | |
| - id: L4-045 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: Identify the total payments made by each customer for invoices in the last quarter. | |
| gold_sql: "WITH payment_summary AS (\n SELECT am.partner_id, SUM(am.amount_total_signed)\ | |
| \ AS total_payments\n FROM account_move am\n WHERE am.move_type = 'out_invoice'\ | |
| \ AND am.state = 'posted' AND am.date >= date_trunc('quarter', NOW())\n GROUP\ | |
| \ BY am.partner_id\n)\nSELECT rp.name AS customer, COALESCE(ps.total_payments,\ | |
| \ 0) AS total_payments\nFROM res_partner rp\nLEFT JOIN payment_summary ps ON ps.partner_id\ | |
| \ = rp.id\nORDER BY total_payments DESC;\n" | |
| tags: | |
| - federation_stub | |
| - quarterly_summary | |
| - id: L4-046 | |
| level: 4 | |
| domains: | |
| - finance | |
| nl: List all customers and their total unpaid invoices as of today. | |
| gold_sql: "WITH unpaid_invoices AS (\n SELECT am.partner_id, SUM(am.amount_residual)\ | |
| \ AS total_unpaid\n FROM account_move am\n WHERE am.move_type = 'out_invoice'\ | |
| \ AND am.state = 'posted'\n GROUP BY am.partner_id\n)\nSELECT rp.name AS customer,\ | |
| \ COALESCE(ui.total_unpaid, 0) AS total_unpaid\nFROM res_partner rp\nLEFT JOIN\ | |
| \ unpaid_invoices ui ON ui.partner_id = rp.id\nORDER BY total_unpaid DESC;\n" | |
| tags: | |
| - federation_stub | |
| - unpaid_invoices | |
| - id: L1-100 | |
| level: 1 | |
| domains: | |
| - inventory | |
| nl: What is the maximum reserved quantity of products in stock? | |
| gold_sql: 'SELECT MAX(reserved_quantity) AS max_reserved_quantity FROM stock_quant; | |
| ' | |
| tags: | |
| - aggregate | |
| - max | |
| - id: L2-098 | |
| level: 2 | |
| domains: | |
| - demand | |
| nl: List all sale orders along with the corresponding customer names. | |
| gold_sql: 'SELECT so.id, so.name, rp.name AS customer_name | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| ORDER BY so.id; | |
| ' | |
| tags: | |
| - join | |
| - id: L2-099 | |
| level: 2 | |
| domains: | |
| - finance | |
| nl: List all account journals with their associated company names. | |
| gold_sql: 'SELECT aj.id, aj.name, rc.name AS company_name | |
| FROM account_journal aj | |
| JOIN res_company rc ON rc.id = aj.company_id | |
| ORDER BY aj.id; | |
| ' | |
| tags: | |
| - join | |
| - filter | |
| - id: L2-100 | |
| level: 2 | |
| domains: | |
| - logistics | |
| nl: Count the number of purchase orders by state. | |
| gold_sql: 'SELECT po.state, COUNT(po.id) AS order_count | |
| FROM purchase_order po | |
| GROUP BY po.state | |
| ORDER BY order_count DESC; | |
| ' | |
| tags: | |
| - aggregate | |
| - group_by | |
| - id: L3-097 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: How many unique customers made purchases last year? | |
| gold_sql: "SELECT COUNT(DISTINCT so.partner_id) AS unique_customers\nFROM sale_order\ | |
| \ so\nWHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW()) - INTERVAL '1 year';\n" | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L3-098 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Show total invoices issued by company for this year. | |
| gold_sql: "SELECT rc.name AS company,\n COUNT(am.id) AS total_invoices\nFROM\ | |
| \ account_move am\nJOIN res_company rc ON rc.id = am.company_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\n AND am.create_date >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY rc.id, rc.name\nORDER BY total_invoices DESC;\n" | |
| tags: | |
| - cross_domain | |
| - temporal | |
| - aggregate | |
| - id: L4-047 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Show the total quantity of products reserved by warehouse location. | |
| gold_sql: 'SELECT sl.name AS location_name, SUM(sq.reserved_quantity) AS total_reserved | |
| FROM stock_quant sq | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| GROUP BY sl.name | |
| ORDER BY total_reserved DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - warehouse | |
| - id: L4-048 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: List the total quantity received for each product and their corresponding order | |
| IDs. | |
| gold_sql: 'SELECT pp.id AS product_id, pp.default_code AS product_code, SUM(pol.product_qty) | |
| AS total_received, po.id AS order_id | |
| FROM purchase_order po | |
| JOIN purchase_order_line pol ON pol.order_id = po.id | |
| JOIN product_product pp ON pp.id = pol.product_id | |
| WHERE po.state IN (''purchase'', ''done'') | |
| GROUP BY pp.id, pp.default_code, po.id | |
| ORDER BY total_received DESC; | |
| ' | |
| tags: | |
| - logistics | |
| - group_by_two | |
| - id: L5-047 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Calculate the average order value per customer for the current year. | |
| gold_sql: "WITH customer_orders AS (\n SELECT so.partner_id, SUM(sol.price_subtotal)\ | |
| \ AS total_spent\n FROM sale_order so\n JOIN sale_order_line sol ON sol.order_id\ | |
| \ = so.id\n WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY so.partner_id\n)\nSELECT rp.name AS customer,\n AVG(co.total_spent)\ | |
| \ AS avg_order_value\nFROM res_partner rp\nJOIN customer_orders co ON co.partner_id\ | |
| \ = rp.id\nGROUP BY rp.id, rp.name\nORDER BY avg_order_value DESC;\n" | |
| tags: | |
| - financial | |
| - average | |
| - id: L5-048 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: Calculate the total amount of invoices grouped by partner for this year. | |
| gold_sql: "WITH invoice_totals AS (\n SELECT partner_id, SUM(amount_total) AS total_amount\n\ | |
| \ FROM account_move\n WHERE invoice_payment_term_id IS NOT NULL\n AND date\ | |
| \ >= date_trunc('year', NOW())\n GROUP BY partner_id\n)\nSELECT rp.name AS partner_name,\ | |
| \ it.total_amount\nFROM invoice_totals it\nJOIN res_partner rp ON rp.id = it.partner_id\n\ | |
| ORDER BY it.total_amount DESC;\n" | |
| tags: | |
| - financial | |
| - aggregation | |
| - id: L5-049 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Identify the top 5 products by total reserved quantity across all locations. | |
| gold_sql: "SELECT pp.id AS product_id,\n pt.name->>'en_US' AS product_name,\n\ | |
| \ SUM(sq.reserved_quantity) AS total_reserved\nFROM stock_quant sq\nJOIN\ | |
| \ product_product pp ON pp.id = sq.product_id\nJOIN product_template pt ON pt.id\ | |
| \ = pp.product_tmpl_id\nGROUP BY pp.id, pt.name\nORDER BY total_reserved DESC\n\ | |
| LIMIT 5;\n" | |
| tags: | |
| - inventory | |
| - top_products | |
| - id: L5-050 | |
| level: 5 | |
| domains: | |
| - logistics | |
| nl: What is the total quantity of products ordered by each supplier with their average | |
| price per unit? | |
| gold_sql: "WITH supplier_totals AS (\n SELECT rp.name AS supplier,\n \ | |
| \ SUM(pol.product_qty) AS total_quantity,\n AVG(pol.price_unit) AS\ | |
| \ avg_price_per_unit\n FROM purchase_order_line pol\n JOIN purchase_order\ | |
| \ po ON po.id = pol.order_id\n JOIN res_partner rp ON rp.id = po.partner_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n GROUP BY rp.id, rp.name\n)\nSELECT\ | |
| \ supplier,\n total_quantity,\n avg_price_per_unit\nFROM supplier_totals\n\ | |
| WHERE total_quantity > 0\nORDER BY total_quantity DESC;\n" | |
| tags: | |
| - supplier_analysis | |
| - pricing | |
| - id: L6-011 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product this year. | |
| gold_sql: "SELECT pt.name AS product, SUM(sol.product_uom_qty * sol.price_unit)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pt.id, pt.name\nORDER BY total_sales\ | |
| \ DESC NULLS LAST;\n" | |
| - nl: Only for the top 3 products. | |
| gold_sql: "SELECT pt.name AS product, SUM(sol.product_uom_qty * sol.price_unit)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pt.id, pt.name\nORDER BY total_sales\ | |
| \ DESC NULLS LAST\nLIMIT 3;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-012 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: Show inventory levels by product. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.name | |
| ORDER BY total_quantity DESC NULLS LAST; | |
| ' | |
| - nl: Only those with quantity below 5. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.name | |
| HAVING SUM(sq.quantity) < 5 | |
| ORDER BY total_quantity DESC NULLS LAST; | |
| ' | |
| tags: | |
| - stock_levels | |
| - threshold | |
| - id: L6-013 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product this year. | |
| gold_sql: "SELECT pt.name AS product, SUM(sol.price_unit * sol.product_uom_qty)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pt.id, pt.name\nORDER BY total_sales\ | |
| \ DESC NULLS LAST;\n" | |
| - nl: Only for the top 3 products. | |
| gold_sql: "SELECT pt.name AS product, SUM(sol.price_unit * sol.product_uom_qty)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pt.id, pt.name\nORDER BY total_sales\ | |
| \ DESC NULLS LAST\nLIMIT 3;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-014 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total revenue by customer this year. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name;\n" | |
| - nl: Only for customers with revenue over 1000. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| HAVING SUM(so.amount_total) > 1000;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-015 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product category this year. | |
| gold_sql: "SELECT pc.name AS category, SUM(so.amount_total) AS total_sales\nFROM\ | |
| \ sale_order so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY pc.id, pc.name\n\ | |
| ORDER BY total_sales DESC NULLS LAST;\n" | |
| - nl: Group by category and only include categories with sales over 1000. | |
| gold_sql: "SELECT pc.name AS category, SUM(so.amount_total) AS total_sales\nFROM\ | |
| \ sale_order so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY pc.id, pc.name\n\ | |
| HAVING SUM(so.amount_total) > 1000\nORDER BY total_sales DESC NULLS LAST;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-016 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total revenue by product this year. | |
| gold_sql: "SELECT pt.name AS product, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pt.id, pt.name\nORDER BY revenue DESC NULLS LAST;\n" | |
| - nl: Only the top 3 products. | |
| gold_sql: "SELECT pt.name AS product, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pt.id, pt.name\nORDER BY revenue DESC NULLS LAST\nLIMIT 3;\n" | |
| tags: | |
| - multi_turn | |
| - revenue | |
| - id: L6-017 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this quarter. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('posted')\n AND invoice_date >= date_trunc('quarter', NOW());\n" | |
| - nl: Only for invoices with an amount over 1000. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('posted')\n AND invoice_date >= date_trunc('quarter', NOW())\n AND amount_total\ | |
| \ > 1000;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-018 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total revenue by month for this year. | |
| gold_sql: "SELECT DATE_TRUNC('month', so.date_order) AS month, SUM(so.amount_total)\ | |
| \ AS total_revenue\nFROM sale_order so\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY month\nORDER BY\ | |
| \ month;\n" | |
| - nl: Only for the last 3 months. | |
| gold_sql: "SELECT DATE_TRUNC('month', so.date_order) AS month, SUM(so.amount_total)\ | |
| \ AS total_revenue\nFROM sale_order so\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('month', NOW()) - INTERVAL '2 months'\nGROUP\ | |
| \ BY month\nORDER BY month;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-019 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: Show inventory levels for all products. | |
| gold_sql: 'SELECT pt.name AS product, SUM(sq.quantity) AS inventory_level | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.id, pt.name | |
| ORDER BY inventory_level DESC NULLS LAST; | |
| ' | |
| - nl: Just for products with inventory less than 50. | |
| gold_sql: 'SELECT pt.name AS product, SUM(sq.quantity) AS inventory_level | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.id, pt.name | |
| HAVING SUM(sq.quantity) < 50 | |
| ORDER BY inventory_level DESC NULLS LAST; | |
| ' | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-020 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this year. | |
| gold_sql: "SELECT SUM(am.amount_total) AS total_invoices\nFROM account_move am\n\ | |
| WHERE am.state = 'posted'\n AND am.invoice_date >= date_trunc('year', NOW());\n" | |
| - nl: Only for invoices above 1000. | |
| gold_sql: "SELECT SUM(am.amount_total) AS total_invoices\nFROM account_move am\n\ | |
| WHERE am.state = 'posted'\n AND am.invoice_date >= date_trunc('year', NOW())\n\ | |
| \ AND am.amount_total > 1000;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-021 | |
| level: 6 | |
| domains: | |
| - logistics | |
| turns: | |
| - nl: Show all sale orders with their total amounts. | |
| gold_sql: 'SELECT so.id, SUM(so.amount_total) AS total_amount | |
| FROM sale_order so | |
| GROUP BY so.id; | |
| ' | |
| - nl: Only for completed orders. | |
| gold_sql: 'SELECT so.id, SUM(so.amount_total) AS total_amount | |
| FROM sale_order so | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY so.id; | |
| ' | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-022 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product this year. | |
| gold_sql: "SELECT pt.name AS product, SUM(so.amount_total) AS total_sales\nFROM\ | |
| \ sale_order so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pt.id, pt.name\nORDER BY total_sales DESC NULLS LAST;\n" | |
| - nl: Only for products with sales over 1000. | |
| gold_sql: "SELECT pt.name AS product, SUM(so.amount_total) AS total_sales\nFROM\ | |
| \ sale_order so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pt.id, pt.name\nHAVING SUM(so.amount_total) > 1000\nORDER\ | |
| \ BY total_sales DESC NULLS LAST;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-023 | |
| level: 6 | |
| domains: | |
| - logistics | |
| turns: | |
| - nl: Show total deliveries by month for the last 6 months. | |
| gold_sql: "SELECT DATE_TRUNC('month', so.date_order) AS month, COUNT(*) AS total_deliveries\n\ | |
| FROM sale_order so\nWHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ NOW() - INTERVAL '6 months'\nGROUP BY month\nORDER BY month DESC;\n" | |
| - nl: Just for the last 3 months. | |
| gold_sql: "SELECT DATE_TRUNC('month', so.date_order) AS month, COUNT(*) AS total_deliveries\n\ | |
| FROM sale_order so\nWHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ NOW() - INTERVAL '3 months'\nGROUP BY month\nORDER BY month DESC;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-024 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoice amounts by partner this year. | |
| gold_sql: "SELECT rp.name AS partner, SUM(am.amount_total) AS total_invoices\n\ | |
| FROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\nWHERE am.state\ | |
| \ IN ('posted')\n AND am.invoice_date >= date_trunc('year', NOW())\nGROUP BY\ | |
| \ rp.id, rp.name\nORDER BY total_invoices DESC NULLS LAST;\n" | |
| - nl: Only for partners with total invoices over 5000. | |
| gold_sql: "SELECT rp.name AS partner, SUM(am.amount_total) AS total_invoices\n\ | |
| FROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\nWHERE am.state\ | |
| \ IN ('posted')\n AND am.invoice_date >= date_trunc('year', NOW())\nGROUP BY\ | |
| \ rp.id, rp.name\nHAVING SUM(am.amount_total) > 5000\nORDER BY total_invoices\ | |
| \ DESC NULLS LAST;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-025 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices by customer this year. | |
| gold_sql: "SELECT rp.name AS customer, SUM(am.amount_total) AS total_invoices\n\ | |
| FROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\nWHERE am.state\ | |
| \ = 'posted'\n AND am.invoice_date >= date_trunc('year', NOW())\nGROUP BY rp.id,\ | |
| \ rp.name;\n" | |
| - nl: And only for the customers with more than 5 invoices. | |
| gold_sql: "SELECT rp.name AS customer, SUM(am.amount_total) AS total_invoices\n\ | |
| FROM account_move am\nJOIN res_partner rp ON rp.id = am.partner_id\nWHERE am.state\ | |
| \ = 'posted'\n AND am.invoice_date >= date_trunc('year', NOW())\nGROUP BY rp.id,\ | |
| \ rp.name\nHAVING COUNT(am.id) > 5;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-026 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product category. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sol.product_uom_qty * sol.price_unit) | |
| AS total_sales | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_sales DESC NULLS LAST; | |
| ' | |
| - nl: Just for the current year. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sol.product_uom_qty * sol.price_unit) | |
| AS total_sales | |
| FROM sale_order_line sol | |
| JOIN sale_order so ON so.id = sol.order_id | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| WHERE so.date_order >= date_trunc(''year'', NOW()) | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_sales DESC NULLS LAST; | |
| ' | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-027 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this month. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE invoice_user_id\ | |
| \ IS NOT NULL\n AND create_date >= date_trunc('month', NOW());\n" | |
| - nl: Focus only on invoices that are paid. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE invoice_user_id\ | |
| \ IS NOT NULL\n AND create_date >= date_trunc('month', NOW())\n AND payment_id\ | |
| \ IS NOT NULL;\n" | |
| tags: | |
| - multi_turn | |
| - invoice | |
| - id: L6-028 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this year. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('posted')\n AND invoice_date >= date_trunc('year', NOW());\n" | |
| - nl: Only for invoices over $1000. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('posted')\n AND invoice_date >= date_trunc('year', NOW())\n AND amount_total\ | |
| \ > 1000;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-029 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show the total number of orders by customer this year. | |
| gold_sql: "SELECT rp.name AS customer, COUNT(so.id) AS total_orders\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale',\ | |
| \ 'done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id,\ | |
| \ rp.name;\n" | |
| - nl: Only for the top 10 customers. | |
| gold_sql: "SELECT rp.name AS customer, COUNT(so.id) AS total_orders\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale',\ | |
| \ 'done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id,\ | |
| \ rp.name\nORDER BY total_orders DESC NULLS LAST\nLIMIT 10;\n" | |
| tags: | |
| - sales | |
| - top_customers | |
| - id: L6-030 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: Show products with their current stock levels. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, SUM(sq.quantity) AS current_stock | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.name; | |
| ' | |
| - nl: Only for items with stock below 5 units. | |
| gold_sql: 'SELECT pt.name->>''en_US'' AS product, SUM(sq.quantity) AS current_stock | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.name | |
| HAVING SUM(sq.quantity) < 5; | |
| ' | |
| tags: | |
| - stock | |
| - low_inventory | |
| - id: L6-031 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this month. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('posted')\n AND invoice_date >= date_trunc('month', NOW());\n" | |
| - nl: Only for invoices above 1000 in amount. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('posted')\n AND invoice_date >= date_trunc('month', NOW())\n AND amount_total\ | |
| \ > 1000;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-032 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued by month this year. | |
| gold_sql: "SELECT date_trunc('month', am.create_date) AS month, COUNT(am.id) AS\ | |
| \ total_invoices\nFROM account_move am\nWHERE am.state IN ('posted')\n AND\ | |
| \ am.create_date >= date_trunc('year', NOW())\nGROUP BY month\nORDER BY month;\n" | |
| - nl: Just for the last 6 months. | |
| gold_sql: "SELECT date_trunc('month', am.create_date) AS month, COUNT(am.id) AS\ | |
| \ total_invoices\nFROM account_move am\nWHERE am.state IN ('posted')\n AND\ | |
| \ am.create_date >= date_trunc('month', NOW()) - INTERVAL '6 months'\nGROUP\ | |
| \ BY month\nORDER BY month;\n" | |
| tags: | |
| - multi_turn | |
| - invoices | |
| - id: L6-033 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total revenue by product category this year. | |
| gold_sql: "SELECT pc.name AS category, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY pc.id, pc.name\n\ | |
| ORDER BY revenue DESC NULLS LAST;\n" | |
| - nl: Only the top 3 categories. | |
| gold_sql: "SELECT pc.name AS category, SUM(so.amount_total) AS revenue\nFROM sale_order\ | |
| \ so\nJOIN sale_order_line sol ON sol.order_id = so.id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY pc.id, pc.name\n\ | |
| ORDER BY revenue DESC NULLS LAST\nLIMIT 3;\n" | |
| tags: | |
| - multi_turn | |
| - revenue | |
| - id: L6-034 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this year. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state =\ | |
| \ 'posted'\n AND invoice_date >= date_trunc('year', NOW());\n" | |
| - nl: Only show invoices above 1000 currency units. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state =\ | |
| \ 'posted'\n AND invoice_date >= date_trunc('year', NOW())\n AND amount_total\ | |
| \ > 1000;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-035 | |
| level: 6 | |
| domains: | |
| - logistics | |
| turns: | |
| - nl: Show total deliveries by month. | |
| gold_sql: 'SELECT DATE_TRUNC(''month'', so.date_order) AS month, COUNT(DISTINCT | |
| so.id) AS total_deliveries | |
| FROM sale_order so | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY month | |
| ORDER BY month ASC; | |
| ' | |
| - nl: Just for the last 6 months. | |
| gold_sql: "SELECT DATE_TRUNC('month', so.date_order) AS month, COUNT(DISTINCT\ | |
| \ so.id) AS total_deliveries\nFROM sale_order so\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= NOW() - INTERVAL '6 months'\nGROUP BY month\nORDER BY\ | |
| \ month ASC;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-036 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this month. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state =\ | |
| \ 'posted'\n AND invoice_date >= date_trunc('month', NOW());\n" | |
| - nl: Only for completed invoices. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state =\ | |
| \ 'posted'\n AND invoice_date >= date_trunc('month', NOW())\n AND amount_total\ | |
| \ > 0;\n" | |
| tags: | |
| - multi_turn | |
| - invoices | |
| - id: L6-037 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total number of sales orders per customer this year. | |
| gold_sql: "SELECT rp.name AS customer, COUNT(so.id) AS total_orders\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY total_orders DESC NULLS LAST;\n" | |
| - nl: Only the top 5 customers by order count. | |
| gold_sql: "SELECT rp.name AS customer, COUNT(so.id) AS total_orders\nFROM sale_order\ | |
| \ so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\n\ | |
| ORDER BY total_orders DESC NULLS LAST\nLIMIT 5;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-038 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product this year. | |
| gold_sql: "SELECT pt.name AS product, SUM(sol.product_uom_qty * sol.price_unit)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale', 'done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pt.id, pt.name;\n" | |
| - nl: Only for the top 10 products. | |
| gold_sql: "SELECT pt.name AS product, SUM(sol.product_uom_qty * sol.price_unit)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale', 'done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW())\nGROUP BY pt.id, pt.name\nORDER BY total_sales\ | |
| \ DESC\nLIMIT 10;\n" | |
| tags: | |
| - multi_turn | |
| - revenue | |
| - id: L6-039 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices created this year. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state =\ | |
| \ 'posted'\n AND create_date >= date_trunc('year', NOW());\n" | |
| - nl: Only for invoices above 1000 currency units. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state =\ | |
| \ 'posted'\n AND create_date >= date_trunc('year', NOW())\n AND amount_total\ | |
| \ > 1000;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-040 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this year. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('draft', 'posted')\n AND invoice_date >= date_trunc('year', NOW());\n" | |
| - nl: Only for invoices that have been paid. | |
| gold_sql: "SELECT COUNT(*) AS total_invoices\nFROM account_move\nWHERE state IN\ | |
| \ ('draft', 'posted')\n AND invoice_date >= date_trunc('year', NOW())\n AND\ | |
| \ payment_id IS NOT NULL;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-041 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by customer for this year. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS total_sales\nFROM\ | |
| \ sale_order so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state\ | |
| \ IN ('sale', 'done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rp.id, rp.name\nORDER BY total_sales DESC NULLS LAST;\n" | |
| - nl: Only the top 10 customers. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS total_sales\nFROM\ | |
| \ sale_order so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state\ | |
| \ IN ('sale', 'done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rp.id, rp.name\nORDER BY total_sales DESC NULLS LAST\nLIMIT 10;\n" | |
| tags: | |
| - sales | |
| - top_customers | |
| - id: L6-042 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product category. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sol.product_uom_qty) AS total_sales | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_sales DESC NULLS LAST; | |
| ' | |
| - nl: Group by category and only include categories with sales over 100. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sol.product_uom_qty) AS total_sales | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| GROUP BY pc.id, pc.name | |
| HAVING SUM(sol.product_uom_qty) > 100 | |
| ORDER BY total_sales DESC NULLS LAST; | |
| ' | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-043 | |
| level: 6 | |
| domains: | |
| - finance | |
| turns: | |
| - nl: Show total invoices issued this year. | |
| gold_sql: "SELECT COUNT(am.id) AS total_invoices\nFROM account_move am\nWHERE\ | |
| \ am.invoice_user_id IS NOT NULL\n AND am.date >= date_trunc('year', NOW());\n" | |
| - nl: Only include invoices that have been paid. | |
| gold_sql: "SELECT COUNT(am.id) AS total_invoices\nFROM account_move am\nWHERE\ | |
| \ am.invoice_user_id IS NOT NULL\n AND am.date >= date_trunc('year', NOW())\n\ | |
| \ AND am.state = 'paid';\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-044 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by product category this year. | |
| gold_sql: "SELECT pc.name AS category, SUM(sol.price_unit * sol.product_uom_qty)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nJOIN product_category pc ON pc.id = pt.categ_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pc.id, pc.name\nORDER BY total_sales DESC NULLS LAST;\n" | |
| - nl: Only for the top 3 categories. | |
| gold_sql: "SELECT pc.name AS category, SUM(sol.price_unit * sol.product_uom_qty)\ | |
| \ AS total_sales\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt\ | |
| \ ON pt.id = pp.product_tmpl_id\nJOIN product_category pc ON pc.id = pt.categ_id\n\ | |
| WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\nGROUP BY pc.id, pc.name\nORDER BY total_sales DESC NULLS LAST\nLIMIT\ | |
| \ 3;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-045 | |
| level: 6 | |
| domains: | |
| - logistics | |
| turns: | |
| - nl: Show total deliveries by month for this year. | |
| gold_sql: "SELECT date_trunc('month', so.date_order) AS month, COUNT(so.id) AS\ | |
| \ total_deliveries\nFROM sale_order so\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY month\nORDER BY\ | |
| \ month;\n" | |
| - nl: Just for the last 6 months. | |
| gold_sql: "SELECT date_trunc('month', so.date_order) AS month, COUNT(so.id) AS\ | |
| \ total_deliveries\nFROM sale_order so\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('month', NOW()) - INTERVAL '6 months'\nGROUP\ | |
| \ BY month\nORDER BY month;\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-046 | |
| level: 6 | |
| domains: | |
| - demand | |
| turns: | |
| - nl: Show total sales by each customer. | |
| gold_sql: 'SELECT rp.name AS customer, SUM(so.amount_total) AS total_sales | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY rp.id, rp.name | |
| ORDER BY total_sales DESC NULLS LAST; | |
| ' | |
| - nl: Only the top 10 customers. | |
| gold_sql: 'SELECT rp.name AS customer, SUM(so.amount_total) AS total_sales | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.state IN (''sale'',''done'') | |
| GROUP BY rp.id, rp.name | |
| ORDER BY total_sales DESC NULLS LAST | |
| LIMIT 10; | |
| ' | |
| - nl: And only for the current year. | |
| gold_sql: "SELECT rp.name AS customer, SUM(so.amount_total) AS total_sales\nFROM\ | |
| \ sale_order so\nJOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state\ | |
| \ IN ('sale','done')\n AND so.date_order >= date_trunc('year', NOW())\nGROUP\ | |
| \ BY rp.id, rp.name\nORDER BY total_sales DESC NULLS LAST\nLIMIT 10;\n" | |
| tags: | |
| - sales | |
| - top_customers | |
| - id: L6-047 | |
| level: 6 | |
| domains: | |
| - logistics | |
| turns: | |
| - nl: Show the number of orders shipped this week. | |
| gold_sql: "SELECT COUNT(so.id) AS total_orders\nFROM sale_order so\nWHERE so.state\ | |
| \ IN ('done')\n AND so.date_order >= date_trunc('week', NOW());\n" | |
| - nl: Just for the last week. | |
| gold_sql: "SELECT COUNT(so.id) AS total_orders\nFROM sale_order so\nWHERE so.state\ | |
| \ IN ('done')\n AND so.date_order >= date_trunc('week', NOW()) - INTERVAL '1\ | |
| \ week'\n AND so.date_order < date_trunc('week', NOW());\n" | |
| - nl: And only for orders from the last month. | |
| gold_sql: "SELECT COUNT(so.id) AS total_orders\nFROM sale_order so\nWHERE so.state\ | |
| \ IN ('done')\n AND so.date_order >= date_trunc('month', NOW()) - INTERVAL\ | |
| \ '1 month'\n AND so.date_order < date_trunc('month', NOW());\n" | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-048 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: Show stock levels for each product. | |
| gold_sql: 'SELECT pt.name AS product, SUM(sq.quantity) AS total_stock | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.id, pt.name | |
| ORDER BY total_stock DESC; | |
| ' | |
| - nl: Only include products with stock less than 50. | |
| gold_sql: 'SELECT pt.name AS product, SUM(sq.quantity) AS total_stock | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.id, pt.name | |
| HAVING SUM(sq.quantity) < 50 | |
| ORDER BY total_stock DESC; | |
| ' | |
| - nl: Show only the top 5 products. | |
| gold_sql: 'SELECT pt.name AS product, SUM(sq.quantity) AS total_stock | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.id, pt.name | |
| HAVING SUM(sq.quantity) < 50 | |
| ORDER BY total_stock DESC | |
| LIMIT 5; | |
| ' | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-049 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: Show inventory levels by product category. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_quantity DESC NULLS LAST; | |
| ' | |
| - nl: Only for active products. | |
| gold_sql: 'SELECT pc.name AS category, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| WHERE pt.active = TRUE | |
| GROUP BY pc.id, pc.name | |
| ORDER BY total_quantity DESC NULLS LAST; | |
| ' | |
| tags: | |
| - multi_turn | |
| - refinement | |
| - id: L6-050 | |
| level: 6 | |
| domains: | |
| - inventory | |
| turns: | |
| - nl: Show the total stock quantity for each product. | |
| gold_sql: 'SELECT pt.name AS product, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.id, pt.name; | |
| ' | |
| - nl: Just for products with stock less than 20. | |
| gold_sql: 'SELECT pt.name AS product, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| GROUP BY pt.id, pt.name | |
| HAVING SUM(sq.quantity) < 20; | |
| ' | |
| tags: | |
| - stock_levels | |
| - low_stock | |
| - id: L3-099 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Identify the total quantity reserved for products in stock by location. | |
| gold_sql: 'SELECT sl.name AS location_name, SUM(sq.reserved_quantity) AS total_reserved_quantity | |
| FROM stock_quant sq | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| GROUP BY sl.name | |
| ORDER BY total_reserved_quantity DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregation | |
| - id: L3-100 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List locations and their respective total inventory quantity for all products. | |
| gold_sql: 'SELECT sl.name AS location_name, SUM(sq.inventory_quantity) AS total_inventory_quantity | |
| FROM stock_quant sq | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| GROUP BY sl.name | |
| ORDER BY total_inventory_quantity DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregation | |
| - id: L3-101 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Find the average price of products sold in the last year grouped by product | |
| template. | |
| gold_sql: "SELECT pt.id, pt.name->>'en_US' AS product_name, AVG(sol.price_unit)\ | |
| \ AS average_price\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN product_product pp ON pp.id = sol.product_id\nJOIN product_template pt ON\ | |
| \ pt.id = pp.product_tmpl_id\nWHERE so.state IN ('sale', 'done')\n AND so.date_order\ | |
| \ >= NOW() - INTERVAL '1 year'\nGROUP BY pt.id, pt.name->>'en_US';\n" | |
| tags: | |
| - price | |
| - aggregation | |
| - id: L3-102 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: List total invoices and total payments for each partner this quarter. | |
| gold_sql: "SELECT rp.name AS partner,\n COALESCE(invoices.total_invoices,\ | |
| \ 0) AS total_invoices,\n COALESCE(payments.total_payments, 0) AS total_payments\n\ | |
| FROM res_partner rp\nLEFT JOIN (\n SELECT partner_id,\n COUNT(id)\ | |
| \ AS total_invoices\n FROM account_move\n WHERE move_type = 'out_invoice'\n\ | |
| \ AND state = 'posted'\n AND date >= date_trunc('quarter', NOW())\n\ | |
| \ GROUP BY partner_id\n) invoices ON invoices.partner_id = rp.id\nLEFT JOIN\ | |
| \ (\n SELECT partner_id,\n COUNT(id) AS total_payments\n FROM\ | |
| \ account_move\n WHERE move_type = 'out_payment'\n AND state = 'posted'\n\ | |
| \ AND date >= date_trunc('quarter', NOW())\n GROUP BY partner_id\n) payments\ | |
| \ ON payments.partner_id = rp.id\nORDER BY partner;\n" | |
| tags: | |
| - finance | |
| - temporal | |
| - comparison | |
| - id: L3-103 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Get the total amount of transactions grouped by journal for the last year. | |
| gold_sql: "SELECT aj.id AS journal_id,\n SUM(aml.balance) AS total_amount\n\ | |
| FROM account_journal aj\nJOIN account_move_line aml ON aj.id = aml.journal_id\n\ | |
| JOIN account_move am ON aml.move_id = am.id\nWHERE am.date >= date_trunc('year',\ | |
| \ NOW()) - interval '1 year'\nGROUP BY aj.id\nORDER BY total_amount DESC;\n" | |
| tags: | |
| - finance | |
| - aggregate | |
| - group_by | |
| - id: L3-104 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Find the average invoice amount for each partner in the last six months. | |
| gold_sql: "SELECT rp.id AS partner_id,\n AVG(am.amount_total) AS average_invoice\n\ | |
| FROM res_partner rp\nJOIN account_move am ON rp.id = am.partner_id\nWHERE am.move_type\ | |
| \ = 'out_invoice'\n AND am.state = 'posted'\n AND am.date >= date_trunc('month',\ | |
| \ NOW()) - interval '6 months'\nGROUP BY rp.id\nORDER BY average_invoice DESC;\n" | |
| tags: | |
| - finance | |
| - temporal | |
| - average | |
| - id: L3-105 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: List the number of purchase orders by state and currency this year. | |
| gold_sql: 'SELECT po.state AS order_state, po.currency_id, COUNT(po.id) AS order_count | |
| FROM purchase_order po | |
| WHERE po.create_date >= date_trunc(''year'', NOW()) | |
| GROUP BY po.state, po.currency_id; | |
| ' | |
| tags: | |
| - logistics | |
| - temporal | |
| - group_by | |
| - id: L3-106 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: What is the average price of products sold in each product category for the | |
| last quarter? | |
| gold_sql: 'SELECT pc.name AS category_name, AVG(sol.price_unit) AS average_price | |
| FROM sale_order_line sol | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| JOIN product_template pt ON pt.id = pp.product_tmpl_id | |
| JOIN product_category pc ON pc.id = pt.categ_id | |
| JOIN sale_order so ON so.id = sol.order_id | |
| WHERE so.date_order >= NOW() - INTERVAL ''3 months'' | |
| GROUP BY pc.name | |
| ORDER BY pc.name; | |
| ' | |
| tags: | |
| - product_analysis | |
| - pricing | |
| - temporal | |
| - id: L3-107 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: How many sale orders were placed by each customer in the last 6 months? | |
| gold_sql: 'SELECT rp.name AS customer_name, COUNT(so.id) AS order_count | |
| FROM sale_order so | |
| JOIN res_partner rp ON rp.id = so.partner_id | |
| WHERE so.date_order >= NOW() - INTERVAL ''6 months'' | |
| GROUP BY rp.name | |
| ORDER BY order_count DESC; | |
| ' | |
| tags: | |
| - customer_analysis | |
| - temporal | |
| - aggregation | |
| - id: L3-108 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: List the total quantity of products sold per product for the last year. | |
| gold_sql: 'SELECT pp.default_code, SUM(sol.product_uom_qty) AS total_quantity | |
| FROM sale_order_line sol | |
| JOIN sale_order so ON so.id = sol.order_id | |
| JOIN product_product pp ON pp.id = sol.product_id | |
| WHERE so.date_order >= NOW() - INTERVAL ''1 year'' | |
| GROUP BY pp.default_code | |
| ORDER BY total_quantity DESC; | |
| ' | |
| tags: | |
| - product_analysis | |
| - sales | |
| - temporal | |
| - id: L3-109 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: List the total quantity sold for each product in the last six months. | |
| gold_sql: "SELECT pp.id AS product_id, SUM(sol.product_uom_qty) AS total_quantity_sold\n\ | |
| FROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nWHERE so.state IN ('sale', 'done')\n AND so.date_order\ | |
| \ >= NOW() - INTERVAL '6 months'\nGROUP BY pp.id\nORDER BY total_quantity_sold\ | |
| \ DESC;\n" | |
| tags: | |
| - demand | |
| - temporal | |
| - aggregation | |
| - id: L3-110 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Which customers have purchased more than five different products in the last | |
| year? | |
| gold_sql: "SELECT rp.id, rp.name AS customer, COUNT(DISTINCT sol.product_id) AS\ | |
| \ product_count\nFROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\n\ | |
| JOIN res_partner rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale', 'done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\nGROUP BY rp.id, rp.name\nHAVING\ | |
| \ COUNT(DISTINCT sol.product_id) > 5;\n" | |
| tags: | |
| - demand | |
| - customer_analysis | |
| - aggregation | |
| - id: L3-111 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Retrieve the total amount of sales for each product category in the last quarter. | |
| gold_sql: "SELECT pc.name AS category_name, SUM(sol.price_subtotal) AS total_sales\n\ | |
| FROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= NOW() - INTERVAL '3 months'\nGROUP BY pc.name;\n" | |
| tags: | |
| - sales | |
| - aggregation | |
| - temporal | |
| - id: L3-112 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Find the average price of sold products grouped by their categories for the | |
| last 6 months. | |
| gold_sql: "SELECT pc.name AS category_name, AVG(sol.price_unit) AS average_price\n\ | |
| FROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| JOIN product_category pc ON pc.id = pt.categ_id\nWHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= NOW() - INTERVAL '6 months'\nGROUP BY pc.name;\n" | |
| tags: | |
| - sales | |
| - aggregation | |
| - temporal | |
| - id: L3-113 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: List the total quantity sold per customer for the last year. | |
| gold_sql: "SELECT rp.name AS customer_name, SUM(sol.product_uom_qty) AS total_quantity\n\ | |
| FROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN res_partner\ | |
| \ rp ON rp.id = so.partner_id\nWHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= NOW() - INTERVAL '1 year'\nGROUP BY rp.name;\n" | |
| tags: | |
| - sales | |
| - aggregation | |
| - id: L3-114 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: How many sale orders did each customer place last year? | |
| gold_sql: "SELECT so.partner_id, COUNT(so.id) AS order_count\nFROM sale_order so\n\ | |
| WHERE so.state IN ('sale', 'done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW()) - INTERVAL '1 year'\nGROUP BY so.partner_id;\n" | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L3-115 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Retrieve the total sales amount for each product category in the last six months. | |
| gold_sql: "SELECT pt.categ_id, SUM(sol.price_unit * sol.product_uom_qty) AS total_sales\n\ | |
| FROM sale_order_line sol\nJOIN sale_order so ON so.id = sol.order_id\nJOIN product_product\ | |
| \ pp ON pp.id = sol.product_id\nJOIN product_template pt ON pt.id = pp.product_tmpl_id\n\ | |
| WHERE so.state IN ('sale', 'done')\n AND so.date_order >= NOW() - INTERVAL '6\ | |
| \ months'\nGROUP BY pt.categ_id;\n" | |
| tags: | |
| - aggregate | |
| - temporal | |
| - id: L3-116 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Get the total quantity received for each product in stock moves. | |
| gold_sql: 'SELECT sm.product_id, SUM(pol.product_qty) AS total_received | |
| FROM stock_move sm | |
| JOIN purchase_order_line pol ON pol.product_id = sm.product_id | |
| GROUP BY sm.product_id; | |
| ' | |
| tags: | |
| - logistics | |
| - quantity_received | |
| - id: L3-117 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Find the number of purchase orders for each supplier and their total amount. | |
| gold_sql: 'SELECT rp.name AS supplier, COUNT(po.id) AS order_count, SUM(pol.price_subtotal) | |
| AS total_amount | |
| FROM purchase_order po | |
| JOIN res_partner rp ON rp.id = po.partner_id | |
| JOIN purchase_order_line pol ON pol.order_id = po.id | |
| GROUP BY rp.name; | |
| ' | |
| tags: | |
| - logistics | |
| - supplier_orders | |
| - id: L3-118 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: List each product and the average price across all purchase orders. | |
| gold_sql: 'SELECT pol.product_id, AVG(pol.price_unit) AS average_price | |
| FROM purchase_order_line pol | |
| GROUP BY pol.product_id; | |
| ' | |
| tags: | |
| - logistics | |
| - average_price | |
| - id: L3-119 | |
| level: 3 | |
| domains: | |
| - logistics | |
| nl: Show the total number of stock moves by state for each product. | |
| gold_sql: 'SELECT sm.product_id, sm.state, COUNT(sm.id) AS total_moves | |
| FROM stock_move sm | |
| GROUP BY sm.product_id, sm.state; | |
| ' | |
| tags: | |
| - logistics | |
| - stock_moves_by_state | |
| - id: L4-049 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: List the top 3 locations with the highest total inventory quantity for this | |
| month. | |
| gold_sql: "SELECT sl.name AS location_name,\n SUM(sq.inventory_quantity) AS\ | |
| \ total_inventory\nFROM stock_quant sq\nJOIN stock_location sl ON sl.id = sq.location_id\n\ | |
| WHERE sq.inventory_date >= date_trunc('month', NOW())\nGROUP BY sl.id, sl.name\n\ | |
| ORDER BY total_inventory DESC\nLIMIT 3;\n" | |
| tags: | |
| - inventory | |
| - location_analysis | |
| - id: L4-050 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Identify the products with the highest reserved quantity and their corresponding | |
| locations. | |
| gold_sql: "SELECT pp.id AS product_id,\n pt.name->>'en_US' AS product_name,\n\ | |
| \ sl.name AS location_name,\n SUM(sq.reserved_quantity) AS total_reserved\n\ | |
| FROM stock_quant sq\nJOIN product_product pp ON pp.id = sq.product_id\nJOIN product_template\ | |
| \ pt ON pt.id = pp.product_tmpl_id\nJOIN stock_location sl ON sl.id = sq.location_id\n\ | |
| GROUP BY pp.id, pt.name, sl.name\nORDER BY total_reserved DESC;\n" | |
| tags: | |
| - inventory | |
| - product_location_analysis | |
| - id: L4-051 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Calculate the average inventory quantity for each product this quarter. | |
| gold_sql: "SELECT pp.id AS product_id,\n pt.name->>'en_US' AS product_name,\n\ | |
| \ AVG(sq.inventory_quantity) AS avg_inventory\nFROM stock_quant sq\nJOIN\ | |
| \ product_product pp ON pp.id = sq.product_id\nJOIN product_template pt ON pt.id\ | |
| \ = pp.product_tmpl_id\nWHERE sq.inventory_date >= date_trunc('quarter', NOW())\n\ | |
| GROUP BY pp.id, pt.name\nORDER BY avg_inventory DESC;\n" | |
| tags: | |
| - inventory | |
| - product_analysis | |
| - id: L4-052 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Show the rank of products by their total inventory quantity in the last month. | |
| gold_sql: "SELECT pp.id AS product_id,\n pt.name->>'en_US' AS product_name,\n\ | |
| \ SUM(sq.inventory_quantity) AS total_inventory,\n RANK() OVER (ORDER\ | |
| \ BY SUM(sq.inventory_quantity) DESC) AS inventory_rank\nFROM stock_quant sq\n\ | |
| JOIN product_product pp ON pp.id = sq.product_id\nJOIN product_template pt ON\ | |
| \ pt.id = pp.product_tmpl_id\nWHERE sq.inventory_date >= date_trunc('month', NOW())\n\ | |
| GROUP BY pp.id, pt.name\nORDER BY total_inventory DESC;\n" | |
| tags: | |
| - inventory | |
| - ranking | |
| - id: L3-120 | |
| level: 3 | |
| domains: | |
| - finance | |
| nl: Get the total number of invoices and the total amount for each company this | |
| year. | |
| gold_sql: "SELECT rc.name AS company_name,\n COUNT(am.id) AS total_invoices,\n\ | |
| \ SUM(am.amount_total) AS total_amount\nFROM account_move am\nJOIN res_company\ | |
| \ rc ON rc.id = am.company_id\nWHERE am.move_type = 'out_invoice'\n AND am.state\ | |
| \ = 'posted'\n AND am.date >= date_trunc('year', NOW())\nGROUP BY rc.id, rc.name\n\ | |
| ORDER BY total_amount DESC;\n" | |
| tags: | |
| - company | |
| - temporal | |
| - aggregate | |
| - id: L3-121 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List the total inventory quantity for each product along with its warehouse | |
| location. | |
| gold_sql: 'SELECT pp.default_code AS product_code, l.name AS warehouse_location, | |
| SUM(sq.inventory_quantity) AS total_inventory | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN stock_location l ON l.id = sq.location_id | |
| GROUP BY pp.default_code, l.name | |
| ORDER BY total_inventory DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregation | |
| - id: L3-122 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of stock quant for each product in specific warehouse | |
| locations. | |
| gold_sql: 'SELECT pp.default_code AS product_code, SUM(sq.quantity) AS total_quantity | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN stock_location l ON l.id = sq.location_id | |
| WHERE l.warehouse_id IN (SELECT id FROM stock_warehouse WHERE company_id = 1) | |
| GROUP BY pp.default_code; | |
| ' | |
| tags: | |
| - inventory | |
| - group_by_two | |
| - id: L3-123 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show the total reserved quantity for each product along with the warehouse name | |
| and location. | |
| gold_sql: 'SELECT pp.default_code AS product_code, w.name AS warehouse_name, SUM(sq.reserved_quantity) | |
| AS total_reserved | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN stock_location l ON l.id = sq.location_id | |
| JOIN stock_warehouse w ON w.id = l.warehouse_id | |
| GROUP BY pp.default_code, w.name; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregation | |
| - id: L5-051 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Determine the average order value for each sales team this year. | |
| gold_sql: "WITH team_sales AS (\n SELECT so.team_id,\n AVG(so.amount_total)\ | |
| \ AS avg_order_value\n FROM sale_order so\n WHERE so.state IN ('sale','done')\n\ | |
| \ AND so.date_order >= date_trunc('year', NOW())\n GROUP BY so.team_id\n)\n\ | |
| SELECT ct.name AS sales_team,\n ts.avg_order_value\nFROM team_sales ts\n\ | |
| JOIN crm_team ct ON ct.id = ts.team_id\nORDER BY avg_order_value DESC;\n" | |
| tags: | |
| - sales | |
| - average | |
| - id: L5-052 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: List the top 5 products by total sales quantity this year. | |
| gold_sql: "WITH product_sales AS (\n SELECT sol.product_id,\n SUM(sol.product_uom_qty)\ | |
| \ AS total_quantity\n FROM sale_order_line sol\n JOIN sale_order so ON so.id\ | |
| \ = sol.order_id\n WHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ date_trunc('year', NOW())\n GROUP BY sol.product_id\n)\nSELECT pp.default_code\ | |
| \ AS product_code,\n ps.total_quantity\nFROM product_sales ps\nJOIN product_product\ | |
| \ pp ON pp.id = ps.product_id\nORDER BY total_quantity DESC\nLIMIT 5;\n" | |
| tags: | |
| - sales | |
| - quantity | |
| - id: L5-053 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Find the total number of sales orders and total revenue generated by each customer | |
| this year. | |
| gold_sql: "WITH customer_sales AS (\n SELECT so.partner_id,\n COUNT(so.id)\ | |
| \ AS order_count,\n SUM(so.amount_total) AS total_revenue\n FROM sale_order\ | |
| \ so\n WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY so.partner_id\n)\nSELECT rp.name AS customer,\n cs.order_count,\n\ | |
| \ cs.total_revenue\nFROM customer_sales cs\nJOIN res_partner rp ON rp.id\ | |
| \ = cs.partner_id\nORDER BY total_revenue DESC;\n" | |
| tags: | |
| - customer | |
| - sales | |
| - id: L5-054 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Calculate the total sales revenue for each product this year, grouped by product | |
| category. | |
| gold_sql: "WITH product_revenue AS (\n SELECT pp.id AS product_id,\n SUM(sol.price_subtotal)\ | |
| \ AS total_revenue,\n pt.categ_id\n FROM sale_order_line sol\n JOIN\ | |
| \ sale_order so ON so.id = sol.order_id\n JOIN product_product pp ON pp.id =\ | |
| \ sol.product_id\n JOIN product_template pt ON pt.id = pp.product_tmpl_id\n \ | |
| \ WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY pp.id, pt.categ_id\n)\nSELECT pc.name AS category,\n \ | |
| \ SUM(pr.total_revenue) AS total_revenue\nFROM product_revenue pr\nJOIN product_category\ | |
| \ pc ON pc.id = pr.categ_id\nGROUP BY pc.name\nORDER BY total_revenue DESC;\n" | |
| tags: | |
| - sales | |
| - category | |
| - id: L4-053 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of products in stock by location, including the reserved | |
| quantity. | |
| gold_sql: 'SELECT location_id, SUM(quantity) AS total_quantity, SUM(reserved_quantity) | |
| AS total_reserved | |
| FROM stock_quant | |
| GROUP BY location_id; | |
| ' | |
| tags: | |
| - inventory | |
| - total_quantity | |
| - id: L4-054 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: List locations with their maximum inventory quantity of products. | |
| gold_sql: 'SELECT location_id, MAX(inventory_quantity) AS max_inventory | |
| FROM stock_quant | |
| GROUP BY location_id; | |
| ' | |
| tags: | |
| - inventory | |
| - max_quantity | |
| - id: L4-055 | |
| level: 4 | |
| domains: | |
| - inventory | |
| nl: Get the total inventory quantity of products that have been reserved, grouped | |
| by product. | |
| gold_sql: 'SELECT product_id, SUM(reserved_quantity) AS total_reserved_quantity | |
| FROM stock_quant | |
| WHERE reserved_quantity > 0 | |
| GROUP BY product_id; | |
| ' | |
| tags: | |
| - inventory | |
| - reserved_products | |
| - id: L3-124 | |
| level: 3 | |
| domains: | |
| - demand | |
| nl: Determine the total sales amount per company for the last year. | |
| gold_sql: "SELECT so.company_id, SUM(so.amount_total) AS total_sales\nFROM sale_order\ | |
| \ so\nWHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW()) - INTERVAL '1 year'\nGROUP BY so.company_id\nORDER BY total_sales DESC;\n" | |
| tags: | |
| - demand | |
| - sales | |
| - company | |
| - id: L3-125 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: What is the total quantity of products moved from each warehouse? | |
| gold_sql: 'SELECT w.name AS warehouse, SUM(sm.product_id) AS total_moved | |
| FROM stock_move sm | |
| JOIN stock_location sl ON sl.id = sm.location_id | |
| JOIN stock_warehouse w ON w.id = sl.warehouse_id | |
| GROUP BY w.name | |
| ORDER BY total_moved DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L3-126 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: List the total inventory quantity of each product across different locations. | |
| gold_sql: 'SELECT pp.default_code AS product_code, SUM(sq.inventory_quantity) AS | |
| total_inventory | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| GROUP BY pp.default_code | |
| ORDER BY total_inventory DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - group_by_two | |
| - id: L3-127 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show total reserved quantity for each product in each warehouse. | |
| gold_sql: 'SELECT pp.default_code AS product_code, w.name AS warehouse, SUM(sq.reserved_quantity) | |
| AS total_reserved | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| JOIN stock_warehouse w ON w.id = sl.warehouse_id | |
| GROUP BY pp.default_code, w.name | |
| ORDER BY total_reserved DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - group_by_two | |
| - id: L3-128 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of products that have been moved on each picking type. | |
| gold_sql: 'SELECT sp.picking_type_id, SUM(sm.product_id) AS total_moved | |
| FROM stock_move sm | |
| JOIN stock_picking sp ON sp.id = sm.picking_id | |
| GROUP BY sp.picking_type_id | |
| ORDER BY total_moved DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - aggregate | |
| - id: L5-055 | |
| level: 5 | |
| domains: | |
| - demand | |
| nl: Find the average discount applied to orders by each sales team over the past | |
| year. | |
| gold_sql: "WITH team_discounts AS (\n SELECT st.id AS team_id,\n AVG(so.amount_total\ | |
| \ - so.amount_untaxed) AS avg_discount\n FROM sale_order so\n JOIN crm_team\ | |
| \ st ON st.id = so.team_id\n WHERE so.state IN ('sale','done')\n AND so.date_order\ | |
| \ >= date_trunc('year', NOW()) - INTERVAL '1 year'\n GROUP BY st.id\n)\nSELECT\ | |
| \ st.name AS sales_team,\n COALESCE(td.avg_discount, 0) AS avg_discount\n\ | |
| FROM crm_team st\nLEFT JOIN team_discounts td ON td.team_id = st.id\nORDER BY\ | |
| \ avg_discount DESC;\n" | |
| tags: | |
| - financial | |
| - team_performance | |
| - id: L4-056 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Determine the average quantity sold per product for the current year. | |
| gold_sql: "WITH product_sales AS (\n SELECT sol.product_id, AVG(sol.product_uom_qty)\ | |
| \ AS avg_quantity_sold\n FROM sale_order_line sol\n JOIN sale_order so ON so.id\ | |
| \ = sol.order_id\n WHERE so.state IN ('sale','done')\n AND so.date_order >=\ | |
| \ date_trunc('year', NOW())\n GROUP BY sol.product_id\n)\nSELECT pp.default_code,\n\ | |
| \ ps.avg_quantity_sold\nFROM product_sales ps\nJOIN product_product pp ON\ | |
| \ pp.id = ps.product_id\nORDER BY ps.avg_quantity_sold DESC;\n" | |
| tags: | |
| - product_sales | |
| - average_metrics | |
| - id: L4-057 | |
| level: 4 | |
| domains: | |
| - demand | |
| nl: Identify the month with the highest sales revenue this year. | |
| gold_sql: "WITH monthly_revenue AS (\n SELECT date_trunc('month', so.date_order)\ | |
| \ AS month,\n SUM(so.amount_total) AS total_revenue\n FROM sale_order\ | |
| \ so\n WHERE so.state IN ('sale','done')\n AND so.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY month\n)\nSELECT month,\n total_revenue\nFROM monthly_revenue\n\ | |
| ORDER BY total_revenue DESC\nLIMIT 1;\n" | |
| tags: | |
| - monthly_analysis | |
| - financial_metrics | |
| - id: L5-056 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Find the total quantity of products available in stock for each product type | |
| across all warehouses. | |
| gold_sql: "WITH total_quantities AS (\n SELECT product_id, SUM(quantity) AS total_qty\n\ | |
| \ FROM stock_quant\n GROUP BY product_id\n)\nSELECT pp.default_code AS product_code,\n\ | |
| \ tq.total_qty\nFROM total_quantities tq\nJOIN product_product pp ON pp.id\ | |
| \ = tq.product_id\nORDER BY tq.total_qty DESC;\n" | |
| tags: | |
| - inventory | |
| - total_quantity | |
| - id: L5-057 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: List the products with the highest inventory quantity along with their respective | |
| inventory dates. | |
| gold_sql: "WITH highest_inventory AS (\n SELECT product_id, MAX(inventory_quantity)\ | |
| \ AS max_inventory\n FROM stock_quant\n GROUP BY product_id\n)\nSELECT pp.default_code\ | |
| \ AS product_code,\n hi.max_inventory,\n sq.inventory_date\nFROM highest_inventory\ | |
| \ hi\nJOIN stock_quant sq ON sq.product_id = hi.product_id AND sq.inventory_quantity\ | |
| \ = hi.max_inventory\nJOIN product_product pp ON pp.id = hi.product_id\nORDER\ | |
| \ BY hi.max_inventory DESC;\n" | |
| tags: | |
| - inventory | |
| - highest_inventory | |
| - id: L5-058 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Calculate the total quantity of products moved for each product across all picking | |
| types. | |
| gold_sql: "WITH total_moved AS (\n SELECT product_id, SUM(quantity) AS total_moved_qty\n\ | |
| \ FROM stock_move_line\n GROUP BY product_id\n)\nSELECT pp.default_code AS product_code,\n\ | |
| \ tm.total_moved_qty\nFROM total_moved tm\nJOIN product_product pp ON pp.id\ | |
| \ = tm.product_id\nORDER BY tm.total_moved_qty DESC;\n" | |
| tags: | |
| - inventory | |
| - total_moved | |
| - id: L5-059 | |
| level: 5 | |
| domains: | |
| - inventory | |
| nl: Determine the total inventory for each product across different storage categories. | |
| gold_sql: "WITH inventory_by_category AS (\n SELECT product_id, storage_category_id,\ | |
| \ SUM(inventory_quantity) AS total_inventory\n FROM stock_quant\n GROUP BY product_id,\ | |
| \ storage_category_id\n)\nSELECT pp.default_code AS product_code,\n ibc.storage_category_id,\n\ | |
| \ ibc.total_inventory\nFROM inventory_by_category ibc\nJOIN product_product\ | |
| \ pp ON pp.id = ibc.product_id\nORDER BY pp.default_code, ibc.storage_category_id;\n" | |
| tags: | |
| - inventory | |
| - inventory_by_category | |
| - id: L4-058 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Calculate the total number of stock moves and the average quantity per product | |
| for this year. | |
| gold_sql: "WITH product_movements AS (\n SELECT sm.product_id, COUNT(sm.id) AS\ | |
| \ total_moves, AVG(sm.product_qty) AS avg_qty\n FROM stock_move sm\n JOIN purchase_order_line\ | |
| \ pol ON pol.product_id = sm.product_id\n JOIN purchase_order po ON po.id = pol.order_id\n\ | |
| \ WHERE po.state IN ('purchase','done')\n AND po.date_order >= date_trunc('year',\ | |
| \ NOW())\n GROUP BY sm.product_id\n)\nSELECT pp.default_code AS product_code,\ | |
| \ pm.total_moves, pm.avg_qty\nFROM product_movements pm\nJOIN product_product\ | |
| \ pp ON pp.id = pm.product_id\nORDER BY pm.total_moves DESC;\n" | |
| tags: | |
| - stock_performance | |
| - cte | |
| - id: L4-059 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Determine the number of purchase orders and the average price subtotal per supplier | |
| for the current year. | |
| gold_sql: "WITH supplier_summary AS (\n SELECT po.partner_id, COUNT(po.id) AS total_orders,\ | |
| \ AVG(pol.price_subtotal) AS avg_subtotal\n FROM purchase_order po\n JOIN purchase_order_line\ | |
| \ pol ON pol.order_id = po.id\n WHERE po.state IN ('purchase','done')\n AND\ | |
| \ po.date_order >= date_trunc('year', NOW())\n GROUP BY po.partner_id\n)\nSELECT\ | |
| \ rp.name AS supplier, ss.total_orders, ss.avg_subtotal\nFROM supplier_summary\ | |
| \ ss\nJOIN res_partner rp ON rp.id = ss.partner_id\nORDER BY ss.total_orders DESC;\n" | |
| tags: | |
| - supplier_analysis | |
| - cte | |
| - id: L4-060 | |
| level: 4 | |
| domains: | |
| - logistics | |
| nl: Show the average quantity and total price received per product from suppliers | |
| this year. | |
| gold_sql: "WITH received_products AS (\n SELECT sm.product_id, SUM(pol.product_qty)\ | |
| \ AS total_qty, SUM(pol.price_subtotal) AS total_price\n FROM stock_move sm\n\ | |
| \ JOIN purchase_order_line pol ON pol.product_id = sm.product_id\n JOIN purchase_order\ | |
| \ po ON po.id = pol.order_id\n WHERE po.state IN ('purchase','done')\n AND\ | |
| \ po.date_order >= date_trunc('year', NOW())\n GROUP BY sm.product_id\n)\nSELECT\ | |
| \ pp.default_code AS product_code, rp.total_qty, rp.total_price / NULLIF(rp.total_qty,\ | |
| \ 0) AS avg_price\nFROM received_products rp\nJOIN product_product pp ON pp.id\ | |
| \ = rp.product_id\nORDER BY rp.total_qty DESC;\n" | |
| tags: | |
| - product_performance | |
| - cte | |
| - id: L3-129 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Show total reserved quantity of products grouped by warehouse. | |
| gold_sql: 'SELECT w.id AS warehouse_id, SUM(sq.reserved_quantity) AS total_reserved_quantity | |
| FROM stock_quant sq | |
| JOIN stock_location sl ON sl.id = sq.location_id | |
| JOIN stock_warehouse w ON w.id = sl.warehouse_id | |
| GROUP BY w.id | |
| ORDER BY total_reserved_quantity DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - group_by | |
| - id: L3-130 | |
| level: 3 | |
| domains: | |
| - inventory | |
| nl: Get total inventory quantity for each product based on their lot. | |
| gold_sql: 'SELECT sq.lot_id, pp.default_code AS product_code, SUM(sq.inventory_quantity) | |
| AS total_inventory | |
| FROM stock_quant sq | |
| JOIN product_product pp ON pp.id = sq.product_id | |
| GROUP BY sq.lot_id, pp.default_code | |
| ORDER BY total_inventory DESC; | |
| ' | |
| tags: | |
| - inventory | |
| - group_by | |
| - id: L5-060 | |
| level: 5 | |
| domains: | |
| - finance | |
| nl: List the average transaction amounts per account type for the last six months. | |
| gold_sql: "WITH transaction_totals AS (\n SELECT account_id,\n AVG(debit\ | |
| \ - credit) AS average_transaction\n FROM account_move_line\n WHERE move_id\ | |
| \ IN (\n SELECT id FROM account_move\n WHERE date >= date_trunc('month',\ | |
| \ NOW()) - interval '6 months'\n )\n GROUP BY account_id\n)\nSELECT aa.account_type,\n\ | |
| \ AVG(tt.average_transaction) AS avg_transaction_amount\nFROM transaction_totals\ | |
| \ tt\nJOIN account_account aa ON aa.id = tt.account_id\nGROUP BY aa.account_type\n\ | |
| ORDER BY avg_transaction_amount DESC;\n" | |
| tags: | |
| - finance | |
| - transactions | |
| - account_type | |