[FIX] partner_statement: Create own invoice in test
The invoice found by the tests has changed, and it causes a failure in the tests. Create a new invoice so that tests are not depending on records created by others.
This commit is contained in:
committed by
Miquel Raïch
parent
9703003eca
commit
a56ed39b25
@@ -2,8 +2,10 @@
|
|||||||
# Copyright 2025 Simone Rubino - PyTech
|
# Copyright 2025 Simone Rubino - PyTech
|
||||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
from odoo.tests.common import TransactionCase, new_test_user
|
from odoo.tests.common import Form, TransactionCase, new_test_user
|
||||||
|
|
||||||
|
|
||||||
class TestOutstandingStatement(TransactionCase):
|
class TestOutstandingStatement(TransactionCase):
|
||||||
@@ -94,6 +96,20 @@ class TestOutstandingStatement(TransactionCase):
|
|||||||
"bucket_labels", report, "There was an error while compiling the report."
|
"bucket_labels", report, "There was an error while compiling the report."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def init_invoice(self, move_type, partner, invoice_date=None, post=True):
|
||||||
|
move_form = Form(
|
||||||
|
self.env["account.move"].with_context(default_move_type=move_type)
|
||||||
|
)
|
||||||
|
move_form.partner_id = partner
|
||||||
|
move_form.invoice_date = invoice_date or fields.Date.from_string("2019-01-01")
|
||||||
|
with move_form.invoice_line_ids.new() as line:
|
||||||
|
line.name = "Test line"
|
||||||
|
line.price_unit = 100
|
||||||
|
move = move_form.save()
|
||||||
|
if post:
|
||||||
|
move.action_post()
|
||||||
|
return move
|
||||||
|
|
||||||
def test_exclude_accounts(self):
|
def test_exclude_accounts(self):
|
||||||
"""Accounts can be excluded with a code selector."""
|
"""Accounts can be excluded with a code selector."""
|
||||||
# Arrange
|
# Arrange
|
||||||
@@ -105,13 +121,8 @@ class TestOutstandingStatement(TransactionCase):
|
|||||||
# Edit one invoice
|
# Edit one invoice
|
||||||
# including a new account
|
# including a new account
|
||||||
# that will be the only one not excluded
|
# that will be the only one not excluded
|
||||||
partner_invoice = self.env["account.move"].search(
|
partner_invoice = self.init_invoice("out_invoice", partners[0])
|
||||||
[
|
|
||||||
("partner_id", "in", partners.ids),
|
|
||||||
("state", "=", "posted"),
|
|
||||||
],
|
|
||||||
limit=1,
|
|
||||||
)
|
|
||||||
account = partner_invoice.line_ids.account_id.filtered(
|
account = partner_invoice.line_ids.account_id.filtered(
|
||||||
lambda a: a.account_type == wizard.account_type
|
lambda a: a.account_type == wizard.account_type
|
||||||
)
|
)
|
||||||
@@ -157,22 +168,13 @@ class TestOutstandingStatement(TransactionCase):
|
|||||||
# Arrange
|
# Arrange
|
||||||
partner = self.partner1
|
partner = self.partner1
|
||||||
today = fields.Date.today()
|
today = fields.Date.today()
|
||||||
overdue_invoice = self.env["account.move"].search(
|
overdue_invoice = self.init_invoice(
|
||||||
[
|
"out_invoice", partner, invoice_date=today - relativedelta(months=1)
|
||||||
("partner_id", "=", partner.id),
|
|
||||||
("state", "=", "posted"),
|
|
||||||
("invoice_date_due", "<", today),
|
|
||||||
],
|
|
||||||
limit=1,
|
|
||||||
)
|
)
|
||||||
due_invoice = self.env["account.move"].search(
|
due_invoice = self.init_invoice(
|
||||||
[
|
"out_invoice", partner, invoice_date=today + relativedelta(months=1)
|
||||||
("partner_id", "=", partner.id),
|
|
||||||
("state", "=", "posted"),
|
|
||||||
("invoice_date_due", ">=", today),
|
|
||||||
],
|
|
||||||
limit=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
wizard = self.wiz.with_context(
|
wizard = self.wiz.with_context(
|
||||||
active_ids=partner.ids,
|
active_ids=partner.ids,
|
||||||
).create(
|
).create(
|
||||||
|
|||||||
Reference in New Issue
Block a user