Browse Source

[IMP] account_financial_report: multiple fixes and improvements

pull/660/head
Jordi Ballester Alomar 5 years ago
committed by Joan Sisquella
parent
commit
8687ce3e13
  1. 1544
      account_financial_report/i18n/es.po
  2. 21
      account_financial_report/report/abstract_report_xlsx.py
  3. 64
      account_financial_report/report/aged_partner_balance.py
  4. 2
      account_financial_report/report/aged_partner_balance_xlsx.py
  5. 85
      account_financial_report/report/general_ledger.py
  6. 30
      account_financial_report/report/general_ledger_xlsx.py
  7. 306
      account_financial_report/report/open_items.py
  8. 22
      account_financial_report/report/open_items_xlsx.py
  9. 2
      account_financial_report/report/templates/aged_partner_balance.xml
  10. 18
      account_financial_report/report/templates/general_ledger.xml
  11. 8
      account_financial_report/report/templates/open_items.xml
  12. 71
      account_financial_report/report/trial_balance.py
  13. 16
      account_financial_report/report/vat_report.py
  14. 2
      account_financial_report/wizard/aged_partner_balance_wizard.py
  15. 1
      account_financial_report/wizard/aged_partner_balance_wizard_view.xml
  16. 5
      account_financial_report/wizard/general_ledger_wizard.py
  17. 30
      account_financial_report/wizard/general_ledger_wizard_view.xml

1544
account_financial_report/i18n/es.po
File diff suppressed because it is too large
View File

21
account_financial_report/report/abstract_report_xlsx.py

@ -426,27 +426,33 @@ class AbstractReportXslx(models.AbstractModel):
value or '', value or '',
self.format_header_right self.format_header_right
) )
elif cell_type == 'currency_name':
self.sheet.write_string(self.row_pos, col_pos,
value or '',
self.format_header_right)
self.row_pos += 1 self.row_pos += 1
def _get_currency_amt_format(self, line_object): def _get_currency_amt_format(self, line_object):
""" Return amount format specific for each currency. """ """ Return amount format specific for each currency. """
if hasattr(line_object, 'account_group_id') and \
line_object.account_group_id:
if 'account_group_id' in line_object and \
line_object['account_group_id']:
format_amt = getattr(self, 'format_amount_bold') format_amt = getattr(self, 'format_amount_bold')
field_prefix = 'format_amount_bold' field_prefix = 'format_amount_bold'
else: else:
format_amt = getattr(self, 'format_amount') format_amt = getattr(self, 'format_amount')
field_prefix = 'format_amount' field_prefix = 'format_amount'
if line_object.currency_id:
if 'currency_id' in line_object and \
line_object.get('currency_id', False):
field_name = \ field_name = \
'%s_%s' % (field_prefix, line_object.currency_id.name)
'%s_%s' % (field_prefix, line_object['currency_id'].name)
if hasattr(self, field_name): if hasattr(self, field_name):
format_amt = getattr(self, field_name) format_amt = getattr(self, field_name)
else: else:
format_amt = self.workbook.add_format() format_amt = self.workbook.add_format()
setattr(self, 'field_name', format_amt) setattr(self, 'field_name', format_amt)
format_amount = \ format_amount = \
'#,##0.' + ('0' * line_object.currency_id.decimal_places)
'#,##0.' + ('0' * line_object[
'currency_id'].decimal_places)
format_amt.set_num_format(format_amount) format_amt.set_num_format(format_amount)
return format_amt return format_amt
@ -460,8 +466,11 @@ class AbstractReportXslx(models.AbstractModel):
format_amt = getattr(self, 'format_amount') format_amt = getattr(self, 'format_amount')
field_prefix = 'format_amount' field_prefix = 'format_amount'
if line_dict.get('currency_id', False) and line_dict['currency_id']: if line_dict.get('currency_id', False) and line_dict['currency_id']:
if isinstance(line_dict['currency_id'], int):
currency = self.env['res.currency'].browse( currency = self.env['res.currency'].browse(
[line_dict['currency_id']])
line_dict['currency_id'])
else:
currency = line_dict['currency_id']
field_name = \ field_name = \
'%s_%s' % (field_prefix, currency.name) '%s_%s' % (field_prefix, currency.name)
if hasattr(self, field_name): if hasattr(self, field_name):

64
account_financial_report/report/aged_partner_balance.py

