Browse Source

[IMP] account_financial_report:

* remove natsort and pandas dependencies
* some fixes in Open Items and Journal Ledger Reports
* Setting "posted entries" by default instead of "all entries"
* ordering General Ledger move_lines by date
* fixing Trial Balance xlsx
pull/660/head
Joan Sisquella 5 years ago
parent
commit
37fd6ab8f8
  1. 5
      account_financial_report/__manifest__.py
  2. 11
      account_financial_report/report/aged_partner_balance.py
  3. 7
      account_financial_report/report/general_ledger.py
  4. 3
      account_financial_report/report/journal_ledger.py
  5. 22
      account_financial_report/report/open_items.py
  6. 13
      account_financial_report/report/trial_balance.py
  7. 4
      account_financial_report/report/trial_balance_xlsx.py
  8. 3
      account_financial_report/tests/test_journal_ledger.py
  9. 9
      account_financial_report/tests/test_vat_report.py
  10. 2
      account_financial_report/wizard/aged_partner_balance_wizard.py
  11. 2
      account_financial_report/wizard/general_ledger_wizard.py
  12. 2
      account_financial_report/wizard/journal_ledger_wizard.py
  13. 2
      account_financial_report/wizard/open_items_wizard.py
  14. 2
      account_financial_report/wizard/trial_balance_wizard.py
  15. 2
      requirements.txt

5
account_financial_report/__manifest__.py

@ -44,11 +44,6 @@
'view/report_aged_partner_balance.xml', 'view/report_aged_partner_balance.xml',
'view/report_vat_report.xml', 'view/report_vat_report.xml',
], ],
"external_dependencies": {
"python": ['natsort',
'pandas',
],
},
'installable': True, 'installable': True,
'application': True, 'application': True,
'auto_install': False, 'auto_install': False,

11
account_financial_report/report/aged_partner_balance.py

