Skip to content

Commit a7a5e55

Browse files
committed
add info for speedy
1 parent 6aeed75 commit a7a5e55

File tree

1 file changed

+66
-19
lines changed

1 file changed

+66
-19
lines changed

import_helper_generic/wizards/import_helper_generic.py

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def prepare_speedy_attribute_value(self):
144144
}
145145
return speedy_attribute_value
146146

147-
def check_vals_product(self, vals):
147+
def check_vals_product(self, vals, speedy):
148148
variant_att = ()
149149
list_attribute_ids = {}
150150
template = False
@@ -163,6 +163,15 @@ def check_vals_product(self, vals):
163163
list_attribute_ids[
164164
speedy_attribute_value[v]["attribute_id"]
165165
] = [speedy_attribute_value[v]["id"]]
166+
else:
167+
speedy["logs"]["product.product"].append(
168+
{
169+
"msg": f"Cannot found attrivutes {v} for {vals['line']}",
170+
"value": v,
171+
"vals": vals,
172+
"field": "product.product,attribute_line_ids",
173+
}
174+
)
166175

167176
if "ref_supplier" in vals:
168177
speedy_partner_id = self.speedy_partner_id()
@@ -239,7 +248,7 @@ def product_import_generic(self):
239248
vals["ref_template"]
240249
]
241250
vals, variant_att, list_attribue_ids, template = (
242-
self.check_vals_product(vals)
251+
self.check_vals_product(vals, speedy)
243252
)
244253
# if (
245254
# not vals.get("product_tmpl_id")
@@ -308,25 +317,53 @@ def product_import_generic(self):
308317
template = self.env["product.template"].browse(
309318
vals["product_tmpl_id"]
310319
)
320+
res_p = False
311321
for p in template.product_variant_ids:
312322
if p.product_template_attribute_value_ids:
313-
for v in p.product_template_attribute_value_ids:
314-
if (
315-
v.product_attribute_value_id.fullname
316-
in variant_att
317-
):
318-
if vals.get("standard_price"):
319-
vals["standard_price"] = float(
320-
vals["standard_price"]
321-
)
322-
if vals.get("list_price") and hasattr(
323-
p, "fix_price"
323+
if not p.barcode:
324+
for v in p.product_template_attribute_value_ids:
325+
if (
326+
v.product_attribute_value_id.fullname
327+
in variant_att
324328
):
325-
vals["fix_price"] = vals["list_price"]
326-
vals.pop("list_price")
327-
elif vals.get("list_price"):
328-
vals.pop("list_price")
329-
p.write(vals)
329+
if vals.get("standard_price"):
330+
vals["standard_price"] = float(
331+
vals["standard_price"]
332+
)
333+
if vals.get("list_price") and hasattr(
334+
p, "fix_price"
335+
):
336+
vals["fix_price"] = vals["list_price"]
337+
vals.pop("list_price")
338+
elif vals.get("list_price"):
339+
vals.pop("list_price")
340+
res_p = p.write(vals)
341+
logger.info(
342+
f"product variant {p.id} has been update {v}"
343+
)
344+
break
345+
else:
346+
speedy["logs"]["product.product"].append(
347+
{
348+
"msg": f"{p.id} product with {variant_att} already exite",
349+
"value": variant_att,
350+
"vals": vals,
351+
"field": "product.product,attribute_line_ids",
352+
"reset": True,
353+
}
354+
)
355+
356+
if not res_p:
357+
speedy["logs"]["product.product"].append(
358+
{
359+
"msg": f"Not product with {variant_att}",
360+
"value": variant_att,
361+
"vals": vals,
362+
"field": "product.product,attribute_line_ids",
363+
"reset": True,
364+
}
365+
)
366+
330367
continue
331368
else:
332369
res = import_obj._create_product(vals, speedy)
@@ -461,18 +498,28 @@ def product_import_generic(self):
461498
}
462499
)
463500
]
501+
logger.info(f"product variant for {att} create")
464502
p_tmpl.default_code = vals["default_code"]
465503
logger.info(
466504
f"{p_tmpl.id} has been create with {len(list_attribue_ids)} variant"
467505
)
468506
else:
469-
logger.warning(f"{p_tmpl.id} has been create")
507+
logger.info(f"{p_tmpl.id} has been create")
470508
continue
471509
# elif (not template or template) and not variant_att:
472510
# res = import_obj._create_product(vals, speedy)
473511
# continue
474512
else:
475513
logger.warning(f"NO PRODUCT IMPORTED line {line} Name {row[1]}")
514+
speedy["logs"]["product.product"].append(
515+
{
516+
"msg": "Pas d'identification product ou template colonnes type [A]",
517+
"value": row[0],
518+
"vals": vals,
519+
"field": "product.product,product_tmpl_id",
520+
"reset": True,
521+
}
522+
)
476523
else:
477524
break
478525
for t in speedy_product_template_list:

0 commit comments

Comments
 (0)