|
15 | 15 | from xbrl import XbrlParseException, TaxonomyNotFound
|
16 | 16 | from xbrl.cache import HttpCache
|
17 | 17 | from xbrl.helper.uri_resolver import resolve_uri
|
18 |
| -from xbrl.linkbase import Linkbase, ExtendedLink, LinkbaseType, parse_linkbase, parse_linkbase_url |
| 18 | +from xbrl.linkbase import Linkbase, ExtendedLink, LinkbaseType, parse_linkbase, parse_linkbase_url, Label |
19 | 19 |
|
20 | 20 | logger = logging.getLogger(__name__)
|
21 | 21 |
|
@@ -90,6 +90,7 @@ def __init__(self, xml_id: str, schema_url: str, name: str) -> None:
|
90 | 90 | self.nillable: bool or None = None
|
91 | 91 | self.period_type: str or None = None
|
92 | 92 | self.balance: str or None = None
|
| 93 | + self.labels: [Label] = [] |
93 | 94 |
|
94 | 95 | def __str__(self) -> str:
|
95 | 96 | return self.name
|
@@ -161,19 +162,19 @@ def __init__(self, schema_url: str, namespace: str):
|
161 | 162 | def __str__(self) -> str:
|
162 | 163 | return self.namespace
|
163 | 164 |
|
164 |
| - def get_taxonomy(self, namespace: str): |
| 165 | + def get_taxonomy(self, url: str): |
165 | 166 | """
|
166 | 167 | Returns the taxonomy with the given namespace (if it is the current taxonomy, or if it is imported)
|
167 | 168 | If the taxonomy cannot be found, the function will return None
|
168 |
| - :param namespace: |
| 169 | + :param url: can either be the namespace or the schema url |
169 | 170 | :return either a TaxonomySchema obj or None
|
170 | 171 | :return:
|
171 | 172 | """
|
172 |
| - if self.namespace == namespace: |
| 173 | + if self.namespace == url or self.schema_url == url: |
173 | 174 | return self
|
174 | 175 |
|
175 | 176 | for imported_tax in self.imports:
|
176 |
| - result = imported_tax.get_taxonomy(namespace) |
| 177 | + result = imported_tax.get_taxonomy(url) |
177 | 178 | if result is not None:
|
178 | 179 | return result
|
179 | 180 | return None
|
@@ -327,4 +328,18 @@ def parse_taxonomy(schema_path: str, cache: HttpCache, schema_url: str or None =
|
327 | 328 | elr.calculation_link = extended_cal_link
|
328 | 329 | break
|
329 | 330 |
|
| 331 | + for label_linkbase in taxonomy.lab_linkbases: |
| 332 | + for extended_link in label_linkbase.extended_links: |
| 333 | + for root_locator in extended_link.root_locators: |
| 334 | + # find the taxonomy the locator is referring to |
| 335 | + schema_url, concept_id = root_locator.href.split('#') |
| 336 | + c_taxonomy: TaxonomySchema = taxonomy.get_taxonomy(schema_url) |
| 337 | + if c_taxonomy is None: |
| 338 | + continue |
| 339 | + concept: Concept = c_taxonomy.concepts[concept_id] |
| 340 | + |
| 341 | + for children in root_locator.children: |
| 342 | + concept.labels = children.labels |
| 343 | + |
| 344 | + |
330 | 345 | return taxonomy
|
0 commit comments