Skip to content

Commit

Permalink
[IMP] *: pre-commit automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cav-adhoc committed Jan 29, 2025
1 parent 75bedc2 commit 77cdbf9
Show file tree
Hide file tree
Showing 49 changed files with 1,137 additions and 992 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

exclude: |
(?x)
# We don't want to mess with tool-generated files
.svg$|/tests/([^/]+/)?cassettes/|^.copier-answers.yml$|^.github/|^eslint.config.cjs|^prettier.config.cjs|
# Library files can have extraneous formatting (even minimized)
Expand Down
38 changes: 18 additions & 20 deletions account_debt_report/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,24 @@
#
##############################################################################
{
'name': 'Account Debt Report',
'version': "18.0.2.0.0",
'category': 'Account Reporting',
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'depends': [
'account',
'report_aeroo',
"name": "Account Debt Report",
"version": "18.0.2.0.0",
"category": "Account Reporting",
"author": "ADHOC SA",
"website": "www.adhoc.com.ar",
"license": "AGPL-3",
"depends": [
"account",
"report_aeroo",
],
'data': [
'report/account_debt_report.xml',
'data/mail_template_data.xml',
'security/ir.model.access.csv',
'wizard/account_debt_report_wizard_view.xml',
'views/account_move_line.xml',
"data": [
"report/account_debt_report.xml",
"data/mail_template_data.xml",
"security/ir.model.access.csv",
"wizard/account_debt_report_wizard_view.xml",
"views/account_move_line.xml",
],
'demo': [
],
'test': [
],
'installable': True,
"demo": [],
"test": [],
"installable": True,
}
199 changes: 120 additions & 79 deletions account_debt_report/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,109 +2,140 @@
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import models, _
from odoo.tools.safe_eval import safe_eval
from odoo import _, models

# from odoo.exceptions import ValidationError


class ResPartner(models.Model):
_inherit = 'res.partner'
_inherit = "res.partner"

def action_open_debt_report_wizard(self):

return {
'type': 'ir.actions.act_window',
'res_model': 'account.debt.report.wizard',
'view_mode': 'form',
'view_id': self.env.ref('account_debt_report.account_debt_report_wizard_form').id,
'target': 'new',
'context': {
'partner_id': self.id,
"type": "ir.actions.act_window",
"res_model": "account.debt.report.wizard",
"view_mode": "form",
"view_id": self.env.ref("account_debt_report.account_debt_report_wizard_form").id,
"target": "new",
"context": {
"partner_id": self.id,
},
}

def _get_debt_report_lines(self):
# TODO ver si borramos este metodo que no tiene mucho sentido (get_line_vals)
def get_line_vals(
date=None, name=None, detail_lines=None, date_maturity=None,
amount=None, amount_residual=None, balance=None,
amount_currency=None,
currency_name=None, move_line=None):
date=None,
name=None,
detail_lines=None,
date_maturity=None,
amount=None,
amount_residual=None,
balance=None,
amount_currency=None,
currency_name=None,
move_line=None,
):
if not detail_lines:
detail_lines = []
return {
'date': date,
'name': name,
'detail_lines': detail_lines,
'date_maturity': date_maturity,
'amount': amount,
'amount_residual': amount_residual,
'balance': balance,
'amount_currency': amount_currency,
'currency_name': currency_name,
'move_line': move_line,
"date": date,
"name": name,
"detail_lines": detail_lines,
"date_maturity": date_maturity,
"amount": amount,
"amount_residual": amount_residual,
"balance": balance,
"amount_currency": amount_currency,
"currency_name": currency_name,
"move_line": move_line,
}

self.ensure_one()

result_selection = self._context.get('result_selection', False)
from_date = self._context.get('from_date', False)
to_date = self._context.get('to_date', False)
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')
result_selection = self._context.get("result_selection", False)
from_date = self._context.get("from_date", False)
to_date = self._context.get("to_date", False)
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 = ''
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
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')
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)]
domain += [("currency_id", "not in", company_currency_ids.ids)]

if not historical_full:
domain += [('reconciled', '=', False), ('full_reconcile_id', '=', False)]
domain += [("reconciled", "=", False), ("full_reconcile_id", "=", False)]
# si pide historial completo entonces mostramos los movimientos
# si no mostramos los saldos
balance_field = 'amount_residual'
balance_field = "amount_residual"
else:
balance_field = 'balance'
balance_field = "balance"

if result_selection == 'receivable':
domain += [('account_type', '=', 'asset_receivable')]
elif result_selection == 'payable':
domain += [('account_type', '=', 'liability_payable')]
if result_selection == "receivable":
domain += [("account_type", "=", "asset_receivable")]
elif result_selection == "payable":
domain += [("account_type", "=", "liability_payable")]
else:
domain += [('account_type', 'in', ['asset_receivable', 'liability_payable'])]
domain += [("account_type", "in", ["asset_receivable", "liability_payable"])]

