Commit 3912504f authored by Jérome Perrin's avatar Jérome Perrin

fixup! accounting: fix validation of accounting transactions with too precise amounts

there was also another script for internal
parent 56c827ac
Pipeline #12357 failed with stage
in 0 seconds
......@@ -8,21 +8,31 @@ total_source_asset_credit = 0
total_destination_asset_debit = 0
total_destination_asset_credit = 0
currency_precision = context.getQuantityPrecisionFromResource(context.getResource())
source_section_precision = 2
source_section = context.getSourceSectionValue(portal_type='Organisation')
if source_section is not None:
source_section_precision = context.getQuantityPrecisionFromResource(source_section.getPriceCurrency())
destination_section_precision = 2
destination_section = context.getDestinationSectionValue(portal_type='Organisation')
if destination_section is not None:
destination_section_precision = context.getQuantityPrecisionFromResource(destination_section.getPriceCurrency())
source_section = context.getSourceSection()
destination_section = context.getDestinationSection()
for line in context.objectValues(
portal_type = context.getPortalAccountingMovementTypeList()) :
if line.getSource() and line.getSourceSection() == source_section:
total_source_debit += line.getSourceDebit()
total_source_asset_debit += line.getSourceInventoriatedTotalAssetDebit()
total_source_credit += line.getSourceCredit()
total_source_asset_credit += line.getSourceInventoriatedTotalAssetCredit()
total_source_debit += round(line.getSourceDebit(), currency_precision)
total_source_asset_debit += round(line.getSourceInventoriatedTotalAssetDebit(), source_section_precision)
total_source_credit += round(line.getSourceCredit(), currency_precision)
total_source_asset_credit += round(line.getSourceInventoriatedTotalAssetCredit(), source_section_precision)
if line.getDestination()\
and line.getDestinationSection() == destination_section:
total_destination_debit += line.getDestinationDebit()
total_destination_asset_debit += line.getDestinationInventoriatedTotalAssetDebit()
total_destination_credit += line.getDestinationCredit()
total_destination_asset_credit += line.getDestinationInventoriatedTotalAssetCredit()
total_destination_debit += round(line.getDestinationDebit(), currency_precision)
total_destination_asset_debit += round(line.getDestinationInventoriatedTotalAssetDebit(), destination_section_precision)
total_destination_credit += round(line.getDestinationCredit(), currency_precision)
total_destination_asset_credit += round(line.getDestinationInventoriatedTotalAssetCredit(), destination_section_precision)
return [Object(
source_debit=total_source_debit,
......
......@@ -5984,6 +5984,52 @@ class TestInternalInvoiceTransaction(AccountingTestCase):
for line in payment.getMovementList(
portal_type='Internal Invoice Transaction Line')])
def test_InternalInvoiceTransaction_statInternalTransactionLineList(self):
internal_invoice = self.portal.accounting_module.newContent(
portal_type='Internal Invoice Transaction',
source_section_value=self.section,
destination_section_value=self.main_section,
start_date=DateTime(2015, 1, 1),
created_by_builder=True,
)
# line1 counts for both source and destination
internal_invoice.newContent(
source_value=self.portal.account_module.receivable,
destination_value=self.portal.account_module.receivable,
source_debit=1, # destination_credit=1
source_asset_debit=0.1111111,
destination_asset_credit=0.222222,
)
# line2 does not count for source, it's another section
internal_invoice.newContent(
source_section_value=self.portal.organisation_module.client_1,
source_value=self.portal.account_module.receivable,
destination_value=self.portal.account_module.receivable,
destination_debit=3,
destination_asset_debit=0.44444,
source_asset_debit=10000,
)
# line3 does not count for destination, it's another section
internal_invoice.newContent(
source_value=self.portal.account_module.receivable,
destination_value=self.portal.account_module.receivable,
destination_section_value=self.portal.organisation_module.client_1,
source_credit=5,
source_asset_credit=0.555555,
destination_asset_debit=1000,
)
stat_internal_transaction, = internal_invoice.InternalInvoiceTransaction_statInternalTransactionLineList()
self.assertEqual(stat_internal_transaction.source_debit, 1) # line1
self.assertEqual(stat_internal_transaction.source_asset_debit, 0.11) # line1
self.assertEqual(stat_internal_transaction.source_credit, 5) # line3
self.assertEqual(stat_internal_transaction.source_asset_credit, 0.56) # line3
self.assertEqual(stat_internal_transaction.destination_debit, 3) # line2
self.assertEqual(stat_internal_transaction.destination_asset_debit, 0.44) # line2
self.assertEqual(stat_internal_transaction.destination_credit, 1) # line1
self.assertEqual(stat_internal_transaction.destination_asset_credit, 0.22) # line1
class TestAccountingAlarms(AccountingTestCase):
def test_check_payable_receivable_account_grouped(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment