From ae6a959ea7db4ed51c024ace5364a38d23a9c98d Mon Sep 17 00:00:00 2001 From: sbejaoui Date: Wed, 25 Jan 2023 10:43:07 +0100 Subject: [PATCH] [16.0][MIG] - finalize sale_exception migration --- sale_exception/models/__init__.py | 3 ++- sale_exception/models/exception_rule.py | 22 ++++++++++++++++ .../models/{sale.py => sale_order.py} | 25 +------------------ sale_exception/tests/test_multi_records.py | 11 +++----- sale_exception/tests/test_sale_exception.py | 17 ++++--------- 5 files changed, 34 insertions(+), 44 deletions(-) create mode 100644 sale_exception/models/exception_rule.py rename sale_exception/models/{sale.py => sale_order.py} (74%) diff --git a/sale_exception/models/__init__.py b/sale_exception/models/__init__.py index d6118113744..04ebb10ecb8 100644 --- a/sale_exception/models/__init__.py +++ b/sale_exception/models/__init__.py @@ -1,3 +1,4 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) -from . import sale +from . import exception_rule +from . import sale_order from . import sale_order_line diff --git a/sale_exception/models/exception_rule.py b/sale_exception/models/exception_rule.py new file mode 100644 index 00000000000..d9feaee5efe --- /dev/null +++ b/sale_exception/models/exception_rule.py @@ -0,0 +1,22 @@ +# Copyright 2011 Akretion, Sodexis +# Copyright 2018 Akretion +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ExceptionRule(models.Model): + _inherit = "exception.rule" + + model = fields.Selection( + selection_add=[ + ("sale.order", "Sale order"), + ("sale.order.line", "Sale order line"), + ], + ondelete={ + "sale.order": "cascade", + "sale.order.line": "cascade", + }, + ) + sale_ids = fields.Many2many("sale.order", string="Sales") diff --git a/sale_exception/models/sale.py b/sale_exception/models/sale_order.py similarity index 74% rename from sale_exception/models/sale.py rename to sale_exception/models/sale_order.py index e68e08279bd..c79884f373d 100644 --- a/sale_exception/models/sale.py +++ b/sale_exception/models/sale_order.py @@ -3,23 +3,7 @@ # Copyright 2019 Camptocamp SA # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import api, fields, models - - -class ExceptionRule(models.Model): - _inherit = "exception.rule" - - model = fields.Selection( - selection_add=[ - ("sale.order", "Sale order"), - ("sale.order.line", "Sale order line"), - ], - ondelete={ - "sale.order": "cascade", - "sale.order.line": "cascade", - }, - ) - sale_ids = fields.Many2many("sale.order", string="Sales") +from odoo import api, models class SaleOrder(models.Model): @@ -53,13 +37,6 @@ def _check_sale_check_exception(self, vals): if check_exceptions: self.sale_check_exception() - @api.model_create_multi - def create(self, vals_list): - records = super().create(vals_list) - for record, vals in zip(records, vals_list): - record._check_sale_check_exception(vals) - return records - def write(self, vals): result = super().write(vals) self._check_sale_check_exception(vals) diff --git a/sale_exception/tests/test_multi_records.py b/sale_exception/tests/test_multi_records.py index 525aa956027..d23713c34fd 100644 --- a/sale_exception/tests/test_multi_records.py +++ b/sale_exception/tests/test_multi_records.py @@ -1,7 +1,8 @@ # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -import mock +from unittest import mock +from odoo import Command from odoo.tests import TransactionCase @@ -26,9 +27,7 @@ def test_sale_order_exception(self): "partner_invoice_id": partner.id, "partner_shipping_id": partner.id, "order_line": [ - ( - 0, - 0, + Command.create( { "name": p.name, "product_id": p.id, @@ -57,9 +56,7 @@ def test_sale_order_exception(self): "partner_invoice_id": partner.id, "partner_shipping_id": partner.id, "order_line": [ - ( - 0, - 0, + Command.create( { "name": p.name, "product_id": p.id, diff --git a/sale_exception/tests/test_sale_exception.py b/sale_exception/tests/test_sale_exception.py index a3f901a6e73..7bb3ed370f3 100644 --- a/sale_exception/tests/test_sale_exception.py +++ b/sale_exception/tests/test_sale_exception.py @@ -4,6 +4,7 @@ # Copyright 2021 Tecnativa - Víctor Martínez # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +from odoo import Command from odoo.exceptions import ValidationError from odoo.tests import Form, TransactionCase @@ -29,9 +30,7 @@ def test_sale_order_exception(self): "partner_invoice_id": partner.id, "partner_shipping_id": partner.id, "order_line": [ - ( - 0, - 0, + Command.create( { "name": p.name, "product_id": p.id, @@ -59,9 +58,7 @@ def test_sale_order_exception(self): "partner_invoice_id": partner.id, "partner_shipping_id": partner.id, "order_line": [ - ( - 0, - 0, + Command.create( { "name": p.name, "product_id": p.id, @@ -91,9 +88,7 @@ def test_sale_order_exception(self): { "ignore_exception": False, "order_line": [ - ( - 0, - 0, + Command.create( { "name": p.name, "product_id": p.id, @@ -113,9 +108,7 @@ def test_sale_order_exception(self): { "ignore_exception": True, "order_line": [ - ( - 0, - 0, + Command.create( { "name": p.name, "product_id": p.id,