@@ -184,21 +184,7 @@ def _check_foreign_countries(self, commune_of_origin, current_year, department_o
184
184
raise ValidationError (self .error_messages ['invalid' ], code = 'invalid' )
185
185
186
186
187
- class FRSIRENENumberMixin :
188
- """Abstract class for SIREN and SIRET numbers, from the SIRENE register."""
189
-
190
- def clean (self , value ):
191
- value = super ().clean (value )
192
- if value in self .empty_values :
193
- return value
194
-
195
- value = value .replace (' ' , '' ).replace ('-' , '' )
196
- if not self .r_valid .match (value ) or not luhn .is_valid (value ):
197
- raise ValidationError (self .error_messages ['invalid' ], code = 'invalid' )
198
- return value
199
-
200
-
201
- class FRSIRENField (FRSIRENENumberMixin , CharField ):
187
+ class FRSIRENField (CharField ):
202
188
"""
203
189
SIREN stands for "Système d'identification du répertoire des entreprises".
204
190
@@ -220,8 +206,18 @@ def prepare_value(self, value):
220
206
value = value .replace (' ' , '' ).replace ('-' , '' )
221
207
return ' ' .join ((value [:3 ], value [3 :6 ], value [6 :]))
222
208
209
+ def clean (self , value ):
210
+ value = super ().clean (value )
211
+ if value in self .empty_values :
212
+ return value
213
+
214
+ value = value .replace (' ' , '' ).replace ('-' , '' )
215
+ if not self .r_valid .match (value ) or not luhn .is_valid (value ):
216
+ raise ValidationError (self .error_messages ['invalid' ], code = 'invalid' )
217
+ return value
218
+
223
219
224
- class FRSIRETField (FRSIRENENumberMixin , CharField ):
220
+ class FRSIRETField (CharField ):
225
221
"""
226
222
SIRET stands for "Système d'identification du répertoire des établissements".
227
223
@@ -244,7 +240,8 @@ def clean(self, value):
244
240
245
241
value = value .replace (' ' , '' ).replace ('-' , '' )
246
242
247
- if not luhn .is_valid (value [:9 ]):
243
+ if not self .r_valid .match (value ) or not luhn .is_valid (value [:9 ]) or \
244
+ (value .startswith ("356000000" ) and sum (int (x ) for x in value ) % 5 != 0 ):
248
245
raise ValidationError (self .error_messages ['invalid' ], code = 'invalid' )
249
246
return value
250
247
0 commit comments