domain += [('partner_id', '=', self.id), ('parent_state', '=', 'posted')]
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, groupby=['partner_id'], aggregates=['balance:sum'])
initial_domain = domain + [("date", "<", from_date)]
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', 'currency_id:array_agg'])
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", "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, currency_name=balance_in_currency_name)]
domain.append(('date', '>=', from_date))
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,
currency_name=balance_in_currency_name,
)
]
domain.append(("date", ">=", from_date))
else:
balance = 0.0
res = []

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

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

# construimos una nueva lista con los valores que queremos y de
# manera mas facil
Expand All @@ -115,15 +146,17 @@ def get_line_vals(
inv_line_name = inv_line.name or "Sin descripción"
inv_line_product_uom_id_name = inv_line.product_uom_id.name or "Sin unidad de medida"
detail_lines.append(
("* %s x %s %s" % (
inv_line_name.replace(
'\n', ' ').replace('\r', ''),
"* %s x %s %s"
% (
inv_line_name.replace("\n", " ").replace("\r", ""),
inv_line.quantity,
inv_line_product_uom_id_name)))
inv_line_product_uom_id_name,
)
)
name = record.move_id.name
# similar to _format_aml_name
if record.ref and record.ref != '/':
name += ' - ' + record.ref
if record.ref and record.ref != "/":
name += " - " + record.ref

date_maturity = record.date_maturity
date = record.date
Expand All @@ -134,26 +167,34 @@ def get_line_vals(
amount_currency = record.amount_currency
show_currency = record.currency_id != record.company_id.currency_id
if record.payment_id:
name += ' - ' + record.journal_id.name
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(
date=date,
name=name,
detail_lines=detail_lines,
date_maturity=date_maturity,
amount=amount,
amount_residual=amount_residual,
balance=balance,
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.append(
get_line_vals(
date=date,
name=name,
detail_lines=detail_lines,
date_maturity=date_maturity,
amount=amount,
amount_residual=amount_residual,
balance=balance,
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)]
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
33 changes: 14 additions & 19 deletions account_debt_report/tests/test_account_debt_report.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
from odoo.tests.common import TransactionCase

class TestAccountDebtReport(TransactionCase):

class TestAccountDebtReport(TransactionCase):
def setUp(self):
super(TestAccountDebtReport, self).setUp()
# Set up test data, e.g., a partner and invoices
self.partner = self.env['res.partner'].create({
'name': 'Test Partner',
'email': '[email protected]'
})
self.partner = self.env["res.partner"].create({"name": "Test Partner", "email": "[email protected]"})

def test_debt_report_lines(self):
# Execute the method and validate output
Expand All @@ -17,26 +14,24 @@ def test_debt_report_lines(self):
self.assertIsInstance(report_lines, list, "Expected a list of report lines")
if report_lines:
first_line = report_lines[0]
self.assertIn('date', first_line, "Report line should contain 'date'")
self.assertIn('name', first_line, "Report line should contain 'name'")
self.assertIn('balance', first_line, "Report line should contain 'balance'")
self.assertIn("date", first_line, "Report line should contain 'date'")
self.assertIn("name", first_line, "Report line should contain 'name'")
self.assertIn("balance", first_line, "Report line should contain 'balance'")


class TestAccountDebtReportWizard(TransactionCase):

def setUp(self):
super(TestAccountDebtReportWizard, self).setUp()
# Crear un partner de prueba
self.partner = self.env['res.partner'].create({
'name': 'Test Partner',
'email': '[email protected]'
})
self.partner = self.env["res.partner"].create({"name": "Test Partner", "email": "[email protected]"})
# Crear el wizard para el reporte de deuda
self.wizard = self.env['account.debt.report.wizard'].create({
'company_id': self.env.company.id,
'result_selection': 'all',
'historical_full': True,
})
self.wizard = self.env["account.debt.report.wizard"].create(
{
"company_id": self.env.company.id,
"result_selection": "all",
"historical_full": True,
}
)

def test_confirm_method(self):
# Verificar que el método confirm se ejecuta correctamente
Expand All @@ -47,4 +42,4 @@ def test_send_by_email_method(self):
# Verificar que el método send_by_email se ejecuta correctamente
action = self.wizard.with_context(active_id=self.partner.id).send_by_email()
self.assertTrue(action, "El método send_by_email debería retornar una acción de ventana")
self.assertEqual(action['res_model'], 'mail.compose.message', "El modelo debería ser 'mail.compose.message'")
self.assertEqual(action["res_model"], "mail.compose.message", "El modelo debería ser 'mail.compose.message'")
Loading

0 comments on commit 77cdbf9

Please sign in to comment.