@ -58,7 +58,7 @@ class AgedPartnerBalanceReport(models.AbstractModel):
@api.model @api.model
def _get_move_lines_domain(self, company_id, account_ids, partner_ids, def _get_move_lines_domain(self, company_id, account_ids, partner_ids,
only_posted_moves):
only_posted_moves, date_from):
domain = [('account_id', 'in', account_ids), domain = [('account_id', 'in', account_ids),
('company_id', '=', company_id), ('company_id', '=', company_id),
('reconciled', '=', False)] ('reconciled', '=', False)]
@ -66,6 +66,8 @@ class AgedPartnerBalanceReport(models.AbstractModel):
domain += [('partner_id', 'in', partner_ids)] domain += [('partner_id', 'in', partner_ids)]
if only_posted_moves: if only_posted_moves:
domain += [('move_id.state', '=', 'posted')] domain += [('move_id.state', '=', 'posted')]
if date_from:
domain += [('date', '>', date_from)]
return domain return domain
@api.model @api.model
@ -95,7 +97,7 @@ class AgedPartnerBalanceReport(models.AbstractModel):
return ag_pb_data return ag_pb_data
def _get_account_partial_reconciled(self, company_id, date_at_object): def _get_account_partial_reconciled(self, company_id, date_at_object):
domain = [('max_date', '>=', date_at_object),
domain = [('max_date', '>', date_at_object),
('company_id', '=', company_id)] ('company_id', '=', company_id)]
fields = ['debit_move_id', 'credit_move_id', 'amount'] fields = ['debit_move_id', 'credit_move_id', 'amount']
accounts_partial_reconcile = \ accounts_partial_reconcile = \
@ -138,11 +140,14 @@ class AgedPartnerBalanceReport(models.AbstractModel):
debit_amount, credit_amount, ml_ids, debit_amount, credit_amount, ml_ids,
account_ids, company_id, partner_ids, account_ids, company_id, partner_ids,
only_posted_moves): only_posted_moves):
reconciled_ids = list(debit_ids) + list(credit_ids)
new_ml_ids = []
for reconciled_id in reconciled_ids:
if reconciled_id not in ml_ids and reconciled_id not in new_ml_ids:
new_ml_ids += [reconciled_id]
debit_ids = set(debit_ids)
credit_ids = set(credit_ids)
in_credit_but_not_in_debit = credit_ids - debit_ids
reconciled_ids = list(debit_ids) + list(in_credit_but_not_in_debit)
reconciled_ids = set(reconciled_ids)
ml_ids = set(ml_ids)
new_ml_ids = reconciled_ids - ml_ids
new_ml_ids = list(new_ml_ids)
new_domain = self._get_new_move_lines_domain(new_ml_ids, account_ids, new_domain = self._get_new_move_lines_domain(new_ml_ids, account_ids,
company_id, partner_ids, company_id, partner_ids,
only_posted_moves) only_posted_moves)
@ -164,9 +169,10 @@ class AgedPartnerBalanceReport(models.AbstractModel):
def _get_move_lines_data( def _get_move_lines_data(
self, company_id, account_ids, partner_ids, date_at_object, self, company_id, account_ids, partner_ids, date_at_object,
only_posted_moves, show_move_line_details):
domain = self._get_move_lines_domain(company_id, account_ids,
partner_ids, only_posted_moves)
date_from, only_posted_moves, show_move_line_details):
domain = self._get_move_lines_domain(
company_id, account_ids, partner_ids, only_posted_moves, date_from
)
ml_fields = [ ml_fields = [
'id', 'name', 'date', 'move_id', 'journal_id', 'account_id', 'id', 'name', 'date', 'move_id', 'journal_id', 'account_id',
'partner_id', 'amount_residual', 'date_maturity', 'ref', 'partner_id', 'amount_residual', 'date_maturity', 'ref',
@ -182,25 +188,20 @@ 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:
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)
ml_ids = list(map(operator.itemgetter('id'), move_lines))
debit_ids = list(map(operator.itemgetter('debit_move_id'),
acc_partial_rec))
credit_ids = list(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,
company_id, partner_ids, only_posted_moves company_id, partner_ids, only_posted_moves
) )
moves_lines_to_remove = []
for move_line in move_lines:
if move_line['date'] > date_at_object or \
move_lines = [move_line for move_line in move_lines if
move_line['date'] <= date_at_object and not
float_is_zero(move_line['amount_residual'], float_is_zero(move_line['amount_residual'],
precision_digits=2):
moves_lines_to_remove.append(move_line)
if len(moves_lines_to_remove) > 0:
for move_line_to_remove in moves_lines_to_remove:
move_lines.remove(move_line_to_remove)
precision_digits=2)]
for move_line in move_lines: for move_line in move_lines:
journals_ids.add(move_line['journal_id'][0]) journals_ids.add(move_line['journal_id'][0])
acc_id = move_line['account_id'][0] acc_id = move_line['account_id'][0]
@ -222,13 +223,25 @@ class AgedPartnerBalanceReport(models.AbstractModel):
prt_id) prt_id)
move_line_data = {} move_line_data = {}
if show_move_line_details: if show_move_line_details:
if move_line['ref'] == move_line['name']:
if move_line['ref']:
ref_label = move_line['ref']
else:
ref_label = ''
elif not move_line['ref']:
ref_label = move_line['name']
elif not move_line['name']:
ref_label = move_line['ref']
else:
ref_label = move_line['ref'] + str(' - ') + move_line[
'name']
move_line_data.update({ move_line_data.update({
'date': move_line['date'], 'date': move_line['date'],
'entry': move_line['move_id'][1], 'entry': move_line['move_id'][1],
'jnl_id': move_line['journal_id'][0], 'jnl_id': move_line['journal_id'][0],
'acc_id': acc_id, 'acc_id': acc_id,
'partner': prt_name, 'partner': prt_name,
'ref': move_line['ref'],
'ref_label': ref_label,
'due_date': move_line['date_maturity'], 'due_date': move_line['date_maturity'],
'residual': move_line['amount_residual'], 'residual': move_line['amount_residual'],
}) })
@ -353,11 +366,12 @@ class AgedPartnerBalanceReport(models.AbstractModel):
partner_ids = data['partner_ids'] partner_ids = data['partner_ids']
date_at = data['date_at'] date_at = data['date_at']
date_at_object = datetime.strptime(date_at, '%Y-%m-%d').date() date_at_object = datetime.strptime(date_at, '%Y-%m-%d').date()
date_from = data['date_from']
only_posted_moves = data['only_posted_moves'] only_posted_moves = data['only_posted_moves']
show_move_line_details = data['show_move_line_details'] show_move_line_details = data['show_move_line_details']
ag_pb_data, accounts_data, partners_data, \ ag_pb_data, accounts_data, partners_data, \
journals_data = self._get_move_lines_data( journals_data = self._get_move_lines_data(
company_id, account_ids, partner_ids, date_at_object,
company_id, account_ids, partner_ids, date_at_object, date_from,
only_posted_moves, show_move_line_details) only_posted_moves, show_move_line_details)
aged_partner_data = self._create_account_list( aged_partner_data = self._create_account_list(
ag_pb_data, accounts_data, partners_data, journals_data, ag_pb_data, accounts_data, partners_data, journals_data,

2
account_financial_report/report/aged_partner_balance_xlsx.py

@ -72,7 +72,7 @@ class AgedPartnerBalanceXslx(models.AbstractModel):
2: {'header': _('Journal'), 'field': 'journal', 'width': 8}, 2: {'header': _('Journal'), 'field': 'journal', 'width': 8},
3: {'header': _('Account'), 'field': 'account', 'width': 9}, 3: {'header': _('Account'), 'field': 'account', 'width': 9},
4: {'header': _('Partner'), 'field': 'partner', 'width': 25}, 4: {'header': _('Partner'), 'field': 'partner', 'width': 25},
5: {'header': _('Ref - Label'), 'field': 'ref', 'width': 40},
5: {'header': _('Ref - Label'), 'field': 'ref_label', 'width': 40},
6: {'header': _('Due date'), 'field': 'due_date', 'width': 11}, 6: {'header': _('Due date'), 'field': 'due_date', 'width': 11},
7: {'header': _('Residual'), 7: {'header': _('Residual'),
'field': 'residual', 'field': 'residual',

85
account_financial_report/report/general_ledger.py

@ -5,6 +5,7 @@
from odoo import models, api from odoo import models, api
import calendar import calendar
import datetime import datetime
import operator
class GeneralLedgerReport(models.AbstractModel): class GeneralLedgerReport(models.AbstractModel):
@ -50,11 +51,14 @@ class GeneralLedgerReport(models.AbstractModel):
'id': tax.id, 'id': tax.id,
'amount': tax.amount, 'amount': tax.amount,
'amount_type': tax.amount_type, 'amount_type': tax.amount_type,
'display_name': tax.display_name,
}}) }})
if tax.amount_type == 'percent' or tax.amount_type == 'division': if tax.amount_type == 'percent' or tax.amount_type == 'division':
taxes_data[tax.id]['string'] = '%' taxes_data[tax.id]['string'] = '%'
else: else:
taxes_data[tax.id]['string'] = '' taxes_data[tax.id]['string'] = ''
taxes_data[tax.id]['tax_name'] = tax.display_name + ' (' + \
str(tax.amount) + taxes_data[tax.id]['string'] + ')'
return taxes_data return taxes_data
def _get_acc_prt_accounts_ids(self, company_id): def _get_acc_prt_accounts_ids(self, company_id):
@ -287,6 +291,7 @@ class GeneralLedgerReport(models.AbstractModel):
'partner_name': move_line['partner_id'][1] if 'partner_name': move_line['partner_id'][1] if
move_line['partner_id'] else "", move_line['partner_id'] else "",
'ref': '' if not move_line['ref'] else move_line['ref'], 'ref': '' if not move_line['ref'] else move_line['ref'],
'name': '' if not move_line['name'] else move_line['name'],
'tax_ids': move_line['tax_ids'], 'tax_ids': move_line['tax_ids'],
'debit': move_line['debit'], 'debit': move_line['debit'],
'credit': move_line['credit'], 'credit': move_line['credit'],
@ -299,6 +304,15 @@ class GeneralLedgerReport(models.AbstractModel):
'tag_ids': move_line['analytic_tag_ids'], 'tag_ids': move_line['analytic_tag_ids'],
'currency_id': move_line['currency_id'], 'currency_id': move_line['currency_id'],
} }
if move_line_data['ref'] == move_line_data['name'] or move_line_data[
'ref'] == '':
ref_label = move_line_data['name']
elif move_line_data['name'] == '':
ref_label = move_line_data['ref']
else:
ref_label = move_line_data['ref'] + str(' - ') + move_line_data[
'name']
move_line_data.update({'ref_label': ref_label})
return move_line_data return move_line_data
@api.model @api.model
@ -356,6 +370,22 @@ class GeneralLedgerReport(models.AbstractModel):
gen_ld_data[acc_id]['fin_bal']['bal_curr'] = 0.0 gen_ld_data[acc_id]['fin_bal']['bal_curr'] = 0.0
return gen_ld_data return gen_ld_data
def _get_reconciled_after_date_to_ids(self, full_reconcile_ids, date_to):
full_reconcile_ids = list(full_reconcile_ids)
domain = [('max_date', '>', date_to),
('full_reconcile_id', 'in', full_reconcile_ids)]
fields = ['full_reconcile_id']
reconciled_after_date_to = \
self.env['account.partial.reconcile'].search_read(
domain=domain,
fields=fields
)
rec_after_date_to_ids = list(map(
operator.itemgetter('full_reconcile_id'),
reconciled_after_date_to))
rec_after_date_to_ids = [i[0] for i in rec_after_date_to_ids]
return rec_after_date_to_ids
def _get_period_ml_data( def _get_period_ml_data(
self, account_ids, partner_ids, company_id, foreign_currency, self, account_ids, partner_ids, company_id, foreign_currency,
only_posted_moves, hide_account_at_0, date_from, date_to, only_posted_moves, hide_account_at_0, date_from, date_to,
@ -369,7 +399,7 @@ class GeneralLedgerReport(models.AbstractModel):
'id', 'name', 'date', 'move_id', 'journal_id', 'account_id', 'id', 'name', 'date', 'move_id', 'journal_id', 'account_id',
'partner_id', 'debit', 'credit', 'balance', 'currency_id', 'partner_id', 'debit', 'credit', 'balance', 'currency_id',
'full_reconcile_id', 'tax_ids', 'analytic_tag_ids', 'full_reconcile_id', 'tax_ids', 'analytic_tag_ids',
'amount_currency', 'ref']
'amount_currency', 'ref', 'name']
move_lines = self.env['account.move.line'].search_read( move_lines = self.env['account.move.line'].search_read(
domain=domain, domain=domain,
fields=ml_fields) fields=ml_fields)
@ -442,18 +472,25 @@ class GeneralLedgerReport(models.AbstractModel):
accounts_data = self._get_accounts_data(gen_ld_data.keys()) accounts_data = self._get_accounts_data(gen_ld_data.keys())
taxes_data = self._get_taxes_data(list(taxes_ids)) taxes_data = self._get_taxes_data(list(taxes_ids))
tags_data = self._get_tags_data(list(tags_ids)) tags_data = self._get_tags_data(list(tags_ids))
rec_after_date_to_ids = self._get_reconciled_after_date_to_ids(
full_reconcile_data.keys(), date_to)
return gen_ld_data, accounts_data, partners_data, journals_data, \ return gen_ld_data, accounts_data, partners_data, journals_data, \
full_reconcile_data, taxes_data, tags_data
full_reconcile_data, taxes_data, tags_data, rec_after_date_to_ids
@api.model @api.model
def _recalculate_cumul_balance(self, move_lines, last_cumul_balance):
def _recalculate_cumul_balance(self, move_lines, last_cumul_balance,
rec_after_date_to_ids):
for move_line in move_lines: for move_line in move_lines:
move_line['balance'] += last_cumul_balance move_line['balance'] += last_cumul_balance
last_cumul_balance = move_line['balance'] last_cumul_balance = move_line['balance']
if move_line['rec_id'] in rec_after_date_to_ids:
move_line['rec_name'] = str('*')+move_line['rec_name']
return move_lines return move_lines
@api.model @api.model
def _create_general_ledger(self, gen_led_data, accounts_data):
def _create_general_ledger(
self, gen_led_data, accounts_data,
show_partner_details, rec_after_date_to_ids):
general_ledger = [] general_ledger = []
for acc_id in gen_led_data.keys(): for acc_id in gen_led_data.keys():
account = {} account = {}
@ -473,15 +510,18 @@ class GeneralLedgerReport(models.AbstractModel):
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'])) move_lines = sorted(move_lines, key=lambda k: (k['date']))
move_lines = self._recalculate_cumul_balance( move_lines = self._recalculate_cumul_balance(
move_lines, gen_led_data[acc_id]['init_bal']['balance'])
move_lines, gen_led_data[acc_id]['init_bal']['balance'],
rec_after_date_to_ids)
account.update({'move_lines': move_lines}) account.update({'move_lines': move_lines})
else: else:
if show_partner_details:
list_partner = [] list_partner = []
for prt_id in gen_led_data[acc_id].keys(): for prt_id in gen_led_data[acc_id].keys():
partner = {} partner = {}
move_lines = [] move_lines = []
if not isinstance(prt_id, int): if not isinstance(prt_id, int):
account.update({prt_id: gen_led_data[acc_id][prt_id]})
account.update({prt_id: gen_led_data[acc_id][
prt_id]})
else: else:
for ml_id in gen_led_data[acc_id][prt_id].keys(): for ml_id in gen_led_data[acc_id][prt_id].keys():
if not isinstance(ml_id, int): if not isinstance(ml_id, int):
@ -495,10 +535,30 @@ class GeneralLedgerReport(models.AbstractModel):
move_lines = self._recalculate_cumul_balance( move_lines = self._recalculate_cumul_balance(
move_lines, move_lines,
gen_led_data[acc_id][prt_id]['init_bal'][ gen_led_data[acc_id][prt_id]['init_bal'][
'balance'])
'balance'],
rec_after_date_to_ids)
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})
else:
move_lines = []
for prt_id in gen_led_data[acc_id].keys():
if not isinstance(prt_id, int):
account.update({prt_id: gen_led_data[acc_id][
prt_id]})
else:
for ml_id in gen_led_data[acc_id][prt_id].keys():
if isinstance(ml_id, int):
move_lines += [
gen_led_data[acc_id][prt_id][ml_id]]
move_lines = sorted(move_lines, key=lambda k: (k['date']))
move_lines = self._recalculate_cumul_balance(
move_lines, gen_led_data[acc_id]['init_bal'][
'balance'], rec_after_date_to_ids)
account.update({
'move_lines': move_lines,
'partners': False,
})
general_ledger += [account] general_ledger += [account]
return general_ledger return general_ledger
@ -520,7 +580,7 @@ class GeneralLedgerReport(models.AbstractModel):
date = date_to date = date_to
centralized_ml[jnl_id][month].update({ centralized_ml[jnl_id][month].update({
'journal_id': jnl_id, 'journal_id': jnl_id,
'ref': 'Centralized entries',
'ref_label': 'Centralized entries',
'date': date, 'date': date,
'debit': 0.0, 'debit': 0.0,
'credit': 0.0, 'credit': 0.0,
@ -582,6 +642,7 @@ class GeneralLedgerReport(models.AbstractModel):
account_ids = data['account_ids'] account_ids = data['account_ids']
analytic_tag_ids = data['analytic_tag_ids'] analytic_tag_ids = data['analytic_tag_ids']
cost_center_ids = data['cost_center_ids'] cost_center_ids = data['cost_center_ids']
show_partner_details = data['show_partner_details']
hide_account_at_0 = data['hide_account_at_0'] hide_account_at_0 = data['hide_account_at_0']
foreign_currency = data['foreign_currency'] foreign_currency = data['foreign_currency']
only_posted_moves = data['only_posted_moves'] only_posted_moves = data['only_posted_moves']
@ -595,13 +656,17 @@ class GeneralLedgerReport(models.AbstractModel):
cost_center_ids) cost_center_ids)
centralize = data['centralize'] centralize = data['centralize']
gen_ld_data, accounts_data, partners_data, journals_data, \ gen_ld_data, accounts_data, partners_data, journals_data, \
full_reconcile_data, taxes_data, tags_data = \
full_reconcile_data, taxes_data, \
tags_data, rec_after_date_to_ids = \
self._get_period_ml_data( self._get_period_ml_data(
account_ids, partner_ids, company_id, foreign_currency, account_ids, partner_ids, company_id, foreign_currency,
only_posted_moves, hide_account_at_0, date_from, date_to, only_posted_moves, hide_account_at_0, date_from, date_to,
partners_data, gen_ld_data, partners_ids, partners_data, gen_ld_data, partners_ids,
centralize, analytic_tag_ids, cost_center_ids) centralize, analytic_tag_ids, cost_center_ids)
general_ledger = self._create_general_ledger(gen_ld_data, accounts_data)
general_ledger = self._create_general_ledger(
gen_ld_data, accounts_data,
show_partner_details, rec_after_date_to_ids
)
if centralize: if centralize:
for account in general_ledger: for account in general_ledger:
if account['centralized']: if account['centralized']:

30
account_financial_report/report/general_ledger_xlsx.py

@ -31,7 +31,7 @@ class GeneralLedgerXslx(models.AbstractModel):
'field': 'taxes_description', 'field': 'taxes_description',
'width': 15}, 'width': 15},
5: {'header': _('Partner'), 'field': 'partner_name', 'width': 25}, 5: {'header': _('Partner'), 'field': 'partner_name', 'width': 25},
6: {'header': _('Ref - Label'), 'field': 'ref', 'width': 40},
6: {'header': _('Ref - Label'), 'field': 'ref_label', 'width': 40},
7: {'header': _('Cost center'), 7: {'header': _('Cost center'),
'field': 'cost_center', 'field': 'cost_center',
'width': 15}, 'width': 15},
@ -165,12 +165,12 @@ class GeneralLedgerXslx(models.AbstractModel):
'currency_name': line['currency_id'][1], 'currency_name': line['currency_id'][1],
'currency_id': line['currency_id'][0], 'currency_id': line['currency_id'][0],
}) })
if line['ref'] != 'Centralized entries':
if line['ref_label'] != 'Centralized entries':
taxes_description = "" taxes_description = ""
tags = "" tags = ""
for tax_id in line['tax_ids']: for tax_id in line['tax_ids']:
taxes_description += str(taxes_data[tax_id][
'amount'])+" "+taxes_data[tax_id]['string']+" "
taxes_description += taxes_data[tax_id][
'tax_name'] + " "
for tag_id in line['tag_ids']: for tag_id in line['tag_ids']:
tags += tags_data[tag_id]['name']+" " tags += tags_data[tag_id]['name']+" "
line.update({ line.update({
@ -211,7 +211,7 @@ class GeneralLedgerXslx(models.AbstractModel):
}) })
if foreign_currency: if foreign_currency:
partner.update({ partner.update({
'initial_bal_culrr': partner['init_bal'][
'initial_bal_curr': partner['init_bal'][
'bal_curr'], 'bal_curr'],
}) })
self.write_initial_balance_from_dict(partner) self.write_initial_balance_from_dict(partner)
@ -222,13 +222,17 @@ class GeneralLedgerXslx(models.AbstractModel):
'account': account['code'], 'account': account['code'],
'journal': journals_data[line['journal_id']]['code'] 'journal': journals_data[line['journal_id']]['code']
}) })
if line['ref'] != 'Centralized entries':
if line['currency_id']:
line.update({
'currency_name': line['currency_id'][1],
'currency_id': line['currency_id'][0],
})
if line['ref_label'] != 'Centralized entries':
taxes_description = "" taxes_description = ""
tags = "" tags = ""
for tax_id in line['tax_ids']: for tax_id in line['tax_ids']:
taxes_description += \
str(taxes_data[tax_id]['amount']) + " " + \
taxes_data[tax_id]['string'] + " "
taxes_description += taxes_data[tax_id][
'tax_name'] + " "
for tag_id in line['tag_ids']: for tag_id in line['tag_ids']:
tags += tags_data[tag_id]['name'] + " " tags += tags_data[tag_id]['name'] + " "
line.update({ line.update({
@ -243,9 +247,11 @@ class GeneralLedgerXslx(models.AbstractModel):
'final_credit': partner['fin_bal']['credit'], 'final_credit': partner['fin_bal']['credit'],
'final_balance': partner['fin_bal']['balance'], 'final_balance': partner['fin_bal']['balance'],
}) })
if foreign_currency:
if foreign_currency and partner['currency_id']:
partner.update({ partner.update({
'final_bal_curr': partner['fin_bal']['bal_curr'], 'final_bal_curr': partner['fin_bal']['bal_curr'],
'currency_name': partner['currency_id'].name,
'currency_id': partner['currency_id'].id,
}) })
self.write_ending_balance_from_dict(partner) self.write_ending_balance_from_dict(partner)
@ -258,9 +264,11 @@ class GeneralLedgerXslx(models.AbstractModel):
'final_credit': account['fin_bal']['credit'], 'final_credit': account['fin_bal']['credit'],
'final_balance': account['fin_bal']['balance'], 'final_balance': account['fin_bal']['balance'],
}) })
if foreign_currency:
if foreign_currency and account['currency_id']:
account.update({ account.update({
'final_bal_curr': account['fin_bal']['bal_curr'], 'final_bal_curr': account['fin_bal']['bal_curr'],
'currency_name': account['currency_id'].name,
'currency_id': account['currency_id'].id,
}) })
self.write_ending_balance_from_dict(account) self.write_ending_balance_from_dict(account)

