Обновить dags/split_subkonto2.py
This commit is contained in:
parent
0a8def696b
commit
fde14fb157
|
|
@ -244,9 +244,11 @@ def parse_contract_cell(cell_text):
|
|||
|
||||
def read_dict_subkonto2_db(**kwargs):
|
||||
engine = get_db_engine()
|
||||
df = pd.read_sql("""
|
||||
select
|
||||
osv.subkonto2 as subkonto2
|
||||
df = pd.read_sql(
|
||||
"""
|
||||
select distinct
|
||||
osv.schet as schet
|
||||
, osv.subkonto2 as subkonto2
|
||||
, osv.nomer as nomer
|
||||
, osv.date_begin as date_begin
|
||||
, osv.date_end as date_end
|
||||
|
|
@ -255,6 +257,7 @@ def read_dict_subkonto2_db(**kwargs):
|
|||
on dst.subkonto2 = osv.subkonto2
|
||||
where osv.subkonto2 not in (select dst2.subkonto2 from public.dict_subkonto_two dst2)
|
||||
and (osv.nomer is null or osv.date_begin is null or osv.date_end is null)
|
||||
and (osv.schet like '%01%' or osv.schet like '%03%')
|
||||
""", engine)
|
||||
return df.to_dict(orient='records')
|
||||
|
||||
|
|
@ -262,9 +265,11 @@ def split_subkonto_from_1C(**kwargs):
|
|||
engine = get_db_engine()
|
||||
df = pd.read_sql("""
|
||||
select distinct
|
||||
osv.subkonto2 as subkonto2
|
||||
osv.schet as schet
|
||||
, osv.subkonto2 as subkonto2
|
||||
from public.oborotno_salbdovaya_vedomostb osv
|
||||
where osv.subkonto2 not in (select dst2.subkonto2 from public.dict_subkonto_two dst2)
|
||||
and (osv.schet like '%01%' or osv.schet like '%03%')
|
||||
""", engine)
|
||||
if df.empty:
|
||||
return pd.DataFrame(columns=['subkonto2', 'naimenovanie', 'nomer', 'date_begin', 'date_end']).to_dict(orient='records')
|
||||
|
|
@ -284,6 +289,7 @@ def merge_dict_and_split_1C(**kwargs):
|
|||
df_split_subkonto = pd.DataFrame.from_records(split_subkonto) if split_subkonto else pd.DataFrame()
|
||||
|
||||
result_df = df_split_subkonto.merge(df_dict_subkonto, how='left', on='subkonto2', suffixes=('_split', '_dict'))
|
||||
result_df['schet'] = result_df['schet_dict']
|
||||
result_df['naimenovanie'] = None
|
||||
|
||||
result_df['nomer'] = np.where(
|
||||
|
|
@ -300,17 +306,18 @@ def merge_dict_and_split_1C(**kwargs):
|
|||
|
||||
result_df['date_end'] = result_df['date_end_dict']
|
||||
|
||||
result_df = result_df[['subkonto2', 'nomer', 'date_begin', 'date_end']]
|
||||
result_df = result_df[['schet', 'subkonto2', 'nomer', 'date_begin', 'date_end']]
|
||||
|
||||
engine = get_db_engine()
|
||||
with engine.begin() as conn:
|
||||
conn.execute('CREATE TEMP TABLE temp_dict_subkonto_two (subkonto2 text null, nomer text null, date_begin text null, date_end text null)')
|
||||
conn.execute('CREATE TEMP TABLE temp_dict_subkonto_two (schet text null, subkonto2 text null, nomer text null, date_begin text null, date_end text null)')
|
||||
result_df.to_sql('temp_dict_subkonto_two', con=conn, if_exists='append', index=False, method='multi')
|
||||
conn.execute(
|
||||
'''
|
||||
INSERT INTO public.dict_subkonto_two (subkonto2, nomer, date_begin, date_end)
|
||||
INSERT INTO public.dict_subkonto_two (schet, subkonto2, nomer, date_begin, date_end)
|
||||
SELECT
|
||||
subkonto2
|
||||
schet
|
||||
, subkonto2
|
||||
, nomer
|
||||
, date_begin
|
||||
, date_end
|
||||
|
|
|
|||
Loading…
Reference in New Issue