@ -5,7 +5,7 @@
from odoo import models, api from odoo import models, api
from odoo.tools import float_is_zero from odoo.tools import float_is_zero
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
import pandas as pd
import operator
class AgedPartnerBalanceReport(models.AbstractModel): class AgedPartnerBalanceReport(models.AbstractModel):
@ -174,7 +174,6 @@ class AgedPartnerBalanceReport(models.AbstractModel):
move_lines = self.env['account.move.line'].search_read( move_lines = self.env['account.move.line'].search_read(
domain=domain, fields=ml_fields domain=domain, fields=ml_fields
) )
ml_ids = set(pd.DataFrame(move_lines).id.to_list())
journals_ids = set() journals_ids = set()
partners_ids = set() partners_ids = set()
partners_data = {} partners_data = {}
@ -183,9 +182,11 @@ class AgedPartnerBalanceReport(models.AbstractModel):
acc_partial_rec, debit_amount, credit_amount = \ acc_partial_rec, debit_amount, credit_amount = \
self._get_account_partial_reconciled(company_id, date_at_object) self._get_account_partial_reconciled(company_id, date_at_object)
if acc_partial_rec: if acc_partial_rec:
acc_partial_rec_data = pd.DataFrame(acc_partial_rec)
debit_ids = set(acc_partial_rec_data.debit_move_id.to_list())
credit_ids = set(acc_partial_rec_data.credit_move_id.to_list())
ml_ids = map(operator.itemgetter('id'), move_lines)
debit_ids = map(operator.itemgetter('debit_move_id'),
acc_partial_rec)
credit_ids = map(operator.itemgetter('credit_move_id'),
acc_partial_rec)
move_lines = self._recalculate_move_lines( move_lines = self._recalculate_move_lines(
move_lines, debit_ids, credit_ids, move_lines, debit_ids, credit_ids,
debit_amount, credit_amount, ml_ids, account_ids, debit_amount, credit_amount, ml_ids, account_ids,

7
account_financial_report/report/general_ledger.py

@ -3,8 +3,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, api from odoo import models, api
from operator import itemgetter
from natsort import natsorted
import calendar import calendar
import datetime import datetime
@ -472,6 +470,7 @@ class GeneralLedgerReport(models.AbstractModel):
account.update({ml_id: gen_led_data[acc_id][ml_id]}) account.update({ml_id: gen_led_data[acc_id][ml_id]})
else: else:
move_lines += [gen_led_data[acc_id][ml_id]] move_lines += [gen_led_data[acc_id][ml_id]]
move_lines = sorted(move_lines, key=lambda k: (k['date']))
account.update({'move_lines': move_lines}) account.update({'move_lines': move_lines})
else: else:
list_partner = [] list_partner = []
@ -488,6 +487,8 @@ class GeneralLedgerReport(models.AbstractModel):
else: else:
move_lines += [ move_lines += [
gen_led_data[acc_id][prt_id][ml_id]] gen_led_data[acc_id][prt_id][ml_id]]
move_lines = sorted(move_lines,
key=lambda k: (k['date']))
partner.update({'move_lines': move_lines}) partner.update({'move_lines': move_lines})
list_partner += [partner] list_partner += [partner]
account.update({'list_partner': list_partner}) account.update({'list_partner': list_partner})
@ -584,7 +585,7 @@ class GeneralLedgerReport(models.AbstractModel):
account['move_lines'] = centralized_ml account['move_lines'] = centralized_ml
account['partners'] = False account['partners'] = False
del account['list_partner'] del account['list_partner']
general_ledger = natsorted(general_ledger, key=itemgetter('code'))
general_ledger = sorted(general_ledger, key=lambda k: k['code'])
return { return {
'doc_ids': [wizard_id], 'doc_ids': [wizard_id],
'doc_model': 'general.ledger.report.wizard', 'doc_model': 'general.ledger.report.wizard',

3
account_financial_report/report/journal_ledger.py

@ -184,10 +184,11 @@ class JournalLedgerReport(models.AbstractModel):
move_lines = self.env['account.move.line'].search( move_lines = self.env['account.move.line'].search(
self._get_move_lines_domain(move_ids, wizard, journal_ids), self._get_move_lines_domain(move_ids, wizard, journal_ids),
order=self._get_move_lines_order(move_ids, wizard, journal_ids)) order=self._get_move_lines_order(move_ids, wizard, journal_ids))
move_line_ids_taxes_data = {}
if move_lines:
# Get the taxes ids for the move lines # Get the taxes ids for the move lines
query_taxes_params = self._get_query_taxes_params(move_lines) query_taxes_params = self._get_query_taxes_params(move_lines)
query_taxes = self._get_query_taxes() query_taxes = self._get_query_taxes()
move_line_ids_taxes_data = {}
self.env.cr.execute(query_taxes, self.env.cr.execute(query_taxes,
query_taxes_params) query_taxes_params)
# Fetch the taxes associated to the move line # Fetch the taxes associated to the move line

22
account_financial_report/report/open_items.py

@ -6,7 +6,7 @@ from odoo import models, api
from odoo.tools import float_is_zero from odoo.tools import float_is_zero
from odoo.osv import expression from odoo.osv import expression
from datetime import date, datetime from datetime import date, datetime
import pandas as pd
import operator
class OpenItemsReport(models.AbstractModel): class OpenItemsReport(models.AbstractModel):
@ -151,12 +151,11 @@ class OpenItemsReport(models.AbstractModel):
query = self._get_query(account_ids, partner_ids, date_at_object, query = self._get_query(account_ids, partner_ids, date_at_object,
target_move, company_id, date_from) target_move, company_id, date_from)
self._cr.execute(query) self._cr.execute(query)
move_lines_data = pd.DataFrame(self._cr.dictfetchall())
account_ids = set(move_lines_data.account_id.to_list())
move_lines_data = self._cr.dictfetchall()
account_ids = map(operator.itemgetter('account_id'), move_lines_data)
accounts_data = self._get_accounts_data(list(account_ids)) accounts_data = self._get_accounts_data(list(account_ids))
journal_ids = set(move_lines_data.journal_id.to_list())
journal_ids = map(operator.itemgetter('journal_id'), move_lines_data)
journals_data = self._get_journals_data(list(journal_ids)) journals_data = self._get_journals_data(list(journal_ids))
move_lines_data = move_lines_data.fillna(0).to_dict(orient='records')
if date_at_object < date.today(): if date_at_object < date.today():
accounts_partial_reconcile, debit_accounts_partial_amount, \ accounts_partial_reconcile, debit_accounts_partial_amount, \
@ -164,12 +163,10 @@ class OpenItemsReport(models.AbstractModel):
self._get_account_partial_reconciled(move_lines_data, self._get_account_partial_reconciled(move_lines_data,
date_at_object) date_at_object)
if accounts_partial_reconcile: if accounts_partial_reconcile:
accounts_partial_reconcile_data = pd.DataFrame(
debit_ids = map(operator.itemgetter('debit_move_id'),
accounts_partial_reconcile)
credit_ids = map(operator.itemgetter('credit_move_id'),
accounts_partial_reconcile) accounts_partial_reconcile)
debit_ids = set(accounts_partial_reconcile_data.debit_move_id
.to_list())
credit_ids = set(
accounts_partial_reconcile_data.credit_move_id.to_list())
for move_line in move_lines_data: for move_line in move_lines_data:
if move_line['id'] in debit_ids: if move_line['id'] in debit_ids:
move_line['amount_residual'] += \ move_line['amount_residual'] += \
@ -195,7 +192,7 @@ class OpenItemsReport(models.AbstractModel):
for move_line in move_lines_data: for move_line in move_lines_data:
no_partner = True no_partner = True
# Partners data # Partners data
if move_line['partner_id'] and not pd.isna(move_line['partner_id']):
if move_line['partner_id']:
no_partner = False no_partner = False
partners_data.update({ partners_data.update({
move_line['partner_id']: { move_line['partner_id']: {
@ -219,7 +216,8 @@ class OpenItemsReport(models.AbstractModel):
move_line.update({ move_line.update({
'date': move_line['date'].strftime("%d/%m/%Y"), 'date': move_line['date'].strftime("%d/%m/%Y"),
'date_maturity': move_line['date_maturity'].strftime("%d/%m/%Y"),
'date_maturity': move_line["date_maturity"]
and move_line["date_maturity"].strftime("%d/%m/%Y"),
'original': original, 'original': original,
'partner_id': 0 if no_partner else move_line['partner_id'], 'partner_id': 0 if no_partner else move_line['partner_id'],
'partner_name': '' if no_partner else move_line['partner_name'], 'partner_name': '' if no_partner else move_line['partner_name'],

13
account_financial_report/report/trial_balance.py

@ -4,8 +4,6 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models, api from odoo import models, api
from operator import itemgetter
from natsort import natsorted
class TrialBalanceReport(models.AbstractModel): class TrialBalanceReport(models.AbstractModel):
@ -595,9 +593,8 @@ class TrialBalanceReport(models.AbstractModel):
accounts_data, total_amount, foreign_currency) accounts_data, total_amount, foreign_currency)
trial_balance = list(groups_data.values()) trial_balance = list(groups_data.values())
trial_balance += list(accounts_data.values()) trial_balance += list(accounts_data.values())
trial_balance = natsorted(trial_balance,
key=itemgetter('complete_code',
'code'))
trial_balance = sorted(trial_balance, key=lambda k: k[
'complete_code'])
for trial in trial_balance: for trial in trial_balance:
counter = trial['complete_code'].count('/') counter = trial['complete_code'].count('/')
trial['level'] = counter trial['level'] = counter
@ -606,12 +603,10 @@ class TrialBalanceReport(models.AbstractModel):
accounts_data, total_amount, foreign_currency) accounts_data, total_amount, foreign_currency)
trial_balance = list(groups_data.values()) trial_balance = list(groups_data.values())
trial_balance += list(accounts_data.values()) trial_balance += list(accounts_data.values())
trial_balance = natsorted(trial_balance,
key=itemgetter('code'))
trial_balance = sorted(trial_balance, key=lambda k: k['code'])
if hierarchy_on == 'none': if hierarchy_on == 'none':
trial_balance = list(accounts_data.values()) trial_balance = list(accounts_data.values())
trial_balance = natsorted(trial_balance,
key=itemgetter('code'))
trial_balance = sorted(trial_balance, key=lambda k: k['code'])
else: else:
if foreign_currency: if foreign_currency:
for account_id in accounts_data.keys(): for account_id in accounts_data.keys():

4
account_financial_report/report/trial_balance_xlsx.py

@ -38,11 +38,11 @@ class TrialBalanceXslx(models.AbstractModel):
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
5: {'header': _('Period balance'), 5: {'header': _('Period balance'),
'field': 'period_balance',
'field': 'balance',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
6: {'header': _('Ending balance'), 6: {'header': _('Ending balance'),
'field': 'final_balance',
'field': 'ending_balance',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
} }

3
account_financial_report/tests/test_journal_ledger.py

@ -184,7 +184,8 @@ class TestJournalReport(TransactionCase):
'date_from': self.fy_date_start, 'date_from': self.fy_date_start,
'date_to': self.fy_date_end, 'date_to': self.fy_date_end,
'company_id': self.company.id, 'company_id': self.company.id,
'journal_ids': [(6, 0, self.journal_sale.ids)]
'journal_ids': [(6, 0, self.journal_sale.ids)],
'move_target': "all",
}) })
data = wiz._prepare_report_journal_ledger() data = wiz._prepare_report_journal_ledger()
res_data = self.JournalLedgerReport._get_report_values(wiz, data) res_data = self.JournalLedgerReport._get_report_values(wiz, data)

9
account_financial_report/tests/test_vat_report.py

@ -34,15 +34,18 @@ class TestVATReport(common.TransactionCase):
], limit=1) ], limit=1)
self.tax_tag_01 = self.env['account.account.tag'].create({ self.tax_tag_01 = self.env['account.account.tag'].create({
'name': 'Tag 01', 'name': 'Tag 01',
'applicability': 'taxes'
'applicability': 'taxes',
'country_id': self.company.country_id.id,
}) })
self.tax_tag_02 = self.env['account.account.tag'].create({ self.tax_tag_02 = self.env['account.account.tag'].create({
'name': 'Tag 02', 'name': 'Tag 02',
'applicability': 'taxes'
'applicability': 'taxes',
'country_id': self.company.country_id.id,
}) })
self.tax_tag_03 = self.env['account.account.tag'].create({ self.tax_tag_03 = self.env['account.account.tag'].create({
'name': 'Tag 03', 'name': 'Tag 03',
'applicability': 'taxes'
'applicability': 'taxes',
'country_id': self.company.country_id.id,
}) })
self.tax_group_10 = self.env['account.tax.group'].create({ self.tax_group_10 = self.env['account.tax.group'].create({
'name': 'Tax 10%', 'name': 'Tax 10%',

2
account_financial_report/wizard/aged_partner_balance_wizard.py

@ -25,7 +25,7 @@ class AgedPartnerBalanceWizard(models.TransientModel):
('all', 'All Entries')], ('all', 'All Entries')],
string='Target Moves', string='Target Moves',
required=True, required=True,
default='all')
default='posted')
account_ids = fields.Many2many( account_ids = fields.Many2many(
comodel_name='account.account', comodel_name='account.account',
string='Filter accounts', string='Filter accounts',

2
account_financial_report/wizard/general_ledger_wizard.py

@ -39,7 +39,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
('all', 'All Entries')], ('all', 'All Entries')],
string='Target Moves', string='Target Moves',
required=True, required=True,
default='all')
default='posted')
account_ids = fields.Many2many( account_ids = fields.Many2many(
comodel_name='account.account', comodel_name='account.account',
string='Filter accounts', string='Filter accounts',

2
account_financial_report/wizard/journal_ledger_wizard.py

@ -36,7 +36,7 @@ class JournalLedgerReportWizard(models.TransientModel):
) )
move_target = fields.Selection( move_target = fields.Selection(
selection='_get_move_targets', selection='_get_move_targets',
default='all',
default='posted',
required=True, required=True,
) )
foreign_currency = fields.Boolean() foreign_currency = fields.Boolean()

2
account_financial_report/wizard/open_items_wizard.py

@ -26,7 +26,7 @@ class OpenItemsReportWizard(models.TransientModel):
('all', 'All Entries')], ('all', 'All Entries')],
string='Target Moves', string='Target Moves',
required=True, required=True,
default='all')
default='posted')
account_ids = fields.Many2many( account_ids = fields.Many2many(
comodel_name='account.account', comodel_name='account.account',
string='Filter accounts', string='Filter accounts',

2
account_financial_report/wizard/trial_balance_wizard.py

@ -32,7 +32,7 @@ class TrialBalanceReportWizard(models.TransientModel):
('all', 'All Entries')], ('all', 'All Entries')],
string='Target Moves', string='Target Moves',
required=True, required=True,
default='all')
default='posted')
hierarchy_on = fields.Selection( hierarchy_on = fields.Selection(
[('computed', 'Computed Accounts'), [('computed', 'Computed Accounts'),
('relation', 'Child Accounts'), ('relation', 'Child Accounts'),

2
requirements.txt

@ -1,2 +0,0 @@
natsort
pandas
Loading…
Cancel
Save