Skip to content

Commit

Permalink
[MIG] sale_invoice_blocking: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rven committed Feb 4, 2025
1 parent 2d7676f commit ab597fa
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sale_invoice_blocking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Sale Invoice Blocking",
"summary": "Allow you to block the creation of invoices from a sale order.",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"author": "Camptocamp, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sale-workflow",
"category": "Sales",
Expand Down
1 change: 1 addition & 0 deletions sale_invoice_blocking/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_sale_invoice_blocking
86 changes: 86 additions & 0 deletions sale_invoice_blocking/tests/test_sale_invoice_blocking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
from psycopg2.errors import UniqueViolation

from odoo.exceptions import UserError
from odoo.tests.common import TransactionCase, mute_logger


class TestSaleInvoiceBlocking(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.sale_order_model = cls.env["sale.order"]
cls.sale_order_line_model = cls.env["sale.order.line"]

# Data
product_ctg = cls._create_product_category()
cls.service_1 = cls._create_product("test_product1", product_ctg)
cls.service_2 = cls._create_product("test_product2", product_ctg)
cls.customer = cls._create_customer("Test Customer")

@classmethod
def _create_customer(cls, name):
"""Create a Partner."""
return cls.env["res.partner"].create(
{"name": name, "email": "[email protected]", "phone": 123456}
)

@classmethod
def _create_product_category(cls):
product_ctg = cls.env["product.category"].create({"name": "test_product_ctg"})
return product_ctg

@classmethod
def _create_product(cls, name, product_ctg):
product = cls.env["product.product"].create(
{
"name": name,
"categ_id": product_ctg.id,
"type": "service",
"invoice_policy": "order",
}
)
return product

@mute_logger("odoo.sql_db")
def test_duplicate_reason(self):
self.env["invoice.blocking.reason"].create({"name": "Test Reason"})
with self.assertRaises(UniqueViolation):
self.env["invoice.blocking.reason"].create({"name": "Test Reason"})

def test_sales_order_invoicing(self):
so = self.sale_order_model.create({"partner_id": self.customer.id})
sol1 = self.sale_order_line_model.create(
{"product_id": self.service_1.id, "product_uom_qty": 1, "order_id": so.id}
)
sol2 = self.sale_order_line_model.create(
{"product_id": self.service_2.id, "product_uom_qty": 2, "order_id": so.id}
)

# confirm quotation
so.action_confirm()
# update quantities delivered
sol1.qty_delivered = 1
sol2.qty_delivered = 2

self.assertEqual(
so.invoice_status, "to invoice", "The invoice status should be To Invoice"
)

so.invoice_blocking_reason_id = self.env["invoice.blocking.reason"].create(
{"name": "Test Reason"}
)

self.assertEqual(
so.invoice_status, "no", "The invoice status should be Nothing to Invoice"
)

with self.assertRaisesRegex(
UserError, "Cannot create an invoice. No items are available to invoice"
):
so._create_invoices()

so.invoice_blocking_reason_id = False
self.assertEqual(
so.invoice_status, "to invoice", "The invoice status should be To Invoice"
)
so._create_invoices()

0 comments on commit ab597fa

Please sign in to comment.