fix add niif in balance detail
This commit is contained in:
parent
5b1105ffab
commit
794fdcd266
14
__init__.py
14
__init__.py
|
@ -27,6 +27,7 @@ def register():
|
|||
account.CashflowTemplate,
|
||||
account.Cashflow,
|
||||
account.Account,
|
||||
account.Type,
|
||||
account.AuxiliaryBookStart,
|
||||
account.PrintTrialBalanceDetailedStart,
|
||||
account.PrintTrialBalanceStart,
|
||||
|
@ -55,9 +56,6 @@ def register():
|
|||
invoice.Invoice,
|
||||
invoice.InvoiceLine,
|
||||
invoice.InvoiceTax,
|
||||
# sale.Sale,
|
||||
# sale.SaleLine,
|
||||
# sale.SaleVoucher,
|
||||
tax.TaxesByInvoiceStart,
|
||||
tax.TaxesPostedStart,
|
||||
move.MoveFixNumberStart,
|
||||
|
@ -73,7 +71,6 @@ def register():
|
|||
invoice.MovesInvoicesStart,
|
||||
invoice.InvoiceUpdateStart,
|
||||
invoice.InvoiceReport,
|
||||
# sale.SaleUpdateStart,
|
||||
payment_term.PaymentTerm,
|
||||
module='account_col', type_='model')
|
||||
Pool.register(
|
||||
|
@ -82,7 +79,6 @@ def register():
|
|||
account.TrialBalanceDetailed,
|
||||
account.TrialBalanceClassic,
|
||||
account.BalanceSheet,
|
||||
# account.BalanceSheetDetail,
|
||||
account.IncomeStatement,
|
||||
invoice.EquivalentInvoice,
|
||||
account.PartyWithholding,
|
||||
|
@ -93,6 +89,7 @@ def register():
|
|||
account.IncomeStatementCOLGAAP,
|
||||
account.CashflowStatement,
|
||||
invoice.MovesInvoicesReport,
|
||||
# account.BalanceSheetDetail,
|
||||
module='account_col', type_='report')
|
||||
Pool.register(
|
||||
move.MoveForceDraft,
|
||||
|
@ -104,8 +101,6 @@ def register():
|
|||
account.PrintTrialBalance,
|
||||
move.MoveFixNumber,
|
||||
account.PrintPartyWithholding,
|
||||
# invoice.InvoiceFixNumber,
|
||||
# invoice.InvoiceFixNumberAlternate,
|
||||
tax.PrintTaxesByInvoice,
|
||||
tax.PrintTaxesPosted,
|
||||
account.PrintAuxiliaryParty,
|
||||
|
@ -116,12 +111,7 @@ def register():
|
|||
move.MoveCloseYear,
|
||||
party.PartyFixCode,
|
||||
invoice.MovesInvoices,
|
||||
# purchase.PurchaseGenerateInvoice,
|
||||
invoice.InvoiceUpdate,
|
||||
# sale.SaleUpdate,
|
||||
# sale.SaleForceDraft,
|
||||
# purchase.PurchaseUpdate,
|
||||
# purchase.PurchaseGenerateShipment,
|
||||
party.PartyFix,
|
||||
user.UserLoginAttempRemove,
|
||||
module='account_col', type_='wizard')
|
||||
|
|
299
account.py
299
account.py
|
@ -1,7 +1,7 @@
|
|||
# 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
|
||||
from datetime import date
|
||||
from datetime import date, timedelta
|
||||
from timeit import default_timer as timer
|
||||
|
||||
import operator
|
||||
|
@ -196,6 +196,99 @@ class Account(ModelSQL, ModelView):
|
|||
account=account.rec_name))
|
||||
|
||||
|
||||
class Type(metaclass=PoolMeta):
|
||||
'Account Type'
|
||||
__name__ = 'account.account.type'
|
||||
|
||||
debit = fields.Function(fields.Numeric('Amount',
|
||||
digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
|
||||
'get_debit_credit', 'search_debit_credit')
|
||||
|
||||
credit = fields.Function(fields.Numeric('Amount',
|
||||
digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
|
||||
'get_debit_credit', 'search_debit_credit')
|
||||
|
||||
@classmethod
|
||||
def get_debit_credit(cls, types, name):
|
||||
pool = Pool()
|
||||
Account = pool.get('account.account')
|
||||
# GeneralLedger = pool.get('account.general_ledger.account')
|
||||
context = Transaction().context
|
||||
|
||||
res = {}
|
||||
for type_ in types:
|
||||
res[type_.id] = Decimal('0.0')
|
||||
|
||||
childs = cls.search([
|
||||
('parent', 'child_of', [t.id for t in types]),
|
||||
])
|
||||
type_sum = {}
|
||||
for type_ in childs:
|
||||
type_sum[type_.id] = Decimal('0.0')
|
||||
|
||||
with Transaction().set_context(context):
|
||||
accounts = Account.search([
|
||||
('type', 'in', [t.id for t in childs]),
|
||||
])
|
||||
if name == 'debit':
|
||||
for account in accounts:
|
||||
balance = account.debit
|
||||
type_sum[account.type.id] += balance
|
||||
else:
|
||||
for account in accounts:
|
||||
balance = account.credit
|
||||
type_sum[account.type.id] += balance
|
||||
|
||||
for type_ in types:
|
||||
childs = cls.search([
|
||||
('parent', 'child_of', [type_.id]),
|
||||
])
|
||||
for child in childs:
|
||||
res[type_.id] += type_sum[child.id]
|
||||
exp = Decimal(str(10.0 ** -type_.currency_digits))
|
||||
res[type_.id] = res[type_.id].quantize(exp)
|
||||
# if type_.statement == 'balance' and type_.assets:
|
||||
# res[type_.id] = - res[type_.id]
|
||||
return res
|
||||
|
||||
@classmethod
|
||||
def search_debit_credit(cls, name, domain):
|
||||
pool = Pool()
|
||||
Account = pool.get('account.account')
|
||||
context = Transaction().context
|
||||
with Transaction().set_context(context):
|
||||
accounts = Account.search([], order=[])
|
||||
|
||||
_, operator_, operand = domain
|
||||
operator_ = {
|
||||
'=': operator.eq,
|
||||
'>=': operator.ge,
|
||||
'>': operator.gt,
|
||||
'<=': operator.le,
|
||||
'<': operator.lt,
|
||||
'!=': operator.ne,
|
||||
'in': lambda v, l: v in l,
|
||||
'not in': lambda v, l: v not in l,
|
||||
}.get(operator_, lambda v, l: False)
|
||||
|
||||
ids = [a.id for a in accounts
|
||||
if operator_(getattr(a, name), operand)]
|
||||
return [('id', 'in', ids)]
|
||||
|
||||
# @classmethod
|
||||
# def get_amount_cmp(cls, types, name):
|
||||
# transaction = Transaction()
|
||||
# current = transaction.context
|
||||
# if not current.get('comparison'):
|
||||
# return dict.fromkeys([t.id for t in types], None)
|
||||
# new = {}
|
||||
# for key, value in current.items():
|
||||
# if key.endswith('_cmp'):
|
||||
# new[key[:-4]] = value
|
||||
# with transaction.set_context(new):
|
||||
# return cls.get_amount(types, name)
|
||||
|
||||
|
||||
class AuxiliaryBookStart(ModelView):
|
||||
'Auxiliary Book Start'
|
||||
__name__ = 'account_col.print_auxiliary_book.start'
|
||||
|
@ -889,6 +982,7 @@ class BalanceSheet(Report):
|
|||
child1.childs[0].childs = account_child_list
|
||||
return report_context
|
||||
|
||||
|
||||
# class BalanceSheetDetail(Report):
|
||||
# 'Balance Sheet Detail Report'
|
||||
# __name__ = 'account.balance_sheet_report'
|
||||
|
@ -897,38 +991,90 @@ class BalanceSheet(Report):
|
|||
# def get_context(cls, records, header, data):
|
||||
# report_context = super().get_context(records, header, data)
|
||||
# context = Transaction().context
|
||||
# Company = Pool().get('company.company')
|
||||
# Account = Pool().get('account.account')
|
||||
# Type = Pool().get('account.account.type')
|
||||
# pool = Pool()
|
||||
# Company = pool.get('company.company')
|
||||
# Account = pool.get('account.account')
|
||||
# Period = pool.get('account.period')
|
||||
# Type = pool.get('account.account.type')
|
||||
# GeneralLedger = pool.get('account.general_ledger.account')
|
||||
# context_model = context.get('context_model')
|
||||
|
||||
# ids = data.get('ids')
|
||||
# # domain_type = [
|
||||
# # ('statement', '=', 'balance'),
|
||||
# # ['OR',
|
||||
# # ('parent', '=', None),
|
||||
# # ('parent.statement', '!=', 'balance'),
|
||||
# # ('parent.statement', '=', None)
|
||||
# # ]
|
||||
# # ]
|
||||
# if context_model == 'account.income_statement.context':
|
||||
# statement = 'income'
|
||||
# else:
|
||||
# statement = 'balance'
|
||||
|
||||
# # for id_ in ids:
|
||||
# # with Transaction().set_context(context):
|
||||
# # types = Type.search(domain_type)
|
||||
# # print(types, 'types++++++++++++++++++++')
|
||||
# for id_ in ids:
|
||||
# domain = [
|
||||
# ['OR',
|
||||
# ('type', 'child_of', id_, 'parent'),
|
||||
# ('debit_type', 'child_of', id_, 'parent')
|
||||
# ],
|
||||
# ('type', '!=', None),
|
||||
# ('closed', '!=', True)
|
||||
# ]
|
||||
# with Transaction().set_context(context):
|
||||
# accounts = Account.search(domain)
|
||||
# from_date = None
|
||||
# to_date = None
|
||||
# period_ids = None
|
||||
# if context.get('start_period') or context.get('end_period'):
|
||||
# start_period_ids = GeneralLedger.get_period_ids('start_%s' % statement)
|
||||
# end_period_ids = GeneralLedger.get_period_ids('end_%s' % statement)
|
||||
# period_ids = list(
|
||||
# set(end_period_ids).difference(set(start_period_ids)))
|
||||
# else:
|
||||
# to_date = date(context.get('date').year - 1, 12, 31)
|
||||
# from_date = to_date
|
||||
|
||||
# context['periods'] = period_ids
|
||||
# context['from_date'] = from_date
|
||||
# context['to_date'] = to_date
|
||||
|
||||
# with Transaction().set_context(context):
|
||||
# types_final = Type.search(
|
||||
# [('statement', '=', statement)],
|
||||
# order=[('sequence', 'ASC')])
|
||||
|
||||
# new_context = {
|
||||
# 'date': to_date,
|
||||
# 'colgaap': context.get('colgaap'),
|
||||
# 'posted': context.get('posted'),
|
||||
# }
|
||||
# with Transaction().set_context(new_context):
|
||||
# types_initial = Type.search(
|
||||
# [('statement', '=', statement)],
|
||||
# order=[('sequence', 'ASC')])
|
||||
|
||||
# types = OrderedDict()
|
||||
# type_ids = []
|
||||
# type_ids_append = type_ids.append
|
||||
# for t1, t2 in izip(types_initial, types_final):
|
||||
# if not t1.childs:
|
||||
# type_ids_append(t1.id)
|
||||
# types[t1] = {
|
||||
# 'name': t1.name,
|
||||
# 'start_balance': t1.amount,
|
||||
# 'end_balance': t2.amount,
|
||||
# 'debit': t2.debit,
|
||||
# 'credit': t2.credit,
|
||||
# 'accounts': []
|
||||
# }
|
||||
|
||||
# domain = [
|
||||
# ('type', 'in', type_ids),
|
||||
# ('closed', '!=', True)
|
||||
# ]
|
||||
# with Transaction().set_context(context):
|
||||
# accounts_initial = Account.search(domain,
|
||||
# order=[('code', 'ASC'), ('name', 'ASC')])
|
||||
|
||||
# with Transaction().set_context(new_context):
|
||||
# accounts_final = Account.search(domain,
|
||||
# order=[('code', 'ASC'), ('name', 'ASC')])
|
||||
|
||||
# for ac_in, ac_fin in izip(accounts_initial, accounts_final):
|
||||
# types[ac_in.type]['accounts'].extend([{
|
||||
# 'code': ac_in.code,
|
||||
# 'name': ac_in.name,
|
||||
# 'start_balance': ac_in.balance,
|
||||
# 'debit': ac_fin.debit,
|
||||
# 'credit': ac_fin.credit,
|
||||
# 'end_balance': ac_fin.balance,
|
||||
# }])
|
||||
|
||||
# report_context['company'] = Company(context.get('company'))
|
||||
# report_context['date'] = context.get('date')
|
||||
# report_context['types'] = types.values()
|
||||
# return report_context
|
||||
|
||||
|
||||
|
@ -948,22 +1094,21 @@ class IncomeStatement(Report):
|
|||
context = Transaction().context
|
||||
|
||||
report_context = super().get_context(records, header, data)
|
||||
|
||||
context_fields = Context.fields_get(['start_period', 'fiscalyear'])
|
||||
types = Type.search([
|
||||
('statement', '=', 'income')
|
||||
])
|
||||
accounts_types = []
|
||||
company_id = Transaction().context.get('company')
|
||||
company_id = context.get('company')
|
||||
records = Type(report_context['data']['id'])
|
||||
fiscalyear_id = Transaction().context.get('fiscalyear')
|
||||
fiscalyear_cmp = Transaction().context.get('fiscalyear_cmp')
|
||||
start_period = Transaction().context.get('start_period')
|
||||
start_period_cmp = Transaction().context.get('start_period_cmp')
|
||||
end_period = Transaction().context.get('end_period')
|
||||
end_period_cmp = Transaction().context.get('end_period_cmp')
|
||||
comparison = Transaction().context.get('comparison')
|
||||
colgaap = Transaction().context.get('colgaap')
|
||||
fiscalyear_id = context.get('fiscalyear')
|
||||
fiscalyear_cmp = context.get('fiscalyear_cmp')
|
||||
start_period = context.get('start_period')
|
||||
start_period_cmp = context.get('start_period_cmp')
|
||||
end_period = context.get('end_period')
|
||||
end_period_cmp = context.get('end_period_cmp')
|
||||
comparison = context.get('comparison')
|
||||
colgaap = context.get('colgaap')
|
||||
if start_period:
|
||||
start_period = Period(start_period)
|
||||
if end_period:
|
||||
|
@ -1009,12 +1154,11 @@ class IncomeStatement(Report):
|
|||
# setattr(v, 'childs', childs)
|
||||
v['childs'] = childs
|
||||
filtered_records.append(v)
|
||||
|
||||
report_context['start_period'] = start_period
|
||||
report_context['start_period_cmp'] = Period(start_period_cmp)
|
||||
report_context['end_period'] = end_period
|
||||
report_context['end_period_cmp'] = Period(end_period_cmp)
|
||||
report_context['fiscalyear'] = Fiscalyear(fiscalyear_id).name
|
||||
report_context['fiscalyear'] = Fiscalyear(fiscalyear_id).name if fiscalyear_id else ''
|
||||
report_context['fiscalyear_cmp'] = Fiscalyear(fiscalyear_cmp).name if fiscalyear_cmp else ''
|
||||
report_context['records'] = filtered_records
|
||||
report_context['comparison'] = comparison
|
||||
|
@ -2097,6 +2241,7 @@ class TrialBalanceClassic(Report):
|
|||
Period = pool.get('account.period')
|
||||
Company = pool.get('company.company')
|
||||
Fiscalyear = pool.get('account.fiscalyear')
|
||||
Type = pool.get('account.account.type')
|
||||
|
||||
company = Company(data['company'])
|
||||
|
||||
|
@ -2105,8 +2250,15 @@ class TrialBalanceClassic(Report):
|
|||
('code', '!=', None),
|
||||
]
|
||||
|
||||
if not data['detailed']:
|
||||
if not data['detailed'] or not data['colgaap']:
|
||||
dom_accounts.append(('type', '!=', None))
|
||||
|
||||
types = None
|
||||
if data['detailed'] and not data['colgaap']:
|
||||
types = Type.search(
|
||||
[('parent', '!=', None)],
|
||||
order=[('sequence', 'ASC')])
|
||||
|
||||
accounts = Account.search(dom_accounts)
|
||||
|
||||
start_periods = []
|
||||
|
@ -2151,12 +2303,19 @@ class TrialBalanceClassic(Report):
|
|||
):
|
||||
start_accounts = Account.browse(accounts)
|
||||
|
||||
if types:
|
||||
to_date = start_period.start_date - timedelta(days=1)
|
||||
with Transaction().set_context(to_date=to_date):
|
||||
start_types = Type.browse(types)
|
||||
|
||||
with Transaction().set_context(
|
||||
fiscalyear=None,
|
||||
periods=end_period_ids,
|
||||
posted=data['posted'],
|
||||
colgaap=data['colgaap']):
|
||||
in_accounts = Account.browse(accounts)
|
||||
if types:
|
||||
in_types = Type.browse(types)
|
||||
|
||||
with Transaction().set_context(
|
||||
fiscalyear=data['fiscalyear'],
|
||||
|
@ -2165,6 +2324,11 @@ class TrialBalanceClassic(Report):
|
|||
colgaap=data['colgaap']):
|
||||
end_accounts = Account.browse(accounts)
|
||||
|
||||
if types:
|
||||
to_date = end_period.end_date
|
||||
with Transaction().set_context(to_date=to_date):
|
||||
end_types = Type.browse(types)
|
||||
|
||||
to_remove = []
|
||||
if not data['empty_account']:
|
||||
for account in in_accounts:
|
||||
|
@ -2176,8 +2340,13 @@ class TrialBalanceClassic(Report):
|
|||
accounts = cls._accounts(data, to_remove,
|
||||
start_accounts, in_accounts, end_accounts)
|
||||
else:
|
||||
accounts = cls._accounts_view(data, to_remove,
|
||||
start_accounts, in_accounts, end_accounts)
|
||||
if data['colgaap']:
|
||||
accounts = cls._accounts_view(data, to_remove,
|
||||
start_accounts, in_accounts, end_accounts)
|
||||
else:
|
||||
accounts = cls._accounts_view_niif(data, to_remove,
|
||||
start_accounts, in_accounts, end_accounts,
|
||||
start_types, in_types, end_types)
|
||||
|
||||
periods = end_periods
|
||||
report_context['accounts'] = accounts
|
||||
|
@ -2243,6 +2412,50 @@ class TrialBalanceClassic(Report):
|
|||
|
||||
return dict_accounts.values()
|
||||
|
||||
@classmethod
|
||||
def _accounts_view_niif(cls, data, to_remove, start_accounts, in_accounts,
|
||||
end_accounts, start_types, in_types, end_types):
|
||||
accounts = []
|
||||
accounts_append = accounts.append
|
||||
types = OrderedDict()
|
||||
for start_type, in_type, end_type in izip(start_types, in_types, end_types):
|
||||
types[start_type] = {
|
||||
'code': '',
|
||||
'name': start_type.name,
|
||||
'start_balance': [start_type.amount * -1],
|
||||
'end_balance': [end_type.amount * -1],
|
||||
'debit': [in_type.debit],
|
||||
'credit': [in_type.credit],
|
||||
'accounts': []
|
||||
}
|
||||
for start_account, in_account, end_account in izip(
|
||||
start_accounts, in_accounts, end_accounts):
|
||||
|
||||
empty_account = all([
|
||||
start_account.balance == 0,
|
||||
in_account.debit == 0,
|
||||
in_account.credit == 0,
|
||||
end_account.balance == 0
|
||||
])
|
||||
if not data['empty_account'] and empty_account:
|
||||
continue
|
||||
types[start_account.type]['accounts'].extend([{
|
||||
'code': start_account.code,
|
||||
'name': start_account.name,
|
||||
'start_balance': [start_account.balance],
|
||||
'debit': [in_account.debit],
|
||||
'credit': [in_account.credit],
|
||||
'end_balance': [end_account.balance],
|
||||
}])
|
||||
|
||||
for type_ in list(types.values()):
|
||||
accounts_ = type_.pop('accounts')
|
||||
accounts_append(type_)
|
||||
for ac in accounts_:
|
||||
accounts_append(ac)
|
||||
|
||||
return accounts
|
||||
|
||||
@classmethod
|
||||
def _accounts(cls, data, to_remove,
|
||||
start_accounts, in_accounts, end_accounts):
|
||||
|
|
|
@ -73,7 +73,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||
</record>
|
||||
|
||||
<!-- <record model="ir.action.report" id="report_balance_sheet_detailed">
|
||||
<field name="name">Balance Sheet detaile</field>
|
||||
<field name="name">Balance Sheet Detail</field>
|
||||
<field name="model">account.account.type</field>
|
||||
<field name="report_name">account.balance_sheet_report</field>
|
||||
<field name="report">account_col/balance_sheet_detailed.fods</field>
|
||||
|
|
Binary file not shown.
2
move.py
2
move.py
|
@ -118,7 +118,6 @@ class Line(ModelSQL, ModelView):
|
|||
fiscalyear = FiscalYear.__table__()
|
||||
context = Transaction().context
|
||||
company = context.get('company')
|
||||
|
||||
fiscalyear_ids = []
|
||||
where = Literal(True)
|
||||
|
||||
|
@ -138,6 +137,7 @@ class Line(ModelSQL, ModelView):
|
|||
fiscalyear_id = context.get('fiscalyear')
|
||||
period_ids = context.get('periods')
|
||||
if date:
|
||||
print('ingresa')
|
||||
fiscalyears = FiscalYear.search([
|
||||
('start_date', '<=', date),
|
||||
('end_date', '>=', date),
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue