Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1 @@
from . import test_base_exception

View file

@ -0,0 +1,101 @@
# Copyright 2016 Akretion Mourad EL HADJ MIMOUNE
# Copyright 2020 Hibou Corp.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class ExceptionRule(models.Model):
_inherit = "exception.rule"
_name = "exception.rule"
method = fields.Selection(
selection_add=[("exception_method_no_zip", "Purchase exception no zip")]
)
model = fields.Selection(
selection_add=[("base.exception.test.purchase", "Purchase Test")],
ondelete={"base.exception.test.purchase": "cascade"},
)
test_purchase_ids = fields.Many2many("base.exception.test.purchase")
class PurchaseTest(models.Model):
_inherit = "base.exception"
_name = "base.exception.test.purchase"
_description = "Base Exception Test Model"
name = fields.Char(required=True)
user_id = fields.Many2one("res.users", string="Responsible")
state = fields.Selection(
[
("draft", "New"),
("cancel", "Cancelled"),
("purchase", "Purchase"),
("to approve", "To approve"),
("done", "Done"),
],
string="Status",
readonly=True,
default="draft",
)
active = fields.Boolean(default=True)
partner_id = fields.Many2one("res.partner", string="Partner")
line_ids = fields.One2many("base.exception.test.purchase.line", "lead_id")
amount_total = fields.Float(compute="_compute_amount_total", store=True)
@api.depends("line_ids")
def _compute_amount_total(self):
for record in self:
for line in record.line_ids:
record.amount_total += line.amount * line.qty
@api.constrains("ignore_exception", "line_ids", "state")
def test_purchase_check_exception(self):
orders = self.filtered(lambda s: s.state == "purchase")
if orders:
orders._check_exception()
def button_approve(self, force=False):
self.write({"state": "to approve"})
return {}
def button_draft(self):
self.write({"state": "draft"})
return {}
def button_confirm(self):
self.write({"state": "purchase"})
return True
def button_cancel(self):
self.write({"state": "cancel"})
def exception_method_no_zip(self):
records_fail = self.env["base.exception.test.purchase"]
for rec in self:
if not rec.partner_id.zip:
records_fail += rec
return records_fail
class LineTest(models.Model):
_name = "base.exception.test.purchase.line"
_description = "Base Exception Test Model Line"
name = fields.Char()
lead_id = fields.Many2one("base.exception.test.purchase", ondelete="cascade")
qty = fields.Float()
amount = fields.Float()
class WizardTest(models.TransientModel):
_name = "exception.rule.confirm.test.purchase"
_inherit = "exception.rule.confirm"
_description = "Base Exception Test Model Confirm"
related_model_id = fields.Many2one("base.exception.test.purchase", "Purchase")
def action_confirm(self):
self.ensure_one()
if self.ignore:
self.related_model_id.ignore_exception = True
return super().action_confirm()

View file

@ -0,0 +1,150 @@
# Copyright 2016 Akretion Mourad EL HADJ MIMOUNE
# Copyright 2020 Hibou Corp.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo_test_helper import FakeModelLoader
from odoo.exceptions import UserError, ValidationError
from odoo.tests import TransactionCase
class TestBaseException(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.loader = FakeModelLoader(cls.env, cls.__module__)
cls.loader.backup_registry()
from .purchase_test import ExceptionRule, LineTest, PurchaseTest, WizardTest
cls.loader.update_registry((ExceptionRule, LineTest, PurchaseTest, WizardTest))
cls.partner = cls.env["res.partner"].create({"name": "Foo"})
cls.po = cls.env["base.exception.test.purchase"].create(
{
"name": "Test base exception to basic purchase",
"partner_id": cls.partner.id,
"line_ids": [
(0, 0, {"name": "line test", "amount": 120.0, "qty": 1.5})
],
}
)
cls.exception_rule = cls.env["exception.rule"].create(
{
"name": "No ZIP code on destination",
"sequence": 10,
"model": "base.exception.test.purchase",
"code": "if not self.partner_id.zip: failed=True",
"exception_type": "by_py_code",
}
)
exception_rule_confirm_obj = cls.env["exception.rule.confirm.test.purchase"]
cls.exception_rule_confirm = exception_rule_confirm_obj.with_context(
active_model="base.exception.test.purchase", active_ids=cls.po.ids
).create(
{
"related_model_id": cls.po.id,
"ignore": False,
}
)
@classmethod
def tearDownClass(cls):
cls.loader.restore_registry()
return super().tearDownClass()
def test_valid(self):
self.partner.write({"zip": "00000"})
self.exception_rule.active = False
self.po.button_confirm()
self.assertFalse(self.po.exception_ids)
def test_exception_rule_confirm(self):
self.exception_rule_confirm.action_confirm()
self.assertFalse(self.exception_rule_confirm.exception_ids)
def test_fail_by_py(self):
with self.assertRaises(ValidationError):
self.po.button_confirm()
self.po.with_context(raise_exception=False).button_confirm()
self.assertTrue(self.po.exception_ids)
def test_fail_by_domain(self):
self.exception_rule.write(
{
"domain": "[('partner_id.zip', '=', False)]",
"exception_type": "by_domain",
}
)
with self.assertRaises(ValidationError):
self.po.button_confirm()
self.po.with_context(raise_exception=False).button_confirm()
self.assertTrue(self.po.exception_ids)
def test_fail_by_method(self):
self.exception_rule.write(
{
"method": "exception_method_no_zip",
"exception_type": "by_method",
}
)
with self.assertRaises(ValidationError):
self.po.button_confirm()
self.po.with_context(raise_exception=False).button_confirm()
self.assertTrue(self.po.exception_ids)
def test_ignorable_exception(self):
# Block because of exception during validation
with self.assertRaises(ValidationError):
self.po.button_confirm()
self.po.with_context(raise_exception=False).button_confirm()
# Test that we have linked exceptions
self.assertTrue(self.po.exception_ids)
# Test ignore exeception make possible for the po to validate
self.po.action_ignore_exceptions()
self.assertTrue(self.po.ignore_exception)
self.assertFalse(self.po.exceptions_summary)
self.po.button_confirm()
self.assertEqual(self.po.state, "purchase")
def test_purchase_check_exception(self):
self.po.test_purchase_check_exception()
def test_purchase_check_button_approve(self):
self.po.button_approve()
self.assertEqual(self.po.state, "to approve")
def test_purchase_check_button_draft(self):
self.po.button_draft()
self.assertEqual(self.po.state, "draft")
def test_purchase_check_button_confirm(self):
self.partner.write({"zip": "00000"})
self.po.button_confirm()
self.assertEqual(self.po.state, "purchase")
def test_purchase_check_button_cancel(self):
self.po.button_cancel()
self.assertEqual(self.po.state, "cancel")
def test_detect_exceptions(self):
self.po.detect_exceptions()
def test_blocking_exception(self):
self.exception_rule.is_blocking = True
# Block because of exception during validation
with self.assertRaises(ValidationError):
self.po.button_confirm()
# Test that we have linked exceptions
self.po.with_context(raise_exception=False).button_confirm()
self.assertTrue(self.po.exception_ids)
self.assertTrue(self.po.exceptions_summary)
# Test cannot ignore blocked exception
with self.assertRaises(UserError):
self.po.action_ignore_exceptions()
self.assertFalse(self.po.ignore_exception)
with self.assertRaises(ValidationError):
self.po.button_confirm()
self.po.with_context(raise_exception=False).button_confirm()
self.assertTrue(self.po.exception_ids)
self.assertTrue(self.po.exceptions_summary)