Fix: UPDATE 6.8

This commit is contained in:
Rodia 2024-07-19 00:36:47 -05:00
parent 3873833fa1
commit 98b357dcf2
7 changed files with 119 additions and 97 deletions

View file

@ -3,18 +3,17 @@ from trytond.pool import Pool
from . import analytic_account_report
from . import income_statement_colgaap_report
def register():
Pool.register(
analytic_account_report.PrintAnalyticAccountStart,
income_statement_colgaap_report.PrintIncomeStatementCOLGAAPStart,
module='analytic_account_co',type_='model')
module='analytic_account_co', type_='model')
Pool.register(
analytic_account_report.PrintAnalyticAccount,
income_statement_colgaap_report.PrintIncomeStatementCOLGAAP,
module='analytic_account_co',type_='wizard')
module='analytic_account_co', type_='wizard')
Pool.register(
analytic_account_report.AnalyticAccount,
income_statement_colgaap_report.IncomeStatementCOLGAAP,
module='analytic_account_co',type_='report')
module='analytic_account_co', type_='report')

View file

@ -6,14 +6,12 @@ from trytond.pyson import Eval
from trytond.transaction import Transaction
from trytond.report import Report
from trytond.pool import Pool
import datetime
def compute_report(data):
pool = Pool()
Analytic_Account = pool.get('analytic_account.account')
Analytic_Account_Line = pool.get('analytic_account.line')
res = {}
ctx = {
'company': data['company']
@ -27,29 +25,31 @@ def compute_report(data):
if child in parent_child.childs:
return True
else:
if is_child(child,parent_child):
if is_child(child, parent_child):
return True
return False
with Transaction().set_context(ctx):
analytic_accounts_filter = Analytic_Account.search([('parent', '!=', None),
('parent.type', '=','root'),
('id', 'in', data['analytic_account']),
], order=[('code', 'ASC')])
analytic_accounts = Analytic_Account.search([],order=[('code', 'ASC')])
with Transaction().set_context(ctx):
analytic_accounts_filter = Analytic_Account.search([
('parent', '!=', None),
('parent.type', '=', 'root'),
('id', 'in', data['analytic_account']),
], order=[('code', 'ASC')])
analytic_accounts = Analytic_Account.search(
[], order=[('code', 'ASC')])
aas = {}
total = 0
for aaf in analytic_accounts_filter:
aas[aaf.code] = {}
aas[aaf.code][aaf.code] = [aaf,0,0,0,False]
aas[aaf.code][aaf.code] = [aaf, 0, 0, 0, False]
for aa in analytic_accounts:
record = []
if is_child(aa, aaf):
record.append(aa)
record = record + [0,0,0]
record = record + [0, 0, 0]
if aa.type == 'normal':
aa_line = Analytic_Account_Line.search([
('account', '=', aa),
@ -57,14 +57,17 @@ def compute_report(data):
('date', '<=', data['end_date']),
], order=[('date', 'ASC')])
lines = {}
for a_l in aa_line:
if a_l.move_line.account.code in lines:
lines[a_l.move_line.account.code][1] += a_l.debit
lines[a_l.move_line.account.code][2] += a_l.credit
lines[a_l.move_line.account.code][3].append(a_l.move_line)
lines[a_l.move_line.account.code][1] += \
a_l.debit
lines[a_l.move_line.account.code][2] += \
a_l.credit
lines[a_l.move_line.account.code][3].append(
a_l.move_line)
else:
move_line = [a_l.move_line]
move_line = [a_l.move_line]
lines[a_l.move_line.account.code] = [
a_l.move_line.account.name,
a_l.debit,
@ -75,21 +78,25 @@ def compute_report(data):
record[2] += a_l.credit * -(1)
record[3] += a_l.debit - a_l.credit
total += a_l.debit - a_l.credit
def is_parent(parent, account, debit, credit):
if parent and account and parent.code in aas[aaf.code]:
aas[aaf.code][parent.code][3] += debit - credit
if parent and account and parent.code in aas[
aaf.code]:
aas[aaf.code][parent.code][3] +=\
debit - credit
if parent.parent and parent.parent.code:
is_parent(parent.parent, account, debit, credit)
is_parent(
parent.parent, account, debit, credit)
is_parent(aa.parent, aa, a_l.debit, a_l.credit)
record.append(lines)
aas[aaf.code][aa.code] = record
res['record'] = aas
res['total'] = -total
res['root'] = Analytic_Account.search([
res['root'] = Analytic_Account.search([
('id', '=', data['analytic_account_root'])
])
])
res['start_date'] = data['start_date']
res['end_date'] = data['end_date']
@ -113,17 +120,19 @@ class PrintAnalyticAccountStart(ModelView):
depends=['detailed'],
help='Show account move detailed')
without_balance = fields.Boolean('Without Balance')
analytic_account_root = fields.Many2One('analytic_account.account',
'Analytic Account Root', required=True,
domain=[('type', '=', 'root')]
)
analytic_account = fields.Many2Many('analytic_account.account',
None, None, 'Analytic Account',
domain=[('parent', '=', Eval('analytic_account_root')),
('type', '!=', 'root')],
depends=['analytic_account_root']
)
analytic_account_root = fields.Many2One(
'analytic_account.account',
'Analytic Account Root', required=True,
domain=[('type', '=', 'root')]
)
analytic_account = fields.Many2Many(
'analytic_account.account',
None, None, 'Analytic Account',
domain=[('parent', '=', Eval('analytic_account_root')),
('type', '!=', 'root')],
depends=['analytic_account_root']
)
@staticmethod
def default_company():
return Transaction().context.get('company')
@ -142,12 +151,13 @@ class PrintAnalyticAccount(Wizard):
def do_print_(self, action):
Analytic_Account = Pool().get('analytic_account.account')
if self.start.analytic_account:
analytic_account_ids = [ac.id for ac in self.start.analytic_account]
analytic_account_ids = [
ac.id for ac in self.start.analytic_account]
else:
analytic_account = Analytic_Account.search([('parent.type', '=', 'root'),
('parent', '=', self.start.analytic_account_root)])
analytic_account = Analytic_Account.search([
('parent.type', '=', 'root'),
('parent', '=', self.start.analytic_account_root)])
analytic_account_ids = [ac.id for ac in analytic_account]
data = {

View file

@ -23,7 +23,6 @@ def compute_report(data, domain, codes):
'posted': data['posted'],
}
def is_child(child, parent):
if child in parent.childs:
return True
@ -32,10 +31,10 @@ def compute_report(data, domain, codes):
if child in parent_child.childs:
return True
else:
if is_child(child,parent_child):
if is_child(child, parent_child):
return True
return False
if data.get('period'):
period = Period(data['period'])
periods = Period.search([
@ -58,17 +57,17 @@ def compute_report(data, domain, codes):
('id', 'in', reduce_ids),
], order=[('code', 'ASC')]
)
if data.get('account_profit'):
account_profit = Account(data['account_profit'])
# account_profit = Account(data['account_profit'])
profit_accounts = Account.search(['OR',
('code', 'in', ['4', '5', '6', '7']),
])
amount_profit = sum([a.balance for a in profit_accounts])
Account_Move_Line = pool.get('account.move.line')
analytics_accounts = []
records = []
# analytics_accounts = []
# records = []
res['records'] = {}
res['records_full'] = {}
res['analytic_balance'] = 0
@ -76,7 +75,7 @@ def compute_report(data, domain, codes):
for analytic_account_id in data['analytic_account']:
analytic_account = Analytic_Account(analytic_account_id)
res['records'][analytic_account.name] = {}
result_parcial = 0
result_parcial = 0
for a in accounts:
record = []
record2 = []
@ -85,7 +84,8 @@ def compute_report(data, domain, codes):
record2.append(a.code)
record2.append(a.name)
record2.append(a.balance)
move_state = ['posted'] if data['posted'] else ['posted', 'draft']
move_state = ['posted'] if data['posted'] else [
'posted', 'draft']
account_move_lines = Account_Move_Line.search([
('account.id', '=', a.id),
('period', 'in', ctx['periods']),
@ -94,13 +94,15 @@ def compute_report(data, domain, codes):
analytic_balance = 0
record.append([])
record2.append([])
if len(account_move_lines) > 0:
for account_move_line in account_move_lines:
for analytic_line in account_move_line.analytic_lines:
if is_child(analytic_line.account, analytic_account):
if is_child(
analytic_line.account, analytic_account):
if analytic_line.debit > 0:
analytic_balance += analytic_line.debit * (-1)
analytic_balance += \
analytic_line.debit * (-1)
analytic_balance += analytic_line.credit
record[1].append(analytic_line)
record2[3].append(analytic_line)
@ -110,18 +112,19 @@ def compute_report(data, domain, codes):
def is_parent(parent, account, debit):
if parent and account:
res['records'][analytic_account.name][parent.code][2] += debit
res['records'][analytic_account.name][
parent.code][2] += debit
res['records_full'][parent.code][4] += debit
if parent.parent and parent.parent.code:
is_parent(parent.parent, account, debit)
is_parent(a.parent, a.code, analytic_balance)
else:
record.append(0)
record2.append(0)
res['records'][analytic_account.name][a.code] = record
if a.code in res['records_full']:
if a.code in res['records_full']:
res['records_full'][a.code][2] += record2[2]
res['records_full'][a.code][4] += record2[4]
else:
@ -130,12 +133,14 @@ def compute_report(data, domain, codes):
if res['analytic_balance'] == 0:
res['records'].pop(analytic_account.name)
else:
res['records'][analytic_account.name]['balance'] = result_parcial
res['records'][analytic_account.name]['code'] = analytic_account.code
res['records'][analytic_account.name]['balance'] = \
result_parcial
res['records'][analytic_account.name]['code'] = \
analytic_account.code
main_accounts = Account.search(['OR',
('code', 'in', codes),
])
res['root'] = Analytic_Account.search([
('id', '=', data['analytic_account_root'])
])
@ -159,7 +164,7 @@ def compute_report(data, domain, codes):
res['analytic_lines'] = data['analytic_lines']
res['detailed'] = data['detailed']
res['without_balance'] = data['without_balance']
return res
@ -187,17 +192,20 @@ class PrintIncomeStatementCOLGAAPStart(ModelView):
depends=['detailed'],
help='Show account move detailed')
without_balance = fields.Boolean('Without Balance')
analytic_account_root = fields.Many2One('analytic_account.account',
'Analytic Account Root', required=True,
domain=[('type', '=', 'root')]
)
analytic_account = fields.Many2Many('analytic_account.account',
None, None, 'Analytic Account',
domain=[('parent', '=', Eval('analytic_account_root')),
('type', '!=', 'root')],
depends=['analytic_account_root']
)
analytic_account_root = fields.Many2One(
'analytic_account.account',
'Analytic Account Root', required=True,
domain=[('type', '=', 'root')]
)
analytic_account = fields.Many2Many(
'analytic_account.account',
None, None, 'Analytic Account',
domain=[
('parent', '=', Eval(
'analytic_account_root')),
('type', '!=', 'root')],
depends=['analytic_account_root']
)
@staticmethod
def default_posted():
@ -221,7 +229,8 @@ class PrintIncomeStatementCOLGAAPStart(ModelView):
class PrintIncomeStatementCOLGAAP(Wizard):
'Print Analytic Income Statement COLGAAP'
__name__ = 'analytic_account_co.print_income_statement_colgaap'
start = StateView('analytic_account_co.print_income_statement_colgaap.start',
start = StateView(
'analytic_account_co.print_income_statement_colgaap.start',
'analytic_account_co.print_income_statement_colgaap_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Print', 'print_', 'tryton-print', default=True),
@ -246,9 +255,11 @@ class PrintIncomeStatementCOLGAAP(Wizard):
periods_ids = [p.id for p in periods]
if self.start.analytic_account:
analytic_account_ids = [ac.id for ac in self.start.analytic_account]
analytic_account_ids = [
ac.id for ac in self.start.analytic_account]
else:
analytic_account = Analytic_Account.search([('parent.type', '=', 'root')])
analytic_account = Analytic_Account.search(
[('parent.type', '=', 'root')])
analytic_account_ids = [ac.id for ac in analytic_account]
ctx['periods'] = periods_ids
@ -278,7 +289,8 @@ class IncomeStatementCOLGAAP(Report):
@classmethod
def get_context(cls, records, data):
report_context = super(IncomeStatementCOLGAAP, cls).get_context(records, data)
report_context = super(IncomeStatementCOLGAAP, cls).get_context(
records, data)
pool = Pool()
Company = pool.get('company.company')
Period = pool.get('account.period')
@ -294,5 +306,5 @@ class IncomeStatementCOLGAAP(Report):
report_context['start_period'] = Period(data['start_period'])
report_context['end_period'] = Period(data['end_period'])
report_context['company'] = company
return report_context

View file

@ -3,7 +3,7 @@ import io
import os
import re
from configparser import ConfigParser
from setuptools import setup, find_packages
from setuptools import setup
MODULE = 'analytic_account_co'
PREFIX = 'etrivial'
@ -66,9 +66,9 @@ setup(name='%s_%s' % (PREFIX, MODULE),
'trytond.modules.%s.tests' % MODULE,
],
package_data={
'trytond.modules.%s' % MODULE : (info.get('xml', [])
'trytond.modules.%s' % MODULE: (info.get('xml', [])
+ ['tryton.cfg', 'view/*.xml', 'locale/*.po', '*.fodt',
'*.fods','icons/*.svg', 'tests/*.rst']),
'*.fods', 'icons/*.svg', 'tests/*.rst']),
},
classifiers=[
'Development Status :: 5 - Production/Stable',
@ -110,13 +110,13 @@ setup(name='%s_%s' % (PREFIX, MODULE),
],
license='GPL-3',
python_requires='>=3.5',
install_requires=requires,
# install_requires=requires,
dependency_links=dependency_links,
zip_safe=False,
entry_points="""
[trytond.modules]
%s = trytond.modules.%s
""" % (MODULE, MODULE),
analytic_account_co = trytond.modules.analytic_account_co
""",
test_suite='tests',
test_loader='trytond.test_loader:Loader',
tests_require=tests_require,

View file

@ -1,8 +1,4 @@
import unittest
from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import suite as test_suite
class AnalyticAccountCoTestCase(ModuleTestCase):
@ -10,8 +6,4 @@ class AnalyticAccountCoTestCase(ModuleTestCase):
module = 'analytic_account_co'
def suite():
suite = test_suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
AnalticAccountCoTestCase))
return suite
del ModuleTestCase

9
tests/test_scenario.py Normal file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env python3
# 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 trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)

View file

@ -1,5 +1,5 @@
[tryton]
version=5.8.0
version=7.0.0
depends=
ir
res
@ -7,4 +7,4 @@ depends=
xml:
analytic_account_report.xml
analytic_account_line.xml
income_statement_colgaap_report.xml
income_statement_colgaap_report.xml