From 7232b48d23f4f8ef2afb717f56a166c8cdbdee6f Mon Sep 17 00:00:00 2001 From: Ignacio Cainelli Date: Mon, 27 Nov 2023 16:53:39 -0300 Subject: [PATCH] [REF] account_debt_report: make method inheritable method _get_domain_report in _get_debt_report_lines --- account_debt_report/models/res_partner.py | 53 +++++++++++++---------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/account_debt_report/models/res_partner.py b/account_debt_report/models/res_partner.py index 98883206e..17cf46ff9 100644 --- a/account_debt_report/models/res_partner.py +++ b/account_debt_report/models/res_partner.py @@ -10,6 +10,35 @@ class ResPartner(models.Model): _inherit = 'res.partner' + def _get_domain_report(self, result_selection, from_date, to_date, + historical_full, company_id): + + domain = [] + + if company_id: + domain += [('company_id', '=', company_id)] + else: + domain += [('company_id', 'in', self.env.companies.ids)] + + if not historical_full: + domain += [('reconciled', '=', False), ('full_reconcile_id', '=', False)] + + if result_selection == 'receivable': + domain += [('account_internal_type', '=', 'receivable')] + elif result_selection == 'payable': + domain += [('account_internal_type', '=', 'payable')] + else: + domain += [('account_internal_type', 'in', ['receivable', 'payable'])] + + domain += [('partner_id', '=', self.id), ('parent_state', '=', 'posted')] + + if from_date: + domain.append(('date', '>=', from_date)) + + if to_date: + domain.append(('date', '<=', to_date)) + return domain + def _get_debt_report_lines(self): # TODO ver si borramos este metodo que no tiene mucho sentido (get_line_vals) def get_line_vals( @@ -41,46 +70,26 @@ def get_line_vals( company_id = self._context.get('company_id', False) show_invoice_detail = self._context.get('show_invoice_detail', False) - domain = [] - - if company_id: - domain += [('company_id', '=', company_id)] - else: - domain += [('company_id', 'in', self.env.companies.ids)] + domain = self._get_domain_report(result_selection, from_date, to_date, historical_full, company_id) if not historical_full: - domain += [('reconciled', '=', False), ('full_reconcile_id', '=', False)] # si pide historial completo entonces mostramos los movimientos # si no mostramos los saldos balance_field = 'amount_residual' else: balance_field = 'balance' - if result_selection == 'receivable': - domain += [('account_internal_type', '=', 'receivable')] - elif result_selection == 'payable': - domain += [('account_internal_type', '=', 'payable')] - else: - domain += [('account_internal_type', 'in', ['receivable', 'payable'])] - - domain += [('partner_id', '=', self.id), ('parent_state', '=', 'posted')] - 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']) balance = inicial_lines[0]['balance'] if inicial_lines else 0.0 res = [get_line_vals(name=_('INITIAL BALANCE'), balance=balance)] - 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')