def checkFacts(facts): for f in facts: cntx = f.context unit = f.unit if getattr(f,"xValid", 0) >= 4 and cntx is not None and f.concept is not None: factNamespaceURI = f.qname.namespaceURI factLocalName = f.qname.localName if factLocalName in mandatoryItems[val.txmyType]: mandatoryFacts[factLocalName] = f if factLocalName == "UKCompaniesHouseRegisteredNumber" and val.isAccounts: if hasCompaniesHouseContext: mandatoryFacts[factLocalName] = f for _cntx in contextsUsed: _scheme, _identifier = _cntx.entityIdentifier if _scheme == "http://www.companieshouse.gov.uk/" and f.xValue != _identifier: modelXbrl.error("JFCVC.3316", _("Context entity identifier %(identifier)s does not match Company Reference Number (UKCompaniesHouseRegisteredNumber) Location: Accounts (context id %(id)s)"), modelObject=(f, _cntx), identifier=_identifier, id=_cntx.id) if not f.isNil: factForConceptContextUnitLangHash[f.conceptContextUnitLangHash].append(f) if f.isNumeric: if f.precision: modelXbrl.error("HMRC.5.4", _("Numeric fact %(fact)s of context %(contextID)s has a precision attribute '%(precision)s'"), modelObject=f, fact=f.qname, contextID=f.contextID, precision=f.precision) try: # only process validated facts if not f.isNil: if f.xValue < 0: label = f.concept.label(lang="en") if not labelHasNegativeTermPattern.match(label): modelXbrl.error("HMRC.5.3", _("Numeric fact %(fact)s of context %(contextID)s has a negative value '%(value)s' but label does not have a bracketed negative term (using parentheses): %(label)s"), modelObject=f, fact=f.qname, contextID=f.contextID, value=f.value, label=label) # 6.5.37 test (insignificant digits due to rounding) if f.decimals and f.decimals != "INF": try: insignificance = insignificantDigits(f.xValue, decimals=f.decimals) if insignificance: # if not None, returns (truncatedDigits, insiginficantDigits) modelXbrl.error("HMRC.SG.4.5", _("Fact %(fact)s of context %(contextID)s decimals %(decimals)s value %(value)s has nonzero digits in insignificant portion %(insignificantDigits)s."), modelObject=f, fact=f.qname, contextID=f.contextID, decimals=f.decimals, value=f.xValue, truncatedDigits=insignificance[0], insignificantDigits=insignificance[1]) except (ValueError,TypeError): modelXbrl.error("HMRC.SG.4.5", _("Fact %(fact)s of context %(contextID)s decimals %(decimals)s value %(value)s causes Value Error exception."), modelObject=f1, fact=f1.qname, contextID=f1.contextID, decimals=f1.decimals, value=f1.value) except AttributeError: pass # if not validated it should have failed with a schema error # check GDV if f.qname.localName in mandatoryGDV: _gdvReqList = mandatoryGDV[factLocalName] _gdvReqRemovals = [] for _gdvReq in _gdvReqList: if any(_gdvReq.memLocalName == dim.memberQname.localName for dim in cntx.qnameDims.values() if dim.isExplicit): _gdvReqRemovals.append(_gdvReq) if _gdvReq.altFact in mandatoryGDV: _gdvAltList = mandatoryGDV[_gdvReq.altFact] _gdvAltRemovals = [] for _gdvAlt in _gdvAltList: if any(_gdvAlt.memLocalName == dim.memberQname.localName for dim in cntx.qnameDims.values() if dim.isExplicit): _gdvAltRemovals.append(_gdvAlt) for _gdvAlt in _gdvAltRemovals: _gdvAltList.remove(_gdvAlt) if _gdvReqRemovals and not f.xValue: # fact was a mandatory name or description modelXbrl.error("JFCVC.3315", _("Generic dimension members associated name/description has no text: %(fact)s"), modelObject=f, fact=f.qname) for _gdvReq in _gdvReqRemovals: _gdvReqList.remove(_gdvReq) if f.modelTupleFacts: checkFacts(f.modelTupleFacts)
def checkFacts(facts): for f in facts: cntx = f.context unit = f.unit if ( f.isNil or getattr(f, "xValid", 0) >= 4 ) and cntx is not None and f.concept is not None and f.concept.type is not None: factNamespaceURI = f.qname.namespaceURI factLocalName = f.qname.localName if factLocalName in mandatoryItems[val.txmyType]: mandatoryFacts[factLocalName] = f if factLocalName == "UKCompaniesHouseRegisteredNumber" and val.isAccounts: if hasCompaniesHouseContext: mandatoryFacts[factLocalName] = f for _cntx in contextsUsed: _scheme, _identifier = _cntx.entityIdentifier if _scheme == "http://www.companieshouse.gov.uk/" and f.xValue != _identifier: modelXbrl.error( "JFCVC.3316", _("Context entity identifier %(identifier)s does not match Company Reference Number (UKCompaniesHouseRegisteredNumber) Location: Accounts (context id %(id)s)" ), modelObject=(f, _cntx), identifier=_identifier, id=_cntx.id) if f.parentElement.qname == qnXbrliXbrl: # JFCVC v4.0 - only check non-tuple facts factForConceptContextUnitHash[ f.conceptContextUnitHash].append(f) if f.isNumeric: if f.precision: modelXbrl.error( "HMRC.5.4", _("Numeric fact %(fact)s of context %(contextID)s has a precision attribute '%(precision)s'" ), modelObject=f, fact=f.qname, contextID=f.contextID, precision=f.precision) try: # only process validated facts if not f.isNil: if f.xValue < 0: label = f.concept.label(lang="en") if not labelHasNegativeTermPattern.match( label): modelXbrl.error( "HMRC.5.3", _("Numeric fact %(fact)s of context %(contextID)s has a negative value '%(value)s' but label does not have a bracketed negative term (using parentheses): %(label)s" ), modelObject=f, fact=f.qname, contextID=f.contextID, value=f.value, label=label) # 6.5.37 test (insignificant digits due to rounding) if f.decimals and f.decimals != "INF": try: insignificance = insignificantDigits( f.xValue, decimals=f.decimals) if insignificance: # if not None, returns (truncatedDigits, insiginficantDigits) modelXbrl.error( "HMRC.SG.4.5", _("Fact %(fact)s of context %(contextID)s decimals %(decimals)s value %(value)s has nonzero digits in insignificant portion %(insignificantDigits)s." ), modelObject=f, fact=f.qname, contextID=f.contextID, decimals=f.decimals, value=f.xValue, truncatedDigits=insignificance[ 0], insignificantDigits= insignificance[1]) except (ValueError, TypeError): modelXbrl.error( "HMRC.SG.4.5", _("Fact %(fact)s of context %(contextID)s decimals %(decimals)s value %(value)s causes Value Error exception." ), modelObject=f1, fact=f1.qname, contextID=f1.contextID, decimals=f1.decimals, value=f1.value) except AttributeError: pass # if not validated it should have failed with a schema error # check GDV if f.qname.localName in mandatoryGDV: _gdvReqList = mandatoryGDV[factLocalName] _gdvReqRemovals = [] for _gdvReq in _gdvReqList: if any(_gdvReq.memLocalName == dim.memberQname.localName for dim in cntx.qnameDims.values() if dim.isExplicit): _gdvReqRemovals.append(_gdvReq) if _gdvReq.altFact in mandatoryGDV: _gdvAltList = mandatoryGDV[_gdvReq.altFact] _gdvAltRemovals = [] for _gdvAlt in _gdvAltList: if any(_gdvAlt.memLocalName == dim.memberQname.localName for dim in cntx.qnameDims.values() if dim.isExplicit): _gdvAltRemovals.append(_gdvAlt) for _gdvAlt in _gdvAltRemovals: _gdvAltList.remove(_gdvAlt) if _gdvReqRemovals and not f.xValue: # fact was a mandatory name or description modelXbrl.error( "JFCVC.3315", _("Generic dimension members associated name/description has no text: %(fact)s" ), modelObject=f, fact=f.qname) for _gdvReq in _gdvReqRemovals: _gdvReqList.remove(_gdvReq) if f.modelTupleFacts: checkFacts(f.modelTupleFacts)