Skip to content

Commit

Permalink
[IMP] account_debt_report: Company currency is optional in report
Browse files Browse the repository at this point in the history
- Donts show Monto Diviza on cmpany currency lines
- clean Pyment group compatiblitiy code
  • Loading branch information
maq-adhoc committed Dec 16, 2024
1 parent 69f6c55 commit bd05ccd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
55 changes: 23 additions & 32 deletions account_debt_report/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import api, models, fields, _
from odoo import models, _
from odoo.tools.safe_eval import safe_eval
# from odoo.exceptions import ValidationError

Expand Down Expand Up @@ -40,13 +40,18 @@ def get_line_vals(
historical_full = self._context.get('historical_full', False)
company_id = self._context.get('company_id', False)
show_invoice_detail = self._context.get('show_invoice_detail', False)

only_currency_lines = not self._context.get('company_currency') and self._context.get('secondary_currency')
balance_in_currency = 0.0
domain = []

if company_id:
domain += [('company_id', '=', company_id)]
company_currency_ids = self.env['res.company'].browse(company_id).currency_id
else:
domain += [('company_id', 'in', self.env.companies.ids)]
company_currency_ids = self.env.companies.mapped('currency_id')
if only_currency_lines and len(company_currency_ids) == 1:
domain += [('currency_id', 'not in', company_currency_ids.ids)]

if not historical_full:
domain += [('reconciled', '=', False), ('full_reconcile_id', '=', False)]
Expand All @@ -70,27 +75,23 @@ def get_line_vals(
inicial_lines = self.env['account.move.line'].sudo()._read_group(
initial_domain, groupby=['partner_id'], aggregates=['balance:sum'])
balance = inicial_lines[0][1] if inicial_lines else 0.0
if len(company_currency_ids) == 1:
inicial_lines_currency = self.env['account.move.line'].sudo()._read_group(
initial_domain + [('currency_id', 'not in', company_currency_ids.ids)], groupby=['partner_id'], aggregates=['amount_currency:sum'])
balance_in_currency = inicial_lines_currency[0][1] if inicial_lines_currency else 0.0

res = [get_line_vals(name=_('INITIAL BALANCE'), balance=balance)]
res = [get_line_vals(name=_('INITIAL BALANCE'), balance=balance, amount_currency=balance_in_currency)]
domain.append(('date', '>=', from_date))
else:
balance = 0.0
res = []

if to_date:
final_line = []
domain.append(('date', '<=', to_date))
else:
final_line = []
final_line = []

records = self.env['account.move.line'].sudo().search(domain, order='date asc, name, move_id desc, date_maturity asc, id')

grouped = self.env['account.payment']._fields.get('payment_group_id') and safe_eval(
self.env['ir.config_parameter'].sudo().get_param(
'account_debt_report.group_payment_group_payments', 'False'))

last_payment_group_id = False

# construimos una nueva lista con los valores que queremos y de
# manera mas facil
for record in records:
Expand All @@ -117,24 +118,8 @@ def get_line_vals(
amount = record.balance
amount_residual = record.amount_residual
amount_currency = record.amount_currency

if grouped and record.payment_id and record.payment_id.payment_group_id == last_payment_group_id:
# si agrupamos pagos y el grupo de pagos coincide con el último, entonces acumulamos en linea anterior
res[-1].update({
'amount': res[-1]['amount'] + record.balance,
'amount_residual': res[-1]['amount_residual'] + record.amount_residual,
'amount_currency': res[-1]['amount_currency'] + record.amount_currency,
'balance': balance,
})
continue
elif grouped and record.payment_id and record.payment_id.payment_group_id != last_payment_group_id:
# si es un payment pero no es del payment group anterior, seteamos este como ultimo payment group
last_payment_group_id = record.payment_id.payment_group_id
elif not grouped and record.payment_id:
# si no agrupamos y es pago, agregamos nombre de diario para que sea mas claro
name += ' - ' + record.journal_id.name
elif not record.payment_id:
last_payment_group_id = False
show_currency = record.currency_id != record.company_id.currency_id
name += ' - ' + record.journal_id.name

# TODO tal vez la suma podriamos probar hacerla en el xls como hacemos en libro iva v11/v12
res.append(get_line_vals(
Expand All @@ -145,9 +130,15 @@ def get_line_vals(
amount=amount,
amount_residual=amount_residual,
balance=balance,
amount_currency=amount_currency,
currency_name=currency.name,
amount_currency=amount_currency if show_currency else False,
currency_name=currency.name if show_currency else False,
# move_line=record.move_line_id,
))

record_currencys = records.filtered(lambda x: x.currency_id != x.company_id.currency_id)
if len(record_currencys.mapped('currency_id')) == 1:
total_currency = sum(record_currencys.mapped('amount_currency')) + balance_in_currency
final_line += [get_line_vals(name=_('Total'), amount_currency=total_currency, currency_name=record_currencys.mapped('currency_id').name)]

res += final_line
return res
5 changes: 5 additions & 0 deletions account_debt_report/wizard/account_debt_report_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ def _default_result_selection(self):
historical_full = fields.Boolean(
help='If true, then it will show all partner history. If not, only '
'unreconciled items will be shown.')
company_currency = fields.Boolean(
default=True,
help='Add columns for company currency?'
)
secondary_currency = fields.Boolean(
help='Add columns for secondary currency?')

Expand All @@ -55,6 +59,7 @@ def confirm(self):
return self.env['ir.actions.report'].search(
[('report_name', '=', 'account_debt_report')],
limit=1).with_context(
company_currency=self.company_currency,
secondary_currency=self.secondary_currency,
result_selection=self.result_selection,
company_id=self.company_id.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<field name="historical_full"/>
<field name="from_date" string="Detallar desde" invisible="not historical_full"/>
<field name="to_date" string="Detallar hasta" invisible="not historical_full"/>
<field name="company_currency"/>
<field name="secondary_currency"/>
<field name="show_invoice_detail"/>
<!-- <field name="show_receipt_detail" attrs="{'invisible': [('group_by_move', '=', False)]}"/> -->
Expand Down

0 comments on commit bd05ccd

Please sign in to comment.