Added agents_info supplier_info
This commit is contained in:
61
dbmodels.py
61
dbmodels.py
@ -79,6 +79,7 @@ class FZ54:
|
||||
'providers_to_kvar': ('kod_postav', 'id_provider'),
|
||||
'services': ('id_service', 'all'),
|
||||
'units': ('id_unit', 'sname'),
|
||||
'atol_receipt': ('external_id', 'external_id'),
|
||||
}
|
||||
self.datas = {tablename: DBModel(
|
||||
self.db, tablename).data for tablename in tables.keys()}
|
||||
@ -278,22 +279,34 @@ class SellTable(Base):
|
||||
|
||||
|
||||
class Sell:
|
||||
def __init__(self, FZ54, FZ54Details):
|
||||
self.fz = FZ54
|
||||
self.fzd = FZ54Details
|
||||
def __init__(self, fz: FZ54, details: FZ54Details, sell_date: datetime):
|
||||
self.fz = fz
|
||||
self.fzd = details
|
||||
self.timestamp = sell_date
|
||||
self.Session = sessionmaker(bind=self.fz.db.engine)
|
||||
self.data_details = self.get_grouped_details()
|
||||
|
||||
def get_grouped_details(self):
|
||||
ids = self.fzd.datas['payment_details']
|
||||
cur_month = self.timestamp.month
|
||||
|
||||
added = [id.get('external_id') for id in self.fz.datas['atol_receipt'] if (
|
||||
datetime.datetime.strptime(id['timestamp'], '%d.%m.%Y %H:%M:%S') > datetime.datetime(self.timestamp.year, cur_month, 1, 0, 0))]
|
||||
ids_filtered = [id for id in ids if (
|
||||
id['month'] == (cur_month - 1) and id['year'] == self.timestamp.year and id['external_id'].lower() not in added)]
|
||||
|
||||
dd = self.fzd.get_group(ids_filtered)
|
||||
print(len(dd))
|
||||
return dd
|
||||
|
||||
def make(self):
|
||||
ids = self.fzd.datas['payment_details']
|
||||
ids_filtered = [id for id in ids if id['month'] == 3]
|
||||
dd = self.fzd.get_group(ids_filtered)
|
||||
timestamp = datetime.datetime(2021, 3, 10, 0, 0, 0)
|
||||
res = []
|
||||
for ext_id, value in dd.items():
|
||||
timestamp = self.timestamp
|
||||
for ext_id, value in self.data_details.items():
|
||||
ext_id = ext_id.lower()
|
||||
val = value[0]
|
||||
total = 0.0
|
||||
timestamp = timestamp + datetime.timedelta(seconds=1)
|
||||
timestamp += datetime.timedelta(seconds=1)
|
||||
vats = {}
|
||||
payments = {}
|
||||
val_items = []
|
||||
@ -334,7 +347,7 @@ class Sell:
|
||||
'payment_method': self.fz.dicts['payment_method'].get(method),
|
||||
'payment_object': self.fz.dicts['payment_object'].get(i['payment_object']),
|
||||
'vat': self.fz.dicts['payment_object_vat_type'].get(vat),
|
||||
'agent_info': i['agent_type'],
|
||||
'agent_info': None if i['agent_type'] == None else 1,
|
||||
'supplier_info': None if i['agent_type'] == None else i['supplier_info']
|
||||
|
||||
})
|
||||
@ -359,14 +372,16 @@ class Sell:
|
||||
{
|
||||
'external_id': ext_id,
|
||||
'company': val['id_company'],
|
||||
'agent_info': val['agent_type'],
|
||||
'supplier_info': None if val['agent_type'] == None else val['supplier_info'],
|
||||
# if val['agent_type'] == None else 1,
|
||||
'agent_info': None,
|
||||
# if val['agent_type'] == None else val['supplier_info'],
|
||||
'supplier_info': None,
|
||||
'items': ext_id,
|
||||
'payments': ext_id,
|
||||
'vats': ext_id,
|
||||
'total': round(total, 2)
|
||||
})
|
||||
"""
|
||||
|
||||
session = self.Session()
|
||||
for vt in vts:
|
||||
session.add(vt)
|
||||
@ -377,16 +392,30 @@ class Sell:
|
||||
session.add(sell)
|
||||
session.add(reciept)
|
||||
session.commit()
|
||||
"""
|
||||
|
||||
mod_val_item = []
|
||||
for val_item in val_items:
|
||||
dict_val = val_item.__dict__
|
||||
dict_val['vat'] = {'type': dict_val.get('vat')}
|
||||
if dict_val.get('agent_info'):
|
||||
dict_val['agent_info'] = {
|
||||
'type': 'another' if dict_val.get('agent_info') == 1 else dict_val.get('agent_info')}
|
||||
supp = dict_val.get('supplier_info')
|
||||
agent = self.fz.dicts['agents'].get(supp)
|
||||
dict_val['supplier_info'] = {
|
||||
|
||||
'name': agent.get('name'),
|
||||
'inn': agent.get('inn')
|
||||
}
|
||||
if dict_val.get('vat'):
|
||||
dict_val['vat'] = {'type': dict_val.get('vat')}
|
||||
else:
|
||||
dict_val['vat'] = None
|
||||
|
||||
mod_val_item.append(dict_val)
|
||||
row_dict = {
|
||||
'reciept': reciept.__dict__,
|
||||
'sell': sell.__dict__,
|
||||
'vats': [vt.__dict__ for vt in vts],
|
||||
# 'vats': [vt.__dict__ for vt in vts],
|
||||
'payments': [pmnt.__dict__ for pmnt in pmnts],
|
||||
'items': mod_val_item,
|
||||
'company': company,
|
||||
|
Reference in New Issue
Block a user