trytonpsk-syncronize_companies/account.py

119 lines
4.3 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.
import time
from decimal import Decimal
import requests
import simplejson as json
from datetime import datetime, date
from trytond.model import ModelView, fields
from trytond.pool import PoolMeta, Pool
from trytond.transaction import Transaction
from trytond.pyson import Bool, Eval, Or, Not
from trytond.wizard import (
Wizard, StateView, StateAction, StateReport, StateTransition, Button)
from trytond.report import Report
__all__ = [
'PrintBalanceSheetCOLGAAPStart', 'PrintBalanceSheetCOLGAAP',
'BalanceSheetCOLGAAP', 'PrintIncomeStatementCOLGAAPStart',
'PrintIncomeStatementCOLGAAP', 'IncomeStatementCOLGAAP'
]
_ZERO = Decimal('0.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
def get_context(cls, records, data):
report_context = super(IncomeStatementCOLGAAP, cls).get_context(records, data)
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:
api_ = 'http://' + sync.api_connection + '/'+ sync.database
route = api_ + '/' + 'report_context'
data_ = json.dumps({
'database': sync.database,
'report_name': 'account_col.income_statement_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
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
def get_context(cls, records, data):
report_context = super(BalanceSheetCOLGAAP, cls).get_context(records, data)
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:
api_ = 'http://' + sync.api_connection + '/'+ sync.database
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