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

backport from  #603
  • Loading branch information
maq-adhoc committed Jan 3, 2025
1 parent 9b81090 commit 1a96782
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
42 changes: 28 additions & 14 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,19 @@ 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
balance_in_currency_name = ''
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 @@ -67,29 +73,30 @@ def get_line_vals(

if from_date:
initial_domain = domain + [('date', '<', from_date)]
inicial_lines = self.env['account.move.line'].sudo().read_group(
initial_domain, fields=['balance'], groupby=['partner_id'])
inicial_lines = self.env['account.move.line'].sudo()._read_group(
initial_domain, groupby=['partner_id'], fields=['balance:sum'])
balance = inicial_lines[0]['balance'] if inicial_lines else 0.0
res = [get_line_vals(name=_('INITIAL BALANCE'), balance=balance)]
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'], fields=['amount_currency:sum', 'currency_id:array_agg'])
balance_in_currency = inicial_lines_currency[0][1] if inicial_lines_currency else 0.0
balance_in_currency_name = self.env['res.currency'].browse(inicial_lines_currency[0][2][0]).display_name if inicial_lines_currency and inicial_lines_currency[0][2][0] else ''

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 @@ -116,7 +123,6 @@ 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({
Expand All @@ -134,6 +140,8 @@ def get_line_vals(
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 @@ -144,9 +152,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
Binary file modified account_debt_report/report/account_debt_report.ods
Binary file not shown.
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" attrs="{'invisible': [('historical_full', '=', False)]}"/>
<field name="to_date" string="Detallar hasta" attrs="{'invisible': [('historical_full', '=', False)]}"/>
<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 1a96782

Please sign in to comment.