@@ -46,6 +46,7 @@ class ImportHelpergeneric(models.TransientModel):
4646 _description = "Import helper generic for importing information with template"
4747
4848 file_import = fields .Binary (string = "File to import" )
49+ update_on = fields .Boolean (string = "Import or update" )
4950
5051 def speedy_partner_categori_id (self ):
5152 categ_id = {}
@@ -270,7 +271,7 @@ def product_import_generic(self):
270271 # else:
271272 # logger.warning(f"line {line} have done nothing")
272273 if not template :
273- if vals .get (reference ) in speedy_product_list :
274+ if vals .get (reference ) in speedy_product_list and self . update_on :
274275 location_id = vals .get ("location_id" ) or speedy .get (
275276 "default_location_id"
276277 )
@@ -301,6 +302,19 @@ def product_import_generic(self):
301302 else :
302303 logger .warning (f"line { line } have done nothing" )
303304 continue
305+ elif (
306+ vals .get (reference ) in speedy_product_list
307+ and not self .update_on
308+ ):
309+ speedy ["logs" ]["product.product" ].append (
310+ {
311+ "msg" : f"Product with { vals [reference ]} already exist for line { line } " ,
312+ "value" : vals [reference ],
313+ "vals" : vals ,
314+ "field" : f"product.product,{ reference } " ,
315+ "reset" : True ,
316+ }
317+ )
304318 elif vals .get ("product_tmpl_id" ):
305319 location_id = vals .get ("location_id" ) or speedy .get (
306320 "default_location_id"
@@ -370,7 +384,7 @@ def product_import_generic(self):
370384 res = import_obj ._create_product (vals , speedy )
371385 continue
372386 elif template :
373- if vals .get (reference ) in speedy_product_list :
387+ if vals .get (reference ) in speedy_product_list and self . update_on :
374388 location_id = vals .get ("location_id" ) or speedy .get (
375389 "default_location_id"
376390 )
@@ -401,6 +415,19 @@ def product_import_generic(self):
401415 else :
402416 logger .warning (f"line { line } have done nothing" )
403417 continue
418+ elif (
419+ vals .get (reference ) in speedy_product_list
420+ and not self .update_on
421+ ):
422+ speedy ["logs" ]["product.product" ].append (
423+ {
424+ "msg" : f"Product with { vals [reference ]} already exist for line { line } " ,
425+ "value" : vals [reference ],
426+ "vals" : vals ,
427+ "field" : f"product.product,{ reference } " ,
428+ "reset" : True ,
429+ }
430+ )
404431 elif vals .get ("default_code" ) in speedy_product_template_list :
405432 location_id = vals .get ("location_id" ) or speedy .get (
406433 "default_location_id"
@@ -502,7 +529,7 @@ def product_import_generic(self):
502529 logger .info (f"product variant for { att } create" )
503530 p_tmpl .default_code = vals ["default_code" ]
504531 logger .info (
505- f"{ p_tmpl .id } has been create with { len (list_attribue_ids )} variant"
532+ f"{ p_tmpl .id } has been create with { len (p_tmpl . attribute_line_ids )} variant"
506533 )
507534 else :
508535 logger .info (f"{ p_tmpl .id } has been create" )
0 commit comments