forked from OCA/credit-control
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] account_invoice_overdue_warn: filter by delay lines
- Loading branch information
1 parent
edf1a0c
commit c9cb8ba
Showing
3 changed files
with
297 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import test_overdue_warn | ||
from . import test_overdue_warn_portion |
258 changes: 258 additions & 0 deletions
258
account_invoice_overdue_warn/tests/test_overdue_warn_portion.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
# Copyright 2024 Engenere.one | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from datetime import datetime, timedelta | ||
|
||
from odoo.tests import Form, tagged | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
@tagged("post_install", "-at_install") | ||
class TestOverdueWarn(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.company = self.env.ref("base.main_company") | ||
self.partner = self.env["res.partner"].create( | ||
{ | ||
"name": "Teste Partner", | ||
"country_id": self.env.ref("base.br").id, | ||
"company_id": self.company.id, | ||
} | ||
) | ||
self.today = datetime.now().date() | ||
self.revenue_acc = self.env["account.account"].search( | ||
[ | ||
("company_id", "=", self.company.id), | ||
( | ||
"user_type_id", | ||
"=", | ||
self.env.ref("account.data_account_type_revenue").id, | ||
), | ||
], | ||
limit=1, | ||
) | ||
|
||
def test_late_draft_invoice(self): | ||
out_invoice_sketch = self.env["account.move"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"move_type": "out_invoice", | ||
"company_id": self.company.id, | ||
"currency_id": self.company.currency_id.id, | ||
"invoice_date": self.today - timedelta(days=5), | ||
"invoice_date_due": self.today - timedelta(days=5), | ||
"invoice_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "test line", | ||
"price_unit": 500, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
self.assertEqual(out_invoice_sketch.state, "draft") | ||
self.assertEqual(self.partner.overdue_invoice_count, 0) | ||
self.assertEqual(self.partner.overdue_invoice_amount, 0.0) | ||
|
||
def test_confirmed_supplier_invoice(self): | ||
out_invoice_supplier = self.env["account.move"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"move_type": "in_invoice", | ||
"company_id": self.company.id, | ||
"currency_id": self.company.currency_id.id, | ||
"invoice_date": self.today - timedelta(days=5), | ||
"invoice_date_due": self.today - timedelta(days=5), | ||
"invoice_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "test line", | ||
"price_unit": 500, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
out_invoice_supplier.action_post() | ||
self.assertEqual(self.partner.overdue_invoice_count, 0) | ||
self.assertEqual(self.partner.overdue_invoice_amount, 0.0) | ||
|
||
def test_mixed_case_with_two_invoices(self): | ||
|
||
out_invoice_a = self.env["account.move"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"move_type": "out_invoice", | ||
"company_id": self.company.id, | ||
"currency_id": self.company.currency_id.id, | ||
"invoice_date": self.today - timedelta(days=10), | ||
"invoice_date_due": self.today - timedelta(days=10), | ||
"invoice_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Portion 1", | ||
"price_unit": 300, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
"date_maturity": self.today - timedelta(days=9), | ||
}, | ||
), | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Portion 2", | ||
"price_unit": 300, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
"date_maturity": self.today - timedelta(days=9), | ||
}, | ||
), | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Portion 3", | ||
"price_unit": 300, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
"date_maturity": self.today - timedelta(days=9), | ||
}, | ||
), | ||
], | ||
} | ||
) | ||
out_invoice_a.action_post() | ||
|
||
out_invoice_b = self.env["account.move"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"move_type": "out_invoice", | ||
"company_id": self.company.id, | ||
"currency_id": self.company.currency_id.id, | ||
"invoice_date": self.today - timedelta(days=10), | ||
"invoice_date_due": self.today - timedelta(days=10), | ||
"invoice_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Portion 1", | ||
"price_unit": 300, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
"date_maturity": self.today - timedelta(days=9), | ||
}, | ||
), | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Portion 2", | ||
"price_unit": 300, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
"date_maturity": self.today - timedelta(days=9), | ||
}, | ||
), | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "Portion 3", | ||
"price_unit": 300, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
"date_maturity": self.today + timedelta(days=20), | ||
}, | ||
), | ||
], | ||
} | ||
) | ||
out_invoice_b.action_post() | ||
|
||
action_data_a = out_invoice_a.action_register_payment() | ||
wizard_a = Form( | ||
self.env["account.payment.register"].with_context(action_data_a["context"]) | ||
).save() | ||
wizard_a.amount = 450.0 | ||
wizard_a.action_create_payments() | ||
|
||
action_data_b = out_invoice_a.action_register_payment() | ||
wizard_b = Form( | ||
self.env["account.payment.register"].with_context(action_data_b["context"]) | ||
).save() | ||
wizard_b.amount = 0 | ||
wizard_b.action_create_payments() | ||
|
||
self.assertEqual(self.partner.overdue_invoice_count, 2) | ||
self.assertEqual(self.partner.overdue_invoice_amount, 1050.0) | ||
|
||
def test_confirmed_invoice_with_past_date(self): | ||
out_invoice_past_paid = self.env["account.move"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"move_type": "out_invoice", | ||
"company_id": self.company.id, | ||
"currency_id": self.company.currency_id.id, | ||
"invoice_date": self.today - timedelta(days=5), | ||
"invoice_date_due": self.today - timedelta(days=5), | ||
"invoice_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "test line", | ||
"price_unit": 500.0, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
out_invoice_past_paid.action_post() | ||
action_data = out_invoice_past_paid.action_register_payment() | ||
wizard = Form( | ||
self.env["account.payment.register"].with_context(action_data["context"]) | ||
).save() | ||
wizard.action_create_payments() | ||
self.assertEqual(self.partner.overdue_invoice_count, 0) | ||
self.assertEqual(self.partner.overdue_invoice_amount, 0) | ||
|
||
def test_confirmed_invoice_with_future_date_unpaid(self): | ||
out_invoice_future = self.env["account.move"].create( | ||
{ | ||
"partner_id": self.partner.id, | ||
"move_type": "out_invoice", | ||
"company_id": self.company.id, | ||
"currency_id": self.company.currency_id.id, | ||
"invoice_date": self.today + timedelta(days=5), | ||
"invoice_date_due": self.today + timedelta(days=10), | ||
"invoice_line_ids": [ | ||
( | ||
0, | ||
0, | ||
{ | ||
"name": "test line", | ||
"price_unit": 500, | ||
"quantity": 1, | ||
"account_id": self.revenue_acc.id, | ||
}, | ||
) | ||
], | ||
} | ||
) | ||
out_invoice_future.action_post() | ||
self.assertEqual(self.partner.overdue_invoice_count, 0) | ||
self.assertEqual(self.partner.overdue_invoice_amount, 0) |