Skip to content

Commit c4338c9

Browse files
committed
[IMP] edi_mail_import_oca: Pass verification logic to constrain
1 parent a88067b commit c4338c9

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

edi_mail_import_oca/models/edi_exchange_record.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import re
88

99
from odoo import api, models
10-
from odoo.exceptions import UserError
1110

1211
_logger = logging.getLogger(__name__)
1312

@@ -21,10 +20,6 @@ def message_new(self, msg_dict, custom_values=None):
2120
msg_dict,
2221
custom_values=custom_values,
2322
)
24-
if record.type_id.direction != "input":
25-
raise UserError(
26-
self.env._("Received email for non-incoming exchange type.")
27-
)
2823
if record.type_id.mail_as_attachment:
2924
new_message_dict = msg_dict.copy()
3025
attachments = new_message_dict.pop("attachments", [])

edi_mail_import_oca/models/edi_exchange_type.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33
import ast
44

5-
from odoo import fields, models
5+
from odoo import api, fields, models
6+
from odoo.exceptions import ValidationError
67

78

89
class EdiExchangeType(models.Model):
@@ -13,6 +14,16 @@ class EdiExchangeType(models.Model):
1314
string="Import Email as an Attachment",
1415
)
1516

17+
@api.constrains("direction", "alias_id.alias_domain", "alias_id.alias_name")
18+
def _check_mail_configuration(self):
19+
for record in self:
20+
if record.direction != "input" and record.alias_email:
21+
raise ValidationError(
22+
self.env._(
23+
"You cannot have a receiving email for a non-incoming type."
24+
)
25+
)
26+
1627
def _alias_get_creation_values(self):
1728
values = super()._alias_get_creation_values()
1829
values["alias_model_id"] = (

edi_mail_import_oca/tests/test_mail_import_oca.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import json
44

5+
from odoo.exceptions import ValidationError
56
from odoo.tests import tagged
67

78
from odoo.addons.mail.tests.common import MailCommon
@@ -38,6 +39,15 @@ def setUpClass(cls):
3839
}
3940
)
4041

42+
def test_constraint(self):
43+
with self.assertRaises(ValidationError):
44+
self.exchange_type.direction = "output"
45+
46+
def test_constraint_no_error_on_no_alias(self):
47+
self.exchange_type.alias_name = False
48+
self.exchange_type.direction = "output"
49+
self.assertFalse(self.exchange_type.alias_email)
50+
4151
def test_import_full(self):
4252
self.assertTrue(self.exchange_type.alias_email)
4353
self.exchange_type.mail_as_attachment = True

0 commit comments

Comments
 (0)