1
1
# Copyright 2013-2019 Camptocamp SA
2
2
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
3
3
from odoo import Command , api , fields , models
4
+ from odoo .exceptions import UserError
4
5
5
6
6
7
class StockBatchPicking (models .Model ):
@@ -14,11 +15,9 @@ class StockBatchPicking(models.Model):
14
15
15
16
carrier_id = fields .Many2one (
16
17
comodel_name = "delivery.carrier" ,
17
- string = "Carrier" ,
18
18
)
19
19
option_ids = fields .Many2many (
20
20
comodel_name = "delivery.carrier.option" ,
21
- string = "Options" ,
22
21
)
23
22
option_ids_domain = fields .Binary (
24
23
string = "Options domain" ,
@@ -61,20 +60,19 @@ def onchange_carrier_id(self):
61
60
62
61
@api .onchange ("option_ids" )
63
62
def onchange_option_ids (self ):
64
- res = {}
65
63
if not self .carrier_id :
66
- return res
64
+ return
65
+
67
66
for available_option in self .carrier_id .available_option_ids :
68
67
if available_option .mandatory and available_option not in self .option_ids :
69
- res ["warning" ] = {
70
- "title" : self .env ._ ("User Error !" ),
71
- "message" : self .env ._ (
72
- "You can not remove a mandatory option."
73
- "\n Please reset options to default."
74
- ),
75
- }
68
+ # Optionally, reset the options to the default values.
76
69
self .option_ids = self ._get_options_to_add ()
77
- return res
70
+ raise UserError (
71
+ self .env ._ (
72
+ "You cannot remove a mandatory option. "
73
+ "\n Please reset options to default."
74
+ )
75
+ )
78
76
79
77
def _values_with_carrier_options (self , values ):
80
78
values = values .copy ()
0 commit comments