Skip to content

Commit

Permalink
[16.0][MIG] - finalize sale_exception migration
Browse files Browse the repository at this point in the history
  • Loading branch information
sbejaoui committed Jan 25, 2023
1 parent 4be9ab6 commit ae6a959
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 44 deletions.
3 changes: 2 additions & 1 deletion sale_exception/models/__init__.py
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions sale_exception/models/exception_rule.py
Original file line number Diff line number Diff line change
@@ -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")
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions sale_exception/tests/test_multi_records.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 5 additions & 12 deletions sale_exception/tests/test_sale_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit ae6a959

Please sign in to comment.