From 66789d32d63b537e92038ea8e206dff0e583c479 Mon Sep 17 00:00:00 2001 From: Martin Quinteros Date: Mon, 9 Dec 2024 15:45:45 -0300 Subject: [PATCH] [IMP] account_debt_report: Company currency is optional in report - Donts show Monto Diviza on cmpany currency lines - clean Pyment group compatiblitiy code --- account_debt_report/models/res_partner.py | 43 ++++++------------- .../wizard/account_debt_report_wizard.py | 5 +++ .../account_debt_report_wizard_view.xml | 1 + 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/account_debt_report/models/res_partner.py b/account_debt_report/models/res_partner.py index 80f06b484..fb40319d5 100644 --- a/account_debt_report/models/res_partner.py +++ b/account_debt_report/models/res_partner.py @@ -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 @@ -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') domain = [] if company_id: domain += [('company_id', '=', company_id)] + if only_currency_lines: + domain += [('currency_id', '!=', self.env['res.company'].browse(company_id).currency_id.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)] @@ -78,19 +83,11 @@ def get_line_vals( 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: @@ -117,24 +114,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( @@ -145,8 +126,8 @@ 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, )) res += final_line diff --git a/account_debt_report/wizard/account_debt_report_wizard.py b/account_debt_report/wizard/account_debt_report_wizard.py index be6552339..1c5684a60 100644 --- a/account_debt_report/wizard/account_debt_report_wizard.py +++ b/account_debt_report/wizard/account_debt_report_wizard.py @@ -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( + defaul=True, + help='Add columns for company currency?' + ) secondary_currency = fields.Boolean( help='Add columns for secondary currency?') @@ -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, diff --git a/account_debt_report/wizard/account_debt_report_wizard_view.xml b/account_debt_report/wizard/account_debt_report_wizard_view.xml index fc5d6b69a..8d33d94c4 100644 --- a/account_debt_report/wizard/account_debt_report_wizard_view.xml +++ b/account_debt_report/wizard/account_debt_report_wizard_view.xml @@ -14,6 +14,7 @@ +