Skip to content

Commit

Permalink
updated
Browse files Browse the repository at this point in the history
  • Loading branch information
satcfdi committed Mar 21, 2024
1 parent 46c6b23 commit a273b6f
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions satdigitalinvoice/file_data_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ def __init__(self, file_source=None):
class ProductosManager(LocalData):
file_source = "productos.yaml"

def __init__(self):
def __init__(self, file_source=None):
if file_source:
self.file_source = file_source

super().__init__()
if "Constants" in self:
del self["Constants"]
Expand All @@ -124,6 +127,7 @@ def __init__(self):


# function to deep merge two dictionaries
# add values to destination dictionary if they are not present
def deep_complement(destination, source):
for key, value in source.items():
if isinstance(value, dict):
Expand All @@ -137,7 +141,10 @@ def deep_complement(destination, source):
class FacturasManager(LocalData):
file_source = "facturas.yaml"

def __init__(self, dp: DatePeriod | date | None):
def __init__(self, dp: DatePeriod | date | None, file_source=None):
if file_source:
self.file_source = file_source

def loading_function(loader, node):
cases = loader.construct_mapping(node, deep=True)
if dp is None:
Expand All @@ -152,7 +159,11 @@ def loading_function(loader, node):
if dup := first_duplicate(json.dumps(x, sort_keys=True, default=str) for x in self["Facturas"]):
raise Exception("Factura Duplicada: {}".format(dup))

pm = ProductosManager()
if file_source:
fp = os.path.join(os.path.dirname(file_source), "productos.yaml")
pm = ProductosManager(fp)
else:
pm = ProductosManager()

for v in self["Facturas"]:
for c in v["Conceptos"]:
Expand Down

0 comments on commit a273b6f

Please sign in to comment.