Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
5
sale_product_identification/tests/__init__.py
Executable file
5
sale_product_identification/tests/__init__.py
Executable file
@@ -0,0 +1,5 @@
|
||||
# Copyright 2025 Binhex <https://www.binhex.cloud>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import sale_product_identification_common
|
||||
from . import test_sale_product_identification
|
||||
133
sale_product_identification/tests/sale_product_identification_common.py
Executable file
133
sale_product_identification/tests/sale_product_identification_common.py
Executable file
@@ -0,0 +1,133 @@
|
||||
# Copyright 2017 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import Command
|
||||
|
||||
from odoo.addons.base.tests.common import BaseCommon
|
||||
|
||||
|
||||
class TestSaleOrderIdentificationCommon(BaseCommon):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
ResPartnerIdCategory = cls.env["res.partner.id_category"]
|
||||
SaleOrder = cls.env["sale.order"]
|
||||
ProductTemplate = cls.env["product.template"]
|
||||
ResPartner = cls.env["res.partner"]
|
||||
cls.category_corrosive = ResPartnerIdCategory.create(
|
||||
{"code": "id_corrosive", "name": "Corrosive"}
|
||||
)
|
||||
cls.category_bilogical = ResPartnerIdCategory.create(
|
||||
{"code": "id_bilogical", "name": "Bilogical"}
|
||||
)
|
||||
cls.category_explosive = ResPartnerIdCategory.create(
|
||||
{"code": "id_explosive", "name": "Explosive"}
|
||||
)
|
||||
|
||||
cls.partner_id = ResPartner.create(
|
||||
{
|
||||
"name": "Partner Test",
|
||||
"id_numbers": [
|
||||
Command.create(
|
||||
{
|
||||
"name": "Bad ID",
|
||||
"category_id": cls.category_corrosive.id,
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.product_tmpl_with_iden = ProductTemplate.create(
|
||||
{
|
||||
"name": "Product Test Iden",
|
||||
"required_identification": True,
|
||||
"product_tmpl_category_ids": [
|
||||
Command.create(
|
||||
{
|
||||
"category_id": cls.category_corrosive.id,
|
||||
"is_mandatory": True,
|
||||
}
|
||||
),
|
||||
Command.create(
|
||||
{
|
||||
"category_id": cls.category_bilogical.id,
|
||||
"is_mandatory": True,
|
||||
}
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.product_with_iden = cls.product_tmpl_with_iden.product_variant_ids[:1]
|
||||
cls.product_tmpl_with_iden_opt = ProductTemplate.create(
|
||||
{
|
||||
"name": "Product Test optional",
|
||||
"required_identification": True,
|
||||
"product_tmpl_category_ids": [
|
||||
Command.create(
|
||||
{
|
||||
"category_id": cls.category_corrosive.id,
|
||||
"is_mandatory": False,
|
||||
}
|
||||
),
|
||||
Command.create(
|
||||
{
|
||||
"category_id": cls.category_bilogical.id,
|
||||
"is_mandatory": True,
|
||||
}
|
||||
),
|
||||
Command.create(
|
||||
{
|
||||
"category_id": cls.category_explosive.id,
|
||||
"is_mandatory": False,
|
||||
}
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.product_with_iden_opt = cls.product_tmpl_with_iden_opt.product_variant_ids[
|
||||
:1
|
||||
]
|
||||
cls.product_tmpl_without_iden = ProductTemplate.create(
|
||||
{
|
||||
"name": "Product Test",
|
||||
}
|
||||
)
|
||||
cls.product_without_iden = cls.product_tmpl_without_iden.product_variant_ids[:1]
|
||||
|
||||
cls.order = SaleOrder.create(
|
||||
{
|
||||
"name": "Sale Order Test",
|
||||
"partner_id": cls.partner_id.id,
|
||||
"order_line": [
|
||||
Command.create(
|
||||
{
|
||||
"name": cls.product_tmpl_with_iden.name,
|
||||
"product_id": cls.product_with_iden.id,
|
||||
"product_uom_qty": 5,
|
||||
}
|
||||
),
|
||||
Command.create(
|
||||
{
|
||||
"name": cls.product_tmpl_without_iden.name,
|
||||
"product_id": cls.product_without_iden.id,
|
||||
"product_uom_qty": 6,
|
||||
}
|
||||
),
|
||||
],
|
||||
}
|
||||
)
|
||||
cls.order_opt = SaleOrder.create(
|
||||
{
|
||||
"name": "Sale Order Test Optional",
|
||||
"partner_id": cls.partner_id.id,
|
||||
"order_line": [
|
||||
Command.create(
|
||||
{
|
||||
"name": cls.product_tmpl_with_iden_opt.name,
|
||||
"product_id": cls.product_with_iden_opt.id,
|
||||
"product_uom_qty": 5,
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
78
sale_product_identification/tests/test_sale_product_identification.py
Executable file
78
sale_product_identification/tests/test_sale_product_identification.py
Executable file
@@ -0,0 +1,78 @@
|
||||
# Copyright 2017 LasLabs Inc.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import Command
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests import Form
|
||||
|
||||
from .sale_product_identification_common import TestSaleOrderIdentificationCommon
|
||||
|
||||
|
||||
class TestSaleOrderIdentification(TestSaleOrderIdentificationCommon):
|
||||
def test_action_confirm(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.order.action_confirm()
|
||||
self.assertEqual(self.order.state, "draft")
|
||||
|
||||
self.partner_id.id_numbers = [
|
||||
Command.create(
|
||||
{
|
||||
"name": "Bad X ID",
|
||||
"category_id": self.category_bilogical.id,
|
||||
}
|
||||
)
|
||||
]
|
||||
self.order.action_confirm()
|
||||
self.assertEqual(self.order.state, "sale")
|
||||
|
||||
self.order_opt.action_confirm()
|
||||
self.assertEqual(self.order_opt.state, "draft")
|
||||
message = self.order_opt._message_error_identifications(
|
||||
[self.category_bilogical.id], True
|
||||
)
|
||||
self.assertIn(self.product_tmpl_with_iden_opt.name, message)
|
||||
self.assertIn(self.category_bilogical.name, message)
|
||||
ConfirmIdentification = self.env["confirm.identification"].with_context(
|
||||
**{
|
||||
"default_order_ids": [Command.set(self.order_opt.ids)],
|
||||
"default_message": message,
|
||||
}
|
||||
)
|
||||
wizard_confirm_identification_form = Form(ConfirmIdentification)
|
||||
wizard_confirm_identification = wizard_confirm_identification_form.save()
|
||||
wizard_confirm_identification.confirm_identification()
|
||||
self.assertEqual(self.order_opt.state, "sale")
|
||||
|
||||
def test_validate_identification_id_number(self):
|
||||
ResPartnerIdNumber = self.env["res.partner.id_number"]
|
||||
with self.assertRaises(ValidationError):
|
||||
ResPartnerIdNumber.validate_identification(
|
||||
**{
|
||||
"partner_id": False,
|
||||
}
|
||||
)
|
||||
category_ids = ResPartnerIdNumber.validate_identification(
|
||||
**{
|
||||
"partner_id": self.partner_id.id,
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(category_ids), 1)
|
||||
self.assertEqual(category_ids[:1], self.category_corrosive)
|
||||
|
||||
self.partner_id.id_numbers = [
|
||||
Command.create(
|
||||
{
|
||||
"name": "Test category",
|
||||
"category_id": self.category_bilogical.id,
|
||||
}
|
||||
)
|
||||
]
|
||||
|
||||
category_ids = ResPartnerIdNumber.validate_identification(
|
||||
**{
|
||||
"partner_id": self.partner_id.id,
|
||||
"compare_identification_ids": self.category_corrosive
|
||||
+ self.category_bilogical,
|
||||
}
|
||||
)
|
||||
self.assertEqual(len(category_ids), 0)
|
||||
Reference in New Issue
Block a user