Skip to content

Commit

Permalink
Merge pull request #843 from hermfischer-wf/calc1.1-inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
austinmatherne-wk committed Dec 21, 2023
2 parents 14a614d + e732b53 commit a6ae836
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 45 deletions.
9 changes: 9 additions & 0 deletions arelle/ModelDtsObject.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,15 @@ def isNumeric(self):
self._isNumeric = XbrlConst.isNumericXsdType(self.baseXsdType)
return self._isNumeric

@property
def isDecimal(self):
"""(bool) -- True for a decimal xsd base type (not including xbrl fractions, float or double)"""
try:
return self._isDecimal
except AttributeError:
self._isDecimal = XbrlConst.isDecimalXsdType(self.baseXsdType)
return self._isDecimal

@property
def isInteger(self):
"""(bool) -- True for elements of, or derived from, integer base type (not including fractionItemType)"""
Expand Down
12 changes: 9 additions & 3 deletions arelle/ValidateXbrlCalcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ def validate(self):
modelObject=(siRels[itemConcept], modelRel), linkrole=modelRel.linkrole,
sumConcept=sumConcept.qname, itemConcept=itemConcept.qname)
siRels[itemConcept] = modelRel
if not sumConcept.isDecimal or not itemConcept.isDecimal:
modelXbrl.error("calc11e:nonDecimalItemNode",
_("The source and target of a Calculations v1.1 relationship MUST both be decimal concepts: %(sumConcept)s, %(itemConcept)s, link role %(linkrole)s"),
modelObject=(sumConcept, itemConcept, modelRel), linkrole=modelRel.linkrole,
sumConcept=sumConcept.qname, itemConcept=itemConcept.qname)