306
account_financial_report/report/open_items.py

@ -4,7 +4,6 @@
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 odoo.osv import expression
from datetime import date, datetime from datetime import date, datetime
import operator import operator
@ -29,100 +28,91 @@ class OpenItemsReport(models.AbstractModel):
'account_financial_report.report_open_items').render(rcontext) 'account_financial_report.report_open_items').render(rcontext)
return result return result
def _get_account_partial_reconciled(self, move_lines_data, date_at_object):
reconciled_ids = []
for move_line in move_lines_data:
if move_line['reconciled']:
reconciled_ids += [move_line['id']]
domain = [('max_date', '>=', date_at_object)]
domain += expression.OR(
[[('debit_move_id', 'in', reconciled_ids)],
[('credit_move_id', 'in', reconciled_ids)]])
def _get_account_partial_reconciled(self, company_id, date_at_object):
domain = [('max_date', '>', date_at_object),
('company_id', '=', company_id)]
fields = ['debit_move_id', 'credit_move_id', 'amount'] fields = ['debit_move_id', 'credit_move_id', 'amount']
accounts_partial_reconcile = \ accounts_partial_reconcile = \
self.env['account.partial.reconcile'].search_read( self.env['account.partial.reconcile'].search_read(
domain=domain, domain=domain,
fields=fields fields=fields
) )
debit_accounts_partial_amount = {}
credit_accounts_partial_amount = {}
debit_amount = {}
credit_amount = {}
for account_partial_reconcile_data in accounts_partial_reconcile: for account_partial_reconcile_data in accounts_partial_reconcile:
debit_move_id = account_partial_reconcile_data['debit_move_id'][0] debit_move_id = account_partial_reconcile_data['debit_move_id'][0]
credit_move_id = account_partial_reconcile_data['credit_move_id'][0] credit_move_id = account_partial_reconcile_data['credit_move_id'][0]
if debit_move_id not in debit_accounts_partial_amount.keys():
debit_accounts_partial_amount[debit_move_id] = 0.0
debit_accounts_partial_amount[debit_move_id] += \
if debit_move_id not in debit_amount.keys():
debit_amount[debit_move_id] = 0.0
debit_amount[debit_move_id] += \
account_partial_reconcile_data['amount'] account_partial_reconcile_data['amount']
if credit_move_id not in credit_accounts_partial_amount.keys():
credit_accounts_partial_amount[credit_move_id] = 0.0
credit_accounts_partial_amount[credit_move_id] += \
if credit_move_id not in credit_amount.keys():
credit_amount[credit_move_id] = 0.0
credit_amount[credit_move_id] += \
account_partial_reconcile_data['amount'] account_partial_reconcile_data['amount']
account_partial_reconcile_data.update({ account_partial_reconcile_data.update({
'debit_move_id': debit_move_id, 'debit_move_id': debit_move_id,
'credit_move_id': credit_move_id, 'credit_move_id': credit_move_id,
}) })
return accounts_partial_reconcile, debit_accounts_partial_amount, \
credit_accounts_partial_amount
return accounts_partial_reconcile, debit_amount, credit_amount
@api.model @api.model
def _get_query_domain(self, account_ids, partner_ids, date_at_object,
target_move, company_id, date_from):
query = """
WHERE aml.account_id in %s and aml.company_id = %s
""" % (tuple(account_ids) if len(account_ids) > 1 else "(%s)" %
account_ids[0], company_id)
if date_from:
query += " and aml.date >= '%s'" % date_from
def _get_new_move_lines_domain(self, new_ml_ids, account_ids, company_id,
partner_ids, target_moves):
domain = [('account_id', 'in', account_ids),
('company_id', '=', company_id),
('id', 'in', new_ml_ids)]
if partner_ids: if partner_ids:
query += " and aml.partner_id in %s" % (tuple(partner_ids),)
if target_move == 'posted':
query += " and am.state = 'posted'"
if date_at_object >= date.today():
query += " and aml.reconciled IS FALSE"
else:
query += """ and ((aml.reconciled IS FALSE OR aml.date >= '%s')
OR aml.full_reconcile_id IS NOT NULL)""" % date_at_object
return query
@api.model
def _get_query(self, account_ids, partner_ids, date_at_object,
target_move, company_id, date_from):
aml_fields = [
'id', 'date', 'move_id', 'journal_id', 'account_id', 'partner_id',
'ref', 'date_maturity', 'amount_residual', 'amount_currency',
'amount_residual_currency', 'debit', 'credit', 'currency_id',
'reconciled', 'full_reconcile_id']
query = ""
domain += [('partner_id', 'in', partner_ids)]
if target_moves == 'posted':
domain += [('move_id.state', '=', 'posted')]
return domain
# SELECT
for field in aml_fields:
if not query:
query = "SELECT aml.%s" % field
else:
query += ", aml.%s" % field
# name from res_partner
query += ", rp.name as partner_name"
# name from res_currency
query += ", rc.name as currency_name"
# state and name from account_move
query += ", am.state, am.name as move_name"
# FROM
query += """
FROM account_move_line as aml
LEFT JOIN res_partner as rp
ON aml.partner_id = rp.id
LEFT JOIN res_currency as rc
ON aml.currency_id = rc.id
LEFT JOIN account_move as am
ON am.id = aml.move_id
"""
def _recalculate_move_lines(self, move_lines, debit_ids, credit_ids,
debit_amount, credit_amount, ml_ids,
account_ids, company_id, partner_ids,
target_moves):
debit_ids = set(debit_ids)
credit_ids = set(credit_ids)
in_credit_but_not_in_debit = credit_ids - debit_ids
reconciled_ids = list(debit_ids) + list(in_credit_but_not_in_debit)
reconciled_ids = set(reconciled_ids)
ml_ids = set(ml_ids)
new_ml_ids = reconciled_ids - ml_ids
new_ml_ids = list(new_ml_ids)
new_domain = self._get_new_move_lines_domain(new_ml_ids, account_ids,
company_id, partner_ids,
target_moves)
ml_fields = [
'id', 'name', 'date', 'move_id', 'journal_id', 'account_id',
'partner_id', 'amount_residual', 'date_maturity', 'ref',
'debit', 'credit', 'reconciled', 'currency_id', 'amount_currency',
'amount_residual_currency']
new_move_lines = self.env['account.move.line'].search_read(
domain=new_domain, fields=ml_fields
)
move_lines = move_lines + new_move_lines
for move_line in move_lines:
ml_id = move_line['id']
if ml_id in debit_ids:
move_line['amount_residual'] += debit_amount[ml_id]
if ml_id in credit_ids:
move_line['amount_residual'] -= credit_amount[ml_id]
return move_lines
# WHERE
query += self._get_query_domain(account_ids, partner_ids,
date_at_object, target_move,
company_id, date_from)
return query
@api.model
def _get_move_lines_domain(self, company_id, account_ids, partner_ids,
target_move, date_from):
domain = [('account_id', 'in', account_ids),
('company_id', '=', company_id),
('reconciled', '=', False)]
if partner_ids:
domain += [('partner_id', 'in', partner_ids)]
if target_move == 'posted':
domain += [('move_id.state', '=', 'posted')]
if date_from:
domain += [('date', '>', date_from)]
return domain
def _get_accounts_data(self, accounts_ids): def _get_accounts_data(self, accounts_ids):
accounts = self.env['account.account'].browse(accounts_ids) accounts = self.env['account.account'].browse(accounts_ids)
@ -146,65 +136,59 @@ class OpenItemsReport(models.AbstractModel):
'code': journal.code}}) 'code': journal.code}})
return journals_data return journals_data
def _get_data(self, account_ids, partner_ids, date_at_object, target_move,
company_id, date_from):
query = self._get_query(account_ids, partner_ids, date_at_object,
target_move, company_id, date_from)
self._cr.execute(query)
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))
journal_ids = map(operator.itemgetter('journal_id'), move_lines_data)
journals_data = self._get_journals_data(list(journal_ids))
def _get_data(
self, account_ids, partner_ids, date_at_object,
target_move, company_id, date_from):
domain = self._get_move_lines_domain(company_id, account_ids,
partner_ids, target_move,
date_from)
ml_fields = [
'id', 'name', 'date', 'move_id', 'journal_id', 'account_id',
'partner_id', 'amount_residual', 'date_maturity', 'ref',
'debit', 'credit', 'reconciled', 'currency_id', 'amount_currency',
'amount_residual_currency']
move_lines = self.env['account.move.line'].search_read(
domain=domain, fields=ml_fields
)
journals_ids = set()
partners_ids = set()
partners_data = {}
if date_at_object < date.today(): if date_at_object < date.today():
accounts_partial_reconcile, debit_accounts_partial_amount, \
credit_accounts_partial_amount = \
self._get_account_partial_reconciled(move_lines_data,
acc_partial_rec, debit_amount, credit_amount = \
self._get_account_partial_reconciled(company_id,
date_at_object) date_at_object)
if accounts_partial_reconcile:
debit_ids = map(operator.itemgetter('debit_move_id'),
accounts_partial_reconcile)
credit_ids = map(operator.itemgetter('credit_move_id'),
accounts_partial_reconcile)
for move_line in move_lines_data:
if move_line['id'] in debit_ids:
move_line['amount_residual'] += \
debit_accounts_partial_amount[move_line['id']]
if move_line['id'] in credit_ids:
move_line['amount_residual'] -= \
credit_accounts_partial_amount[move_line['id']]
moves_lines_to_remove = []
for move_line in move_lines_data:
if move_line['date'] > date_at_object or float_is_zero(
move_line['amount_residual'], precision_digits=2):
moves_lines_to_remove.append(move_line)
if len(moves_lines_to_remove) > 0:
for move_line_to_remove in moves_lines_to_remove:
move_lines_data.remove(move_line_to_remove)
partners_data = {
0: {
'id': 0,
'name': 'Missing Partner'
}
}
if acc_partial_rec:
ml_ids = list(map(operator.itemgetter('id'), move_lines))
debit_ids = list(map(operator.itemgetter('debit_move_id'),
acc_partial_rec))
credit_ids = list(map(operator.itemgetter('credit_move_id'),
acc_partial_rec))
move_lines = self._recalculate_move_lines(
move_lines, debit_ids, credit_ids,
debit_amount, credit_amount, ml_ids, account_ids,
company_id, partner_ids, target_move
)
move_lines = [move_line for move_line in move_lines if
move_line['date'] <= date_at_object and not
float_is_zero(move_line['amount_residual'],
precision_digits=2)]
open_items_move_lines_data = {} open_items_move_lines_data = {}
for move_line in move_lines_data:
no_partner = True
for move_line in move_lines:
journals_ids.add(move_line['journal_id'][0])
acc_id = move_line['account_id'][0]
# Partners data # Partners data
if move_line['partner_id']: if move_line['partner_id']:
no_partner = False
prt_id = move_line['partner_id'][0]
prt_name = move_line['partner_id'][1]
else:
prt_id = 0
prt_name = "Missing Partner"
if prt_id not in partners_ids:
partners_data.update({ partners_data.update({
move_line['partner_id']: {
'id': move_line['partner_id'],
'name': move_line['partner_name'],
'currency_id': accounts_data[move_line[
'account_id']]['currency_id'],
}
prt_id: {'id': prt_id, 'name': prt_name}
}) })
else:
partners_data[0]['currency_id'] = accounts_data[move_line[
'account_id']]['currency_id']
partners_ids.add(prt_id)
# Move line update # Move line update
original = 0 original = 0
@ -214,32 +198,46 @@ class OpenItemsReport(models.AbstractModel):
if not float_is_zero(move_line['debit'], precision_digits=2): if not float_is_zero(move_line['debit'], precision_digits=2):
original = move_line['debit'] original = move_line['debit']
if move_line['ref'] == move_line['name']:
if move_line['ref']:
ref_label = move_line['ref']
else:
ref_label = ''
elif not move_line['ref']:
ref_label = move_line['name']
elif not move_line['name']:
ref_label = move_line['ref']
else:
ref_label = move_line['ref'] + str(' - ') + move_line['name']
move_line.update({ move_line.update({
'date': move_line['date'].strftime("%d/%m/%Y"),
'date': move_line['date'],
'date_maturity': move_line["date_maturity"] 'date_maturity': move_line["date_maturity"]
and move_line["date_maturity"].strftime("%d/%m/%Y"), 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_name': '' if no_partner else move_line['partner_name'],
'ref': '' if not move_line['ref'] else move_line['ref'],
'account': accounts_data[move_line['account_id']]['code'],
'journal': journals_data[move_line['journal_id']]['code'],
'partner_id': prt_id,
'partner_name': prt_name,
'ref_label': ref_label,
'journal_id': move_line['journal_id'][0],
'move_name': move_line['move_id'][1],
'currency_id': move_line['currency_id'][0]
if move_line['currency_id'] else False,
'currency_name': move_line['currency_id'][1]
if move_line['currency_id'] else False,
}) })
# Open Items Move Lines Data # Open Items Move Lines Data
if move_line['account_id'] not in open_items_move_lines_data.keys():
open_items_move_lines_data[move_line['account_id']] = {
move_line['partner_id']: [move_line]}
if acc_id not in open_items_move_lines_data.keys():
open_items_move_lines_data[acc_id] = {prt_id: [move_line]}
else: else:
if move_line['partner_id'] not in \
open_items_move_lines_data[move_line[
'account_id']].keys():
open_items_move_lines_data[move_line['account_id']][
move_line['partner_id']] = [move_line]
if prt_id not in open_items_move_lines_data[acc_id].keys():
open_items_move_lines_data[acc_id][prt_id] = [move_line]
else: else:
open_items_move_lines_data[move_line['account_id']][
move_line['partner_id']].append(move_line)
return move_lines_data, partners_data, journals_data, accounts_data, \
open_items_move_lines_data[acc_id][prt_id].append(move_line)
journals_data = self._get_journals_data(list(journals_ids))
accounts_data = self._get_accounts_data(
open_items_move_lines_data.keys())
return move_lines, partners_data, journals_data, accounts_data, \
open_items_move_lines_data open_items_move_lines_data
@api.model @api.model
@ -260,8 +258,10 @@ class OpenItemsReport(models.AbstractModel):
return total_amount return total_amount
@api.model @api.model
def _get_open_items_no_partners(self, open_items_move_lines_data):
def _order_open_items_by_date(
self, open_items_move_lines_data, show_partner_details):
new_open_items = {} new_open_items = {}
if not show_partner_details:
for acc_id in open_items_move_lines_data.keys(): for acc_id in open_items_move_lines_data.keys():
new_open_items[acc_id] = {} new_open_items[acc_id] = {}
move_lines = [] move_lines = []
@ -270,6 +270,16 @@ class OpenItemsReport(models.AbstractModel):
move_lines += [move_line] move_lines += [move_line]
move_lines = sorted(move_lines, key=lambda k: (k['date'])) move_lines = sorted(move_lines, key=lambda k: (k['date']))
new_open_items[acc_id] = move_lines new_open_items[acc_id] = move_lines
else:
for acc_id in open_items_move_lines_data.keys():
new_open_items[acc_id] = {}
for prt_id in open_items_move_lines_data[acc_id]:
new_open_items[acc_id][prt_id] = {}
move_lines = []
for move_line in open_items_move_lines_data[acc_id][prt_id]:
move_lines += [move_line]
move_lines = sorted(move_lines, key=lambda k: (k['date']))
new_open_items[acc_id][prt_id] = move_lines
return new_open_items return new_open_items
@api.multi @api.multi
@ -291,9 +301,8 @@ class OpenItemsReport(models.AbstractModel):
target_move, company_id, date_from) target_move, company_id, date_from)
total_amount = self._calculate_amounts(open_items_move_lines_data) total_amount = self._calculate_amounts(open_items_move_lines_data)
if not show_partner_details:
open_items_move_lines_data = self._get_open_items_no_partners(
open_items_move_lines_data
open_items_move_lines_data = self._order_open_items_by_date(
open_items_move_lines_data, show_partner_details
) )
return{ return{
'doc_ids': [wizard_id], 'doc_ids': [wizard_id],
@ -306,6 +315,7 @@ class OpenItemsReport(models.AbstractModel):
'date_at': date_at_object.strftime("%d/%m/%Y"), 'date_at': date_at_object.strftime("%d/%m/%Y"),
'hide_account_at_0': data['hide_account_at_0'], 'hide_account_at_0': data['hide_account_at_0'],
'target_move': data['target_move'], 'target_move': data['target_move'],
'journals_data': journals_data,
'partners_data': partners_data, 'partners_data': partners_data,
'accounts_data': accounts_data, 'accounts_data': accounts_data,
'total_amount': total_amount, 'total_amount': total_amount,

22
account_financial_report/report/open_items_xlsx.py

@ -22,11 +22,11 @@ class OpenItemsXslx(models.AbstractModel):
def _get_report_columns(self, report): def _get_report_columns(self, report):
res = { res = {
0: {'header': _('Date'), 'field': 'date', 'width': 11}, 0: {'header': _('Date'), 'field': 'date', 'width': 11},
1: {'header': _('Entry'), 'field': 'move_id_name', 'width': 18},
1: {'header': _('Entry'), 'field': 'move_name', 'width': 18},
2: {'header': _('Journal'), 'field': 'journal', 'width': 8}, 2: {'header': _('Journal'), 'field': 'journal', 'width': 8},
3: {'header': _('Account'), 'field': 'account', 'width': 9}, 3: {'header': _('Account'), 'field': 'account', 'width': 9},
4: {'header': _('Partner'), 'field': 'partner', 'width': 25},
5: {'header': _('Ref - Label'), 'field': 'ref', 'width': 40},
4: {'header': _('Partner'), 'field': 'partner_name', 'width': 25},
5: {'header': _('Ref - Label'), 'field': 'ref_label', 'width': 40},
6: {'header': _('Due date'), 'field': 'date_maturity', 'width': 11}, 6: {'header': _('Due date'), 'field': 'date_maturity', 'width': 11},
7: {'header': _('Original'), 7: {'header': _('Original'),
'field': 'original', 'field': 'original',
@ -92,6 +92,7 @@ class OpenItemsXslx(models.AbstractModel):
Open_items = res_data['Open_Items'] Open_items = res_data['Open_Items']
accounts_data = res_data['accounts_data'] accounts_data = res_data['accounts_data']
partners_data = res_data['partners_data'] partners_data = res_data['partners_data']
journals_data = res_data['journals_data']
total_amount = res_data['total_amount'] total_amount = res_data['total_amount']
show_partner_details = res_data['show_partner_details'] show_partner_details = res_data['show_partner_details']
for account_id in Open_items.keys(): for account_id in Open_items.keys():
@ -112,9 +113,20 @@ class OpenItemsXslx(models.AbstractModel):
# Display account move lines # Display account move lines
for line in Open_items[account_id][partner_id]: for line in Open_items[account_id][partner_id]:
line.update({
'account': accounts_data[account_id]['code'],
'journal': journals_data[line['journal_id']][
'code']
})
self.write_line_from_dict(line) self.write_line_from_dict(line)
# Display ending balance line for partner # Display ending balance line for partner
partners_data[partner_id].update({
'currency_id': accounts_data[account_id][
'currency_id'],
'currency_name': accounts_data[account_id][
'currency_name']
})
self.write_ending_balance_from_dict( self.write_ending_balance_from_dict(
partners_data[partner_id], type_object, total_amount, partners_data[partner_id], type_object, total_amount,
account_id, partner_id) account_id, partner_id)
@ -127,6 +139,10 @@ class OpenItemsXslx(models.AbstractModel):
# Display account move lines # Display account move lines
for line in Open_items[account_id]: for line in Open_items[account_id]:
line.update({
'account': accounts_data[account_id]['code'],
'journal': journals_data[line['journal_id']]['code']
})
self.write_line_from_dict(line) self.write_line_from_dict(line)
# Display ending balance line for account # Display ending balance line for account

2
account_financial_report/report/templates/aged_partner_balance.xml

@ -271,7 +271,7 @@
<!-- t-att-data-res-model="'account.move.line'"--> <!-- t-att-data-res-model="'account.move.line'"-->
<!-- class="o_account_financial_reports_web_action"--> <!-- class="o_account_financial_reports_web_action"-->
<!-- style="color: black;">--> <!-- style="color: black;">-->
<t t-raw="line['ref']"/>
<t t-raw="line['ref_label']"/>
<!-- </a>--> <!-- </a>-->
<!-- </span>--> <!-- </span>-->
</div> </div>

18
account_financial_report/report/templates/general_ledger.xml

@ -285,7 +285,7 @@
<t t-if="foreign_currency"> <t t-if="foreign_currency">
<t t-if="o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')"> <t t-if="o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')">
<div class="act_as_cell amount" style="width: 2.08%;"> <div class="act_as_cell amount" style="width: 2.08%;">
<span t-field="o._get_atr_from_dict(account['id'], accounts_data, 'currency_name')"/>
<span t-esc="o._get_atr_from_dict(account['id'], accounts_data, 'currency_name')"/>
</div> </div>
<div class="act_as_cell amount" style="width: 5.19%;"> <div class="act_as_cell amount" style="width: 5.19%;">
<t t-if="type == 'account_type'"> <t t-if="type == 'account_type'">
@ -298,7 +298,7 @@
class="o_account_financial_reports_web_action_monetary_multi" class="o_account_financial_reports_web_action_monetary_multi"
style="color: black;"> style="color: black;">
<t <t
t-raw="account_or_partner_object['init_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': account.account_id.currency_id}"/></a>
t-raw="account_or_partner_object['init_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')}"/></a>
</span> </span>
</t> </t>
<t t-if="type == 'partner_type'"> <t t-if="type == 'partner_type'">
@ -311,7 +311,7 @@
t-att-data-res-model="'account.move.line'" t-att-data-res-model="'account.move.line'"
class="o_account_financial_reports_web_action_monetary_multi" class="o_account_financial_reports_web_action_monetary_multi"
style="color: black;"> style="color: black;">
<t t-raw="account_or_partner_object['init_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': account.account_id.currency_id}"/></a>
<t t-raw="account_or_partner_object['init_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')}"/></a>
</span> </span>
</t> </t>
</div> </div>
@ -386,7 +386,7 @@
<div class="act_as_cell left"> <div class="act_as_cell left">
<t t-if="taxes_data and line['tax_ids']"> <t t-if="taxes_data and line['tax_ids']">
<t t-foreach="line['tax_ids']" t-as="tax_id"> <t t-foreach="line['tax_ids']" t-as="tax_id">
<span t-esc="o._get_atr_from_dict(tax_id, taxes_data, 'amount')"/> <span t-esc="o._get_atr_from_dict(tax_id, taxes_data, 'string')"/>
<span t-esc="o._get_atr_from_dict(tax_id, taxes_data, 'tax_name')"/>
</t> </t>
</t> </t>
</div> </div>
@ -410,14 +410,14 @@
t-att-data-res-model="res_model" t-att-data-res-model="res_model"
class="o_account_financial_reports_web_action" class="o_account_financial_reports_web_action"
style="color: black;"> style="color: black;">
<t t-raw="line['ref']"/></a>
<t t-raw="line['ref_label']"/></a>
</span> </span>
</t> </t>
<t t-if="not line['id']"> <t t-if="not line['id']">
<span> <span>
<a class="o_account_financial_reports_web_action" <a class="o_account_financial_reports_web_action"
style="color: black;"> style="color: black;">
<t t-raw="line['ref']"/></a>
<t t-raw="line['ref_label']"/></a>
</span> </span>
</t> </t>
</div> </div>
@ -589,7 +589,7 @@
<t t-if="foreign_currency"> <t t-if="foreign_currency">
<t t-if="o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')"> <t t-if="o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')">
<div class="act_as_cell amount" style="width: 2.08%;"> <div class="act_as_cell amount" style="width: 2.08%;">
<span t-field="o._get_atr_from_dict(account['id'], accounts_data, 'currency_name')"/>
<span t-esc="o._get_atr_from_dict(account['id'], accounts_data, 'currency_name')"/>
</div> </div>
<div class="act_as_cell amount" style="width: 5.19%;"> <div class="act_as_cell amount" style="width: 5.19%;">
<t t-if="type == 'account_type'"> <t t-if="type == 'account_type'">
@ -602,7 +602,7 @@
class="o_account_financial_reports_web_action_monetary_multi" class="o_account_financial_reports_web_action_monetary_multi"
style="color: black;"> style="color: black;">
<t <t
t-raw="account_or_partner_object['fin_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': account_or_partner_object.account_id.currency_id}"/></a>
t-raw="account_or_partner_object['fin_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')}"/></a>
</span> </span>
</t> </t>
<t t-if="type == 'partner_type'"> <t t-if="type == 'partner_type'">
@ -614,7 +614,7 @@
t-att-data-res-model="'account.move.line'" t-att-data-res-model="'account.move.line'"
class="o_account_financial_reports_web_action_monetary_multi" class="o_account_financial_reports_web_action_monetary_multi"
style="color: black;"> style="color: black;">
<t t-raw="account_or_partner_object['fin_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': account_or_partner_object.report_account_id.currency_id}"/></a>
<t t-raw="account_or_partner_object['fin_bal']['bal_curr']" t-options="{'widget': 'monetary', 'display_currency': o._get_atr_from_dict(account['id'], accounts_data, 'currency_id')}"/></a>
</span> </span>
</t> </t>
</div> </div>

8
account_financial_report/report/templates/open_items.xml

@ -143,7 +143,7 @@
<div class="act_as_row lines"> <div class="act_as_row lines">
<!--## date--> <!--## date-->
<div class="act_as_cell left"> <div class="act_as_cell left">
<span t-raw="line['date']"/>
<span t-raw="line['date'].strftime('%d/%m/%Y')"/>
</div> </div>
<!--## move--> <!--## move-->
<div class="act_as_cell left"> <div class="act_as_cell left">
@ -159,11 +159,11 @@
</div> </div>
<!--## journal--> <!--## journal-->
<div class="act_as_cell left"> <div class="act_as_cell left">
<span t-esc="line['journal']"/>
<span t-esc="journals_data[line['journal_id']]['code']"/>
</div> </div>
<!--## account code--> <!--## account code-->
<div class="act_as_cell left"> <div class="act_as_cell left">
<span t-esc="line['account']"/>
<span t-esc="accounts_data[account_id]['code']"/>
</div> </div>
<!--## partner--> <!--## partner-->
<div class="act_as_cell left"> <div class="act_as_cell left">
@ -172,7 +172,7 @@
</div> </div>
<!--## ref - label--> <!--## ref - label-->
<div class="act_as_cell left"> <div class="act_as_cell left">
<span t-esc="line['ref']"/>
<span t-esc="line['ref_label']"/>
</div> </div>
<!--## date_due--> <!--## date_due-->
<div class="act_as_cell left"> <div class="act_as_cell left">

71
account_financial_report/report/trial_balance.py

@ -154,14 +154,25 @@ class TrialBalanceReport(models.AbstractModel):
for initial_balance in initial_balances: for initial_balance in initial_balances:
pl_initial_balance += initial_balance['balance'] pl_initial_balance += initial_balance['balance']
if foreign_currency: if foreign_currency:
pl_initial_currency_balance += initial_balance[
'amount_currency']
pl_initial_currency_balance += round(initial_balance[
'amount_currency'], 2)
return pl_initial_balance, pl_initial_currency_balance return pl_initial_balance, pl_initial_currency_balance
def _get_data(self, account_ids, journal_ids, partner_ids, def _get_data(self, account_ids, journal_ids, partner_ids,
company_id, date_to, date_from, foreign_currency, company_id, date_to, date_from, foreign_currency,
only_posted_moves, show_partner_details, hide_account_at_0, only_posted_moves, show_partner_details, hide_account_at_0,
unaffected_earnings_account, fy_start_date): unaffected_earnings_account, fy_start_date):
accounts_domain = [('company_id', '=', company_id)]
if account_ids:
accounts_domain += [('id', 'in', account_ids)]
accounts = self.env['account.account'].search(accounts_domain)
tb_initial_acc = []
for account in accounts:
tb_initial_acc.append({
'account_id': account.id,
'balance': 0.0,
'amount_currency': 0.0,
})
initial_domain_bs = self._get_initial_balances_bs_ml_domain( initial_domain_bs = self._get_initial_balances_bs_ml_domain(
account_ids, journal_ids, partner_ids, account_ids, journal_ids, partner_ids,
company_id, date_from, only_posted_moves, show_partner_details) company_id, date_from, only_posted_moves, show_partner_details)
@ -183,7 +194,14 @@ class TrialBalanceReport(models.AbstractModel):
'balance', 'balance',
'amount_currency'], 'amount_currency'],
groupby=['account_id']) groupby=['account_id'])
tb_initial_acc = tb_initial_acc_bs + tb_initial_acc_pl
tb_initial_acc_rg = tb_initial_acc_bs + tb_initial_acc_pl
for account_rg in tb_initial_acc_rg:
element = list(filter(
lambda acc_dict: acc_dict['account_id'] == account_rg[
'account_id'][0], tb_initial_acc))
if element:
element[0]['balance'] += account_rg['balance']
element[0]['amount_currency'] += account_rg['amount_currency']
if hide_account_at_0: if hide_account_at_0:
tb_initial_acc = [p for p in tb_initial_acc if p['balance'] != 0] tb_initial_acc = [p for p in tb_initial_acc if p['balance'] != 0]
@ -245,9 +263,9 @@ class TrialBalanceReport(models.AbstractModel):
total_amount[acc_id]['initial_currency_balance'] =\ total_amount[acc_id]['initial_currency_balance'] =\
0.0 0.0
total_amount[acc_id]['ending_currency_balance'] =\ total_amount[acc_id]['ending_currency_balance'] =\
tb['amount_currency']
round(tb['amount_currency'], 2)
for tb in tb_initial_acc: for tb in tb_initial_acc:
acc_id = tb['account_id'][0]
acc_id = tb['account_id']
if acc_id not in total_amount.keys(): if acc_id not in total_amount.keys():
total_amount[acc_id] = {} total_amount[acc_id] = {}
total_amount[acc_id]['credit'] = 0.0 total_amount[acc_id]['credit'] = 0.0
@ -256,18 +274,18 @@ class TrialBalanceReport(models.AbstractModel):
total_amount[acc_id]['initial_balance'] = tb['balance'] total_amount[acc_id]['initial_balance'] = tb['balance']
total_amount[acc_id]['ending_balance'] = tb['balance'] total_amount[acc_id]['ending_balance'] = tb['balance']
if foreign_currency: if foreign_currency:
total_amount[acc_id]['initial_currency_balance'] = tb[
'amount_currency']
total_amount[acc_id]['ending_currency_balance'] = tb[
'amount_currency']
total_amount[acc_id]['initial_currency_balance'] = round(
tb['amount_currency'], 2)
total_amount[acc_id]['ending_currency_balance'] = round(
tb['amount_currency'], 2)
else: else:
total_amount[acc_id]['initial_balance'] = tb['balance'] total_amount[acc_id]['initial_balance'] = tb['balance']
total_amount[acc_id]['ending_balance'] += tb['balance'] total_amount[acc_id]['ending_balance'] += tb['balance']
if foreign_currency: if foreign_currency:
total_amount[acc_id]['initial_currency_balance'] = tb[
'amount_currency']
total_amount[acc_id]['ending_currency_balance'] += tb[
'amount_currency']
total_amount[acc_id]['initial_currency_balance'] = round(
tb['amount_currency'], 2)
total_amount[acc_id]['ending_currency_balance'] += round(
tb['amount_currency'], 2)
if show_partner_details: if show_partner_details:
partners_ids = set() partners_ids = set()
partners_data = {} partners_data = {}
@ -293,7 +311,8 @@ class TrialBalanceReport(models.AbstractModel):
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'initial_currency_balance'] = 0.0 'initial_currency_balance'] = 0.0
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'ending_currency_balance'] = tb['amount_currency']
'ending_currency_balance'] = round(
tb['amount_currency'], 2)
partners_ids.add(tb['partner_id']) partners_ids.add(tb['partner_id'])
for tb in tb_initial_prt: for tb in tb_initial_prt:
acc_id = tb['account_id'][0] acc_id = tb['account_id'][0]
@ -317,11 +336,11 @@ class TrialBalanceReport(models.AbstractModel):
'balance'] 'balance']
if foreign_currency: if foreign_currency:
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'initial_currency_balance'] = tb[
'amount_currency']
'initial_currency_balance'] = round(
tb['amount_currency'], 2)
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'ending_currency_balance'] = tb[
'amount_currency']
'ending_currency_balance'] = round(
tb['amount_currency'], 2)
partners_ids.add(tb['partner_id']) partners_ids.add(tb['partner_id'])
elif prt_id not in total_amount[acc_id].keys(): elif prt_id not in total_amount[acc_id].keys():
total_amount[acc_id][prt_id] = {} total_amount[acc_id][prt_id] = {}
@ -334,11 +353,11 @@ class TrialBalanceReport(models.AbstractModel):
'balance'] 'balance']
if foreign_currency: if foreign_currency:
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'initial_currency_balance'] = tb[
'amount_currency']
'initial_currency_balance'] = round(
tb['amount_currency'], 2)
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'ending_currency_balance'] = tb[
'amount_currency']
'ending_currency_balance'] = round(
tb['amount_currency'], 2)
partners_ids.add(tb['partner_id']) partners_ids.add(tb['partner_id'])
else: else:
total_amount[acc_id][prt_id]['initial_balance'] += \ total_amount[acc_id][prt_id]['initial_balance'] += \
@ -347,11 +366,11 @@ class TrialBalanceReport(models.AbstractModel):
'balance'] 'balance']
if foreign_currency: if foreign_currency:
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'initial_currency_balance'] += tb[
'amount_currency']
'initial_currency_balance'] += round(
tb['amount_currency'], 2)
total_amount[acc_id][prt_id][ total_amount[acc_id][prt_id][
'ending_currency_balance'] += tb[
'amount_currency']
'ending_currency_balance'] += round(
tb['amount_currency'], 2)
accounts_ids = list(total_amount.keys()) accounts_ids = list(total_amount.keys())
unaffected_id = unaffected_earnings_account unaffected_id = unaffected_earnings_account
if unaffected_id not in accounts_ids: if unaffected_id not in accounts_ids:

