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.

55 lines
1.2 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 res_partner AS part ON (ml.partner_id = part.id)
  19. INNER JOIN account_move AS m ON (ml.move_id = m.id)
  20. WINDOW w_account AS (
  21. PARTITION BY acc.code
  22. ORDER BY ml.date, ml.id
  23. )
  24. ORDER BY acc.id, ml.date
  25. )
  26. INSERT INTO ledger_report_wizard_line (
  27. date,
  28. name,
  29. journal_id,
  30. account_id,
  31. partner_id,
  32. ref,
  33. label,
  34. --counterpart
  35. debit,
  36. credit,
  37. cumul_balance,
  38. wizard_id
  39. )
  40. SELECT
  41. date,
  42. name,
  43. journal_id,
  44. account_id,
  45. partner_id,
  46. ref,
  47. ' TODO label ' as label,
  48. --counterpart
  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;
  55. -- WHERE date >= %(fy_date)s