Skip to content

Commit

Permalink
[FIX] Validation should be done during chunk processing
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienbeau committed Feb 20, 2021
1 parent 0463c5c commit 49dd5a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Copyright (c) Akretion 2020
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
from odoo import _
from odoo.exceptions import ValidationError
from odoo.tools import float_compare

from odoo.addons.component.core import Component
Expand All @@ -15,6 +17,8 @@ def _prepare_sale_vals(self, data):
carrier_id = self.env["delivery.carrier"].search(
[("name", "=", data["delivery_carrier"]["name"])]
)
if not carrier_id:
raise ValidationError(_("Couldn't find a carrier with given name"))
vals.update({"carrier_id": carrier_id.id})
return vals

Expand Down
9 changes: 0 additions & 9 deletions sale_import_delivery_carrier/datamodels/delivery_carrier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Copyright (c) Akretion 2020
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
from marshmallow_objects import ValidationError, validates

from odoo import _

from odoo.addons.datamodel import fields
from odoo.addons.datamodel.core import Datamodel
Expand All @@ -11,12 +8,6 @@
class DeliveryCarrierDatamodel(Datamodel):
_name = "delivery.carrier"

@validates("name")
def _validate_name(self, name):
carrier = self._env["delivery.carrier"].search([("name", "=", name)])
if not carrier:
raise ValidationError(_("Couldn't find a carrier with given name"))

name = fields.Str(required=True)
price_unit = fields.Decimal(required=True)
discount = fields.Decimal()
Expand Down

0 comments on commit 49dd5a5

Please sign in to comment.