Skip to content

Commit

Permalink
fixup! [IMP] calculate opening debit, credit from balance of opening …
Browse files Browse the repository at this point in the history
…lines
  • Loading branch information
hbrunn committed Mar 19, 2024
1 parent db18af4 commit 147a1ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions l10n_nl_xaf_auditfile_export/models/xaf_auditfile_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def get_ob_sql_fragment(self):
def get_ob_totals(self):
"""return totals of opening balance"""
self.env.cr.execute(
# pylint: disable=sql-injection
"select sum(l.balance), count(distinct a.id) " +
self.get_ob_sql_fragment() +
"and l.balance < 0"
Expand All @@ -282,6 +283,7 @@ def get_ob_totals(self):
count=row[1] or 0,
)
self.env.cr.execute(
# pylint: disable=sql-injection
"select sum(l.balance), count(distinct a.id) " +
self.get_ob_sql_fragment() +
"and l.balance > 0"
Expand All @@ -295,6 +297,7 @@ def get_ob_totals(self):
def get_ob_lines(self):
"""return opening balance entries"""
self.env.cr.execute(
# pylint: disable=sql-injection
"select a.id, a.code, sum(l.balance) " +
self.get_ob_sql_fragment() +
"group by a.id, a.code",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import os
from zipfile import ZipFile


from odoo.tests.common import TransactionCase
from odoo.tools import mute_logger

Expand All @@ -21,7 +22,9 @@ def xaf_xpath(auditfile, query):
remove_blank_text=True
)
root = etree.XML(bytes(contents, encoding='utf8'), parser=parser)
for element in root.xpath(query, namespaces={'a': 'http://www.auditfiles.nl/XAF/3.2'}):
for element in root.xpath(
query, namespaces={'a': 'http://www.auditfiles.nl/XAF/3.2'}
):
yield element


Expand Down Expand Up @@ -161,7 +164,10 @@ def test_07_opening_balance(self):
record = self.env['xaf.auditfile.export'].create({})

acc_receivable = self.env['account.account'].search([
('user_type_id', '=', self.env.ref('account.data_account_type_receivable').id),
(
'user_type_id', '=',
self.env.ref('account.data_account_type_receivable').id
),
], limit=1)
acc_payable = self.env['account.account'].search([
('user_type_id', '=', self.env.ref('account.data_account_type_payable').id),
Expand Down Expand Up @@ -194,20 +200,25 @@ def test_07_opening_balance(self):
def xaf_val(auditfile, xpath):
return float(''.join(xaf_xpath(auditfile, xpath)))

total_credit = xaf_val(record.auditfile, '//a:openingBalance/a:totalCredit/text()')
total_credit = xaf_val(
record.auditfile, '//a:openingBalance/a:totalCredit/text()')
self.assertEqual(total_credit, 42)
result = record.get_ob_totals()
total_debit = xaf_val(record.auditfile, '//a:openingBalance/a:totalDebit/text()')
total_debit = xaf_val(
record.auditfile, '//a:openingBalance/a:totalDebit/text()')
self.assertEqual(total_debit, 0)
lines_count = xaf_val(record.auditfile, '//a:openingBalance/a:linesCount/text()')
lines_count = xaf_val(
record.auditfile, '//a:openingBalance/a:linesCount/text()')
self.assertEqual(lines_count, 1)

move_payable.post()
record = self.env['xaf.auditfile.export'].create({})
record.button_generate()
total_credit = xaf_val(record.auditfile, '//a:openingBalance/a:totalCredit/text()')
total_credit = xaf_val(
record.auditfile, '//a:openingBalance/a:totalCredit/text()')
self.assertEqual(total_credit, 42)
total_debit = xaf_val(record.auditfile, '//a:openingBalance/a:totalDebit/text()')
total_debit = xaf_val(
record.auditfile, '//a:openingBalance/a:totalDebit/text()')
self.assertEqual(total_debit, 4242)
lines_count = xaf_val(record.auditfile, '//a:openingBalance/a:linesCount/text()')
lines_count = xaf_val(
record.auditfile, '//a:openingBalance/a:linesCount/text()')
self.assertEqual(lines_count, 2)

0 comments on commit 147a1ff

Please sign in to comment.