1414 ERR_ORGANIZATION_NAME ,
1515)
1616from ffc .flows .order import MPT_ORDER_STATUS_COMPLETED , MPT_ORDER_STATUS_QUERYING
17+ from ffc .flows .steps .utils import reset_order_error
1718from ffc .notifications import send_email_notification
1819from ffc .parameters import (
1920 PARAM_ADMIN_CONTACT ,
2021 PARAM_CURRENCY ,
2122 PARAM_ORGANIZATION_NAME ,
2223 get_ordering_parameter ,
24+ reset_ordering_parameters_error ,
2325 set_ordering_parameter_error ,
2426)
2527
@@ -73,8 +75,8 @@ def __call__(self, client, context, next_step):
7375
7476class CheckOrderParameters (Step ):
7577 """
76- Check if all required parameters are submitted, if not
77- query order
78+ Check if all required parameters are submitted
79+ If not sets `validation_succeeded` to False
7880 """
7981
8082 def __call__ (self , client , context , next_step ):
@@ -84,7 +86,6 @@ def __call__(self, client, context, next_step):
8486 PARAM_ADMIN_CONTACT : ERR_ADMIN_CONTACT ,
8587 }
8688 order = context .order
87- empty_parameters = []
8889
8990 for param_name in [
9091 PARAM_ORGANIZATION_NAME ,
@@ -96,9 +97,20 @@ def __call__(self, client, context, next_step):
9697 order = set_ordering_parameter_error (
9798 order , param_name , errors [param_name ]
9899 )
99- empty_parameters . append ( param_name )
100+ context . validation_succeeded = False
100101
101- if empty_parameters :
102+ next_step (client , context )
103+
104+
105+ class QueryIfInvalid (Step ):
106+ """
107+ Check if `validation_succeeded` context parameter is True
108+ If not - query order
109+ """
110+
111+ def __call__ (self , client , context , next_step ):
112+ order = context .order
113+ if not context .validation_succeeded :
102114 template = get_product_template_or_default (
103115 client ,
104116 context .product_id ,
@@ -109,9 +121,22 @@ def __call__(self, client, context, next_step):
109121 order ["agreement" ] = agreement
110122 context .order = order
111123 logger .info (
112- f"{ context } : parameters { ', ' . join ( empty_parameters ) } are empty , move to querying" ,
124+ f"{ context } : ordering parameters are invalid , move to querying" ,
113125 )
114126 send_email_notification (client , order )
115127 return
116128
117129 next_step (client , context )
130+
131+
132+ class ResetOrderErrors (Step ):
133+ """
134+ Reset order errors and parameter errors. Is used before processing
135+ to not to show errors during procesing or after validation is succeseed
136+ """
137+
138+ def __call__ (self , client , context , next_step ):
139+ context .order = reset_order_error (context .order )
140+ context .order = reset_ordering_parameters_error (context .order )
141+
142+ next_step (client , context )
0 commit comments