trytonpsk-syncronize_companies/account.py

160 lines
5.8 KiB
Python
Raw Normal View History

2020-09-21 23:54:01 +02:00
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from decimal import Decimal
import requests
import simplejson as json
2020-12-02 20:45:18 +01:00
from trytond.model import fields
2020-09-21 23:54:01 +02:00
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
_ZERO = Decimal('0.00')
2021-02-19 03:57:26 +01:00
class PrintTrialBalanceStart(metaclass=PoolMeta):
__name__ = 'account.print_trial_balance.start'
sincronize = fields.Boolean('Syncronize')
class PrintTrialBalance(metaclass=PoolMeta):
__name__ = 'account.print_trial_balance'
def do_print_(self, action):
action, data = super(PrintTrialBalance, self).do_print_(action)
data['sincronize'] = self.start.sincronize
return action, data
class TrialBalanceClassic(metaclass=PoolMeta):
2021-02-19 04:40:10 +01:00
__name__ = 'account_col.trial_balance_classic'
2021-02-19 03:57:26 +01:00
@classmethod
2021-07-22 16:42:51 +02:00
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
2021-02-19 03:57:26 +01:00
Company = Pool().get('company.company')
company = Company(Transaction().context.get('company'))
result = {}
sync = data['sincronize']
2021-02-19 04:35:00 +01:00
print('yyyyyyyyyyy', sync)
2021-02-19 03:57:26 +01:00
if sync:
2021-02-19 05:40:45 +01:00
data['sincronize'] = False
2021-02-19 03:57:26 +01:00
args = {
'records': [],
'data': data,
}
for sync in company.connection_companies:
api_ = 'http://' + sync.api_connection + '/' + sync.database
route = api_ + '/' + 'report_context'
data_ = json.dumps({
'database': sync.database,
'report_name': 'account_col.trial_balance_classic',
'args': args,
})
res = requests.get(route, data=data_)
result = res.json()
# obj_ = dict(sorted(result['records'].items()))
print('-' * 190)
2021-02-19 04:42:32 +01:00
print(result)
print('-' * 190)
2021-02-19 05:40:45 +01:00
report_context['accounts'].extend(result)
2021-02-19 03:57:26 +01:00
# report_context['records'].extend(obj_.values())
# report_context['global_result'] += Decimal(result['global_result'])
return report_context
2020-09-21 23:54:01 +02:00
class PrintIncomeStatementCOLGAAPStart(metaclass=PoolMeta):
__name__ = 'account_col.print_income_statement_colgaap.start'
sincronize = fields.Boolean('Syncronize')
class PrintIncomeStatementCOLGAAP(metaclass=PoolMeta):
__name__ = 'account_col.print_income_statement_colgaap'
def do_print_(self, action):
action, data = super(PrintIncomeStatementCOLGAAP, self).do_print_(action)
data['sincronize'] = self.start.sincronize
return action, data
class IncomeStatementCOLGAAP(metaclass=PoolMeta):
__name__ = 'account_col.income_statement_colgaap'
@classmethod
2022-01-20 14:50:42 +01:00
def get_context(cls, records, header, data):
report_context = super().get_context(records, header, data)
2020-09-21 23:54:01 +02:00
Company = Pool().get('company.company')
company = Company(Transaction().context.get('company'))
result = {}
sync = data['sincronize']
if sync:
data['sincronize'] = [False]
args = {
2021-02-19 02:40:49 +01:00
'records': [],
2020-09-21 23:54:01 +02:00
'data': data,
}
for sync in company.connection_companies:
2021-02-19 02:40:49 +01:00
api_ = 'http://' + sync.api_connection + '/' + sync.database
2020-09-21 23:54:01 +02:00
route = api_ + '/' + 'report_context'
data_ = json.dumps({
2021-02-19 03:02:34 +01:00
'database': sync.database,
'report_name': 'account_col.income_statement_colgaap',
'args': args,
})
2020-09-21 23:54:01 +02:00
res = requests.get(route, data=data_)
result = res.json()
obj_ = dict(sorted(result['records'].items()))
2021-02-19 03:02:34 +01:00
print(report_context['records'])
print('-'*190)
print(obj_.values())
2020-09-21 23:54:01 +02:00
report_context['records'].extend(obj_.values())
report_context['global_result'] += Decimal(result['global_result'])
return report_context
class PrintBalanceSheetCOLGAAPStart(metaclass=PoolMeta):
__name__ = 'account_col.print_balance_sheet_colgaap.start'
sincronize = fields.Boolean('Syncronize')
class PrintBalanceSheetCOLGAAP(metaclass=PoolMeta):
__name__ = 'account_col.print_balance_sheet_colgaap'
def do_print_(self, action):
action, data = super(PrintBalanceSheetCOLGAAP, self).do_print_(action)
data['sincronize'] = self.start.sincronize
return action, data
class BalanceSheetCOLGAAP(metaclass=PoolMeta):
__name__ = 'account_col.balance_sheet_colgaap'
@classmethod
2021-07-22 16:42:51 +02:00
def get_context(cls, records, header, data):
2022-01-20 14:50:42 +01:00
report_context = super().get_context(records, header, data)
2020-09-21 23:54:01 +02:00
Company = Pool().get('company.company')
company = Company(Transaction().context.get('company'))
result = {}
sync = data['sincronize']
if sync:
data['sincronize'] = [False]
args = {
'records': records,
'data': data,
}
for sync in company.connection_companies:
2021-02-19 02:40:49 +01:00
api_ = 'http://' + sync.api_connection + '/' + sync.database
2020-09-21 23:54:01 +02:00
route = api_ + '/' + 'report_context'
data_ = json.dumps({
'database': sync.database,
'report_name': 'account_col.balance_sheet_colgaap',
'args': args,
})
res = requests.get(route, data=data_)
result = res.json()
obj_ = dict(sorted(result['records'].items()))
report_context['records'].extend(obj_.values())
report_context['global_result'] += Decimal(result['global_result'])
return report_context