# add up rounded items
boundSums = defaultdict(decimal.Decimal) # sum of facts meeting factKey
boundIntervals = {} # interval sum of facts meeting factKey
Expand Down Expand Up @@ -298,7 +304,7 @@ def validate(self):
inclA = incls1 | inclx1
inclB = incls2 | inclx2
if (a == b and not (inclA and inclB)) or (a > b):
modelXbrl.error("calc11e:inconsistentCalculationUsing" + self.calc11suffix,
modelXbrl.log('INCONSISTENCY', "calc11e:inconsistentCalculationUsing" + self.calc11suffix,
_("Calculation inconsistent from %(concept)s in link role %(linkrole)s reported sum %(reportedSum)s computed sum %(computedSum)s context %(contextID)s unit %(unitID)s"),
modelObject=sumFacts + boundIntervalItems[sumBindKey],
concept=sumConcept.qname, linkrole=ELR,
Expand Down Expand Up @@ -452,14 +458,14 @@ def consistentFactValueInterval(self, fList, truncate=False) -> tuple[decimal.De
inclB |= _inclB
_inConsistent = (a == b and not(inclA and inclB)) or (a > b)
if _excessDigitFacts:
self.modelXbrl.error("calc11e:excessDigits",
self.modelXbrl.log('INCONSISTENCY', "calc11e:excessDigits",
_("Calculations check stopped for excess digits in fact values %(element)s: %(values)s, %(contextIDs)s."),
modelObject=fList, element=_excessDigitFacts[0].qname,
contextIDs=", ".join(sorted(set(f.contextID for f in _excessDigitFacts))),
values=", ".join(strTruncate(f.value,64) for f in _excessDigitFacts))
return (INCONSISTENT, INCONSISTENT,True,True)
if _inConsistent:
self.modelXbrl.error(
self.modelXbrl.log('INCONSISTENCY',
"calc11e:disallowedDuplicateFactsUsingTruncation" if self.calc11t else "oime:disallowedDuplicateFacts",
_("Calculations check stopped for duplicate fact values %(element)s: %(values)s, %(contextIDs)s."),
modelObject=fList, element=fList[0].qname,
Expand Down
19 changes: 19 additions & 0 deletions arelle/XbrlConst.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,25 @@ def isNumericXsdType(xsdType: str) -> bool:
}


def isDecimalXsdType(xsdType: str) -> bool:
return xsdType in {
"integer",
"positiveInteger",
"negativeInteger",
"nonNegativeInteger",
"nonPositiveInteger",
"long",
"unsignedLong",
"int",
"unsignedInt",
"short",
"unsignedShort",
"byte",
"unsignedByte",
"decimal",
}


def isIntegerXsdType(xsdType: str) -> bool:
return xsdType in {
"integer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,9 @@
from tests.integration_tests.validation.conformance_suite_config import ConformanceSuiteConfig

config = ConformanceSuiteConfig(
expected_failure_ids=frozenset(f'calculation-1.1-conformance-2023-02-22/{s}' for s in [
# The loadFromOIM plugin is required to load the conformance suite json
# files. However, OIM validation raises xbrlxe:unsupportedTuple for
# tuples which then raises calc11e:tuplesInReportWarning in calc 1.1.
# This isn't modeled in the conformance suite, but expected if both
# calc 1.1 and OIM validation are performed together.
# https://www.xbrl.org/Specification/xbrl-xml/REC-2021-10-13/xbrl-xml-REC-2021-10-13.html#unsupportedTuple
# https://www.xbrl.org/Specification/calculation-1.1/REC-2023-02-22/calculation-1.1-REC-2023-02-22.html#error-calc11e-tuplesinreportwarning
'calc11/index.xml:oim-tuple-consistent-round',
'calc11/index.xml:oim-tuple-consistent-truncate',
'calc11/index.xml:oim-tuple-ignored-calculation-round',
'calc11/index.xml:oim-tuple-ignored-calculation-truncate',
'xbrl21/index.xml:oim-tuple-consistent-round',
'xbrl21/index.xml:oim-tuple-consistent-truncate',
'xbrl21/index.xml:oim-tuple-ignored-calculation-round',
'xbrl21/index.xml:oim-tuple-ignored-calculation-truncate',

# Similar to the above, validation errors other than
# xbrlxe:unsupportedTuple are expected to raise
# calc11e:oimIncompatibleReportWarning during calc 1.1 validation.
# https://www.xbrl.org/Specification/calculation-1.1/REC-2023-02-22/calculation-1.1-REC-2023-02-22.html#error-calc11e-oimincompatiblereportwarning
'calc11/index.xml:oim-illegal-fraction-item-round',
'calc11/index.xml:oim-illegal-fraction-item-truncate',
'xbrl21/index.xml:oim-illegal-fraction-item-round',
'xbrl21/index.xml:oim-illegal-fraction-item-truncate',
]),
file='calculation-1.1-conformance-2023-02-22/index.xml',
file='calculation-1.1-conformance-2023-12-20/index.xml',
info_url='https://specifications.xbrl.org/work-product-index-calculations-2-calculations-1-1.html',
local_filepath='calculation-1.1-conformance-2023-02-22.zip',
local_filepath='calculation-1.1-conformance-2023-12-20.zip',
membership_url='https://www.xbrl.org/join',
name=PurePath(__file__).stem,
network_or_cache_required=False,
Expand Down
29 changes: 15 additions & 14 deletions tests/plugin/testcaseCalc11ValidateSetup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
'''
This plug-in removes xmlns="http://www.w3.org/1999/xhtml" from
escaped html in text content of expected instance facts for inline XBRL text facts
(c) Copyright 2019 Mark V Systems Limited, All rights reserved.
'''
try:
import regex as re
except ImportError:
import re
from arelle.XhtmlValidate import htmlEltUriAttrs, resolveHtmlUri
"""
See COPYRIGHT.md for copyright information.
"""
from arelle.ValidateXbrlCalcs import ValidateCalcsMode as CalcsMode
from arelle.Version import authorLabel, copyrightLabel


def testcaseVariationLoaded(testInstance, testcaseInstance, modelTestcaseVariation):
for result in modelTestcaseVariation.iter("{*}result"):
Expand All @@ -20,13 +14,20 @@ def testcaseVariationLoaded(testInstance, testcaseInstance, modelTestcaseVariati
elif v == "truncate":
testInstance.modelManager.validateCalcs = CalcsMode.TRUNCATION


def testcaseVariationExpectedResult(modelTestcaseVariation):
for result in modelTestcaseVariation.iter("{*}warning"):
return result.text


__pluginInfo__ = {
'name': 'Testcase obtain expected calc 11 mode from variation/result@mode',
'version': '0.9',
'description': "This plug-in removes xxx. ",
'license': 'Apache-2',
'author': 'Mark V Systems Limited',
'copyright': '(c) Copyright 2019 Mark V Systems Limited, All rights reserved.',
'license': "Apache-2",
'author': authorLabel,
'copyright': copyrightLabel,
# classes of mount points (required)
'TestcaseVariation.Xbrl.Loaded': testcaseVariationLoaded,
'ModelTestcaseVariation.ExpectedResult': testcaseVariationExpectedResult
}

0 comments on commit a6ae836

Please sign in to comment.