|
@@ -8,6 +8,7 @@ class PlannerLoad:
|
|
|
account_info: list = None
|
|
|
plan_values: list = None
|
|
|
marketing_values: list = None
|
|
|
+ new_structure: list
|
|
|
structure: list
|
|
|
config = {
|
|
|
'department': [1, 2, 3, 10, 30, 40, 50, 55, 81, 82],
|
|
@@ -20,6 +21,10 @@ class PlannerLoad:
|
|
|
self.base_dir = Path(base_dir)
|
|
|
|
|
|
def new_file(self, year: str):
|
|
|
+ self.load_values(year)
|
|
|
+ return self.convert_file(self.new_structure)
|
|
|
+
|
|
|
+ def load_values(self, year: str):
|
|
|
with open(self.base_dir.joinpath(f'accounts_{year}.json'), 'r') as frh:
|
|
|
self.account_values = json.load(frh)['values']
|
|
|
with open(self.base_dir.joinpath(f'planning_{year}.json'), 'r') as frh:
|
|
@@ -29,7 +34,10 @@ class PlannerLoad:
|
|
|
with open(self.base_dir.joinpath('gcstruct.json'), 'r') as frh:
|
|
|
gcstruct = json.load(frh)
|
|
|
self.account_info = dict([(a['Konto_Nr'], a) for a in gcstruct['accounts']])
|
|
|
- return self.convert_file(gcstruct['flat']['Struktur_FB'])
|
|
|
+ self.new_structure = gcstruct['flat']['Struktur_FB']
|
|
|
+
|
|
|
+ def set_structure(self, structure: list):
|
|
|
+ self.structure = structure
|
|
|
|
|
|
def convert_file(self, structure_source):
|
|
|
self.structure = []
|
|
@@ -86,35 +94,80 @@ class PlannerLoad:
|
|
|
return self.structure
|
|
|
|
|
|
def get_values2(self, s):
|
|
|
- a_values = {}
|
|
|
- m_values = {}
|
|
|
- if s['accounts'] and s['values2'] is None:
|
|
|
- a_values = self.account_values.get(s['accounts'][0], dict())
|
|
|
- m_values = self.marketing_values.get(s['accounts'][0], dict())
|
|
|
- p_values = {}
|
|
|
- if self.plan_values is not None:
|
|
|
- p_values = self.plan_values.get(s['id'], dict())
|
|
|
+ if 'values2' not in s or len(s['values2'].keys()) == 0:
|
|
|
+ s['values2'] = dict([(str(d), [0] * 30) for d in self.config['department']])
|
|
|
+ else:
|
|
|
+ for d in s['values2'].keys():
|
|
|
+ if len(s['values2'][d]) < 30:
|
|
|
+ s['values2'][d] = [s['values2'][d][i] if 0 <= i < len(s['values2'][d]) else 0
|
|
|
+ for i in self.config['translation']]
|
|
|
+
|
|
|
+ self.update_account_values(s)
|
|
|
+ self.update_plan_values(s)
|
|
|
+ self.update_marketing_values(s)
|
|
|
+
|
|
|
+ def update_values(self, value_type):
|
|
|
+ v_types = {
|
|
|
+ 'accounts': self.update_account_values,
|
|
|
+ 'plan': self.update_plan_values,
|
|
|
+ 'marketing': self.update_marketing_values
|
|
|
+ }
|
|
|
+
|
|
|
+ parents = []
|
|
|
+ for s in self.structure:
|
|
|
+ if v_types[value_type](s):
|
|
|
+ parents.append(s['parents'][0])
|
|
|
+ if value_type == 'marketing':
|
|
|
+ for p_id in set(parents):
|
|
|
+ parent = self.get_structure_by_id(p_id)
|
|
|
+ parent['form'] = '9'
|
|
|
+ for d in parent['options'].keys():
|
|
|
+ parent['options'][d]['status'] = '0'
|
|
|
+ return self.structure
|
|
|
|
|
|
- values = dict([(str(d), [0] * 30) for d in self.config['department']])
|
|
|
- for d in values.keys():
|
|
|
- if s['values2'] is not None and d in s['values2']:
|
|
|
- if len(s['values2'][d]) == 30:
|
|
|
- values[d] = s['values2'][d]
|
|
|
- else:
|
|
|
- values[d] = [s['values2'][d][i] if 0 <= i < len(s['values2'][d]) else 0
|
|
|
- for i in self.config['translation']]
|
|
|
- if d in p_values:
|
|
|
- for i, v in enumerate(p_values[d], 28):
|
|
|
- values[d][i] = v
|
|
|
+ def get_structure_by_id(self, id):
|
|
|
+ for s in self.structure:
|
|
|
+ if s['id'] == id:
|
|
|
+ return s
|
|
|
+ return None
|
|
|
+
|
|
|
+ def update_account_values(self, s):
|
|
|
+ if len(s['accounts']) == 0:
|
|
|
+ return False
|
|
|
+ a_values = self.account_values.get(s['accounts'][0], dict())
|
|
|
+
|
|
|
+ for d in s['values2'].keys():
|
|
|
if d in a_values:
|
|
|
for i, v in enumerate(a_values[d], 20):
|
|
|
- values[d][i] = v
|
|
|
+ s['values2'][d][i] = v
|
|
|
+ return s['values2']
|
|
|
+
|
|
|
+ def update_plan_values(self, s):
|
|
|
+ if self.plan_values is None:
|
|
|
+ return False
|
|
|
+ p_values = self.plan_values.get(s['id'], dict())
|
|
|
+
|
|
|
+ for d in s['values2'].keys():
|
|
|
+ if d in p_values:
|
|
|
+ for i, v in enumerate(p_values[d], 28):
|
|
|
+ s['values2'][d][i] = v
|
|
|
+ return True
|
|
|
+
|
|
|
+ def update_marketing_values(self, s):
|
|
|
+ if len(s['accounts']) == 0:
|
|
|
+ return False
|
|
|
+ m_values = self.marketing_values.get(s['accounts'][0], dict())
|
|
|
+ if not m_values:
|
|
|
+ return False
|
|
|
+
|
|
|
+ for d in s['values2'].keys():
|
|
|
if d in m_values:
|
|
|
for i, v in enumerate(m_values[d], 1):
|
|
|
- values[d][i] = v
|
|
|
- values[d][0] = sum(m_values[d])
|
|
|
- values[d][14] = sum(m_values[d])
|
|
|
- return values
|
|
|
+ s['values2'][d][i] = v
|
|
|
+ s['values2'][d][0] = sum(m_values[d])
|
|
|
+ s['values2'][d][14] = sum(m_values[d])
|
|
|
+ s['options'][d]['seasonal'] = False
|
|
|
+ return True
|
|
|
|
|
|
def convert_values2(self, s):
|
|
|
a_values = {}
|