You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1 KiB

9 years ago
9 years ago
9 years ago
  1. WITH view_q as (
  2. SELECT
  3. ml.date,
  4. acc.id AS account_id,
  5. ml.debit,
  6. ml.credit,
  7. ml.name AS name,
  8. ml.ref,
  9. ml.journal_id,
  10. ml.partner_id,
  11. SUM(debit - credit) OVER w_account - (debit - credit) AS init_balance,
  12. SUM(debit - credit) OVER w_account AS cumul_balance
  13. FROM account_account AS acc
  14. LEFT JOIN account_move_line AS ml ON (ml.account_id = acc.id)
  15. INNER JOIN account_move AS m ON (ml.move_id = m.id)
  16. INNER JOIN account_account_type aat ON (acc.user_type_id = aat.id)
  17. WHERE ml.date >= %(fy_date)s OR aat.include_initial_balance IS TRUE
  18. WINDOW w_account AS (
  19. PARTITION BY acc.code
  20. ORDER BY ml.date, ml.id
  21. )
  22. ORDER BY acc.id, ml.date
  23. )
  24. INSERT INTO ledger_report_wizard_line (
  25. date,
  26. name,
  27. journal_id,
  28. account_id,
  29. partner_id,
  30. ref,
  31. label,
  32. --counterpart
  33. init_balance,
  34. debit,
  35. credit,
  36. cumul_balance,
  37. wizard_id
  38. )
  39. SELECT
  40. date,
  41. name,
  42. journal_id,
  43. account_id,
  44. partner_id,
  45. ref,
  46. ' TODO label ' AS label,
  47. --counterpart
  48. init_balance,
  49. debit,
  50. credit,
  51. cumul_balance,
  52. %(wizard_id)s AS wizard_id
  53. FROM view_q
  54. WHERE date BETWEEN %(date_from)s AND %(date_to)s;