16
account_financial_report/report/vat_report.py

@ -3,6 +3,7 @@
# 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
import operator
class VATReport(models.AbstractModel): class VATReport(models.AbstractModel):
@ -18,7 +19,8 @@ class VATReport(models.AbstractModel):
'id': tax.id, 'id': tax.id,
'name': tax.name, 'name': tax.name,
'tax_group_id': tax.tax_group_id.id, 'tax_group_id': tax.tax_group_id.id,
'tags_ids': tax.tag_ids.ids
'tags_ids': tax.tag_ids.ids,
'type_tax_use': tax.type_tax_use
} }
}) })
return tax_data return tax_data
@ -41,19 +43,21 @@ class VATReport(models.AbstractModel):
fields=ml_fields, fields=ml_fields,
) )
vat_data = {} vat_data = {}
tax_ids = set()
tax_ids = list(map(operator.itemgetter('tax_line_id'), tax_move_lines))
tax_ids = [i[0] for i in tax_ids]
tax_data = self._get_tax_data(tax_ids)
for tax_move_line in tax_move_lines: for tax_move_line in tax_move_lines:
tax_ml_id = tax_move_line['id'] tax_ml_id = tax_move_line['id']
tax_id = tax_move_line['tax_line_id'][0]
vat_data[tax_ml_id] = {} vat_data[tax_ml_id] = {}
vat_data[tax_ml_id].update({ vat_data[tax_ml_id].update({
'id': tax_ml_id, 'id': tax_ml_id,
'net': tax_move_line['tax_base_amount'], 'net': tax_move_line['tax_base_amount'],
'tax': tax_move_line['balance'] if tax_move_line[
'balance'] > 0 else (-1) * tax_move_line['balance'],
'tax': (-1) * tax_move_line['balance']
if tax_data[tax_id]['type_tax_use'] == 'sale'
else tax_move_line['balance'],
'tax_line_id': tax_move_line['tax_line_id'], 'tax_line_id': tax_move_line['tax_line_id'],
}) })
tax_ids.add(tax_move_line['tax_line_id'][0])
tax_data = self._get_tax_data(tax_ids)
return vat_data, tax_data return vat_data, tax_data
def _get_tax_group_data(self, tax_group_ids): def _get_tax_group_data(self, tax_group_ids):

2
account_financial_report/wizard/aged_partner_balance_wizard.py

@ -21,6 +21,7 @@ class AgedPartnerBalanceWizard(models.TransientModel):
) )
date_at = fields.Date(required=True, date_at = fields.Date(required=True,
default=fields.Date.context_today) default=fields.Date.context_today)
date_from = fields.Date(string='Date From')
target_move = fields.Selection([('posted', 'All Posted Entries'), target_move = fields.Selection([('posted', 'All Posted Entries'),
('all', 'All Entries')], ('all', 'All Entries')],
string='Target Moves', string='Target Moves',
@ -146,6 +147,7 @@ class AgedPartnerBalanceWizard(models.TransientModel):
return { return {
'wizard_id': self.id, 'wizard_id': self.id,
'date_at': self.date_at, 'date_at': self.date_at,
'date_from': self.date_from or False,
'only_posted_moves': self.target_move == 'posted', 'only_posted_moves': self.target_move == 'posted',
'company_id': self.company_id.id, 'company_id': self.company_id.id,
'account_ids': self.account_ids.ids, 'account_ids': self.account_ids.ids,

1
account_financial_report/wizard/aged_partner_balance_wizard_view.xml

@ -13,6 +13,7 @@
<group name="filters"> <group name="filters">
<group name="date_range"> <group name="date_range">
<field name="date_at"/> <field name="date_at"/>
<field name="date_from"/>
</group> </group>
<group name="other_filters"> <group name="other_filters">
<field name="target_move" widget="radio"/> <field name="target_move" widget="radio"/>

5
account_financial_report/wizard/general_ledger_wizard.py

@ -97,6 +97,10 @@ class GeneralLedgerReportWizard(models.TransientModel):
comodel_name='account.account', comodel_name='account.account',
string='Account Code To', string='Account Code To',
help='Ending account in a range') help='Ending account in a range')
show_partner_details = fields.Boolean(
string='Show Partner Details',
default=True,
)
@api.onchange('account_code_from', 'account_code_to') @api.onchange('account_code_from', 'account_code_to')
def on_change_account_range(self): def on_change_account_range(self):
@ -284,6 +288,7 @@ class GeneralLedgerReportWizard(models.TransientModel):
'company_id': self.company_id.id, 'company_id': self.company_id.id,
'account_ids': self.account_ids.ids, 'account_ids': self.account_ids.ids,
'partner_ids': self.partner_ids.ids, 'partner_ids': self.partner_ids.ids,
'show_partner_details': self.show_partner_details,
'cost_center_ids': self.cost_center_ids.ids, 'cost_center_ids': self.cost_center_ids.ids,
'analytic_tag_ids': self.analytic_tag_ids.ids, 'analytic_tag_ids': self.analytic_tag_ids.ids,
'journal_ids': self.account_journal_ids.ids, 'journal_ids': self.account_journal_ids.ids,

30
account_financial_report/wizard/general_ledger_wizard_view.xml

@ -20,31 +20,11 @@
</group> </group>
<group name="other_filters"> <group name="other_filters">
<field name="target_move" widget="radio"/> <field name="target_move" widget="radio"/>
<label string="Other options" for="centralize"/>
<div>
<field name="centralize" nolabel="1" class="oe_inline"/>
<label for="centralize" class="oe_inline"/>
</div>
<label string=" " for="hide_account_at_0"/>
<div>
<field name="hide_account_at_0" nolabel="1" class="oe_inline"/>
<label for="hide_account_at_0" class="oe_inline"/>
</div>
<label string=" " for="foreign_currency"/>
<div>
<field name="foreign_currency" nolabel="1" class="oe_inline"/>
<label for="foreign_currency" class="oe_inline"/>
</div>
<label string=" " for="show_analytic_tags"/>
<div>
<field name="show_analytic_tags" nolabel="1" class="oe_inline"/>
<label for="show_analytic_tags" class="oe_inline"/>
</div>
<label string=" " for="partner_ungrouped"/>
<div>
<field name="partner_ungrouped" nolabel="1" class="oe_inline"/>
<label for="partner_ungrouped" class="oe_inline"/>
</div>
<field name="centralize"/>
<field name="show_partner_details"/>
<field name="hide_account_at_0"/>
<field name="foreign_currency"/>
<field name="show_analytic_tags"/>
</group> </group>
</group> </group>
<notebook> <notebook>

Loading…
Cancel
Save