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

  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) OVER w_account - debit AS init_debit,
  12. SUM(credit) OVER w_account - credit AS init_credit,
  13. SUM(debit - credit) OVER w_account - (debit - credit) AS init_balance,
  14. SUM(debit - credit) OVER w_account AS cumul_balance
  15. FROM
  16. account_account AS acc
  17. LEFT JOIN account_move_line AS ml ON (ml.account_id = acc.id)
  18. INNER JOIN account_move AS m ON (ml.move_id = m.id)
  19. WINDOW w_account AS (
  20. PARTITION BY acc.code
  21. ORDER BY ml.date, ml.id
  22. )
  23. ORDER BY acc.id, ml.date
  24. )
  25. INSERT INTO ledger_report_wizard_line (
  26. date,
  27. name,
  28. journal_id,
  29. account_id,
  30. partner_id,
  31. ref,
  32. label,
  33. --counterpart
  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. debit,
  49. credit,
  50. cumul_balance,
  51. %(wizard_id)s as wizard_id
  52. FROM view_q
  53. WHERE date BETWEEN %(date_from)s AND %(date_to)s;
  54. -- WHERE date >= %(fy_date)s