Skip to content

Commit 1b1cb16

Browse files
committed
[IMP] with tag and supplier_min_qty
1 parent 6d06797 commit 1b1cb16

File tree

2 files changed

+86
-38
lines changed

2 files changed

+86
-38
lines changed

import_helper_generic/wizards/import_helper_generic.py

Lines changed: 82 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,11 @@ def partner_import_generic(self):
123123
vals = self.check_vals_partner(vals)
124124
if vals["ref"] in partner_ids_list:
125125
import_obj._prepare_partner_vals(vals, speedy)
126-
res = (
127-
self.env["res.partner"]
128-
.browse(partner_ids_list[vals["ref"]])
129-
.write(vals)
130-
)
126+
record = self.env["res.partner"].browse(partner_ids_list[vals["ref"]])
127+
res = record.write(vals)
131128
if res:
132129
logger.info(
133-
f"{res.display_name},id {res.id} has been update with line {line}"
130+
f"{record.display_name},id {record.id} has been update with line {line}"
134131
)
135132
else:
136133
import_obj._create_partner(vals, speedy)
@@ -261,22 +258,62 @@ def product_import_generic(self):
261258
location_id = vals.get("location_id") or speedy.get(
262259
"default_location_id"
263260
)
264-
vals = import_obj._prepare_product_vals(vals, location_id, speedy)
265-
if not vals:
266-
logger.warning("Product on line %s skipped", line)
261+
ref_product = vals.pop(reference)
262+
record = self.env["product.product"].browse(
263+
speedy_product_list[ref_product]
264+
)
265+
if record:
266+
if record.location_id and record.location_id != location_id:
267+
location_id = record.location_id
268+
if vals.get("default_code") == record.default_code:
269+
vals.pop("default_code")
270+
if vals.get("barcode") == record.barcode:
271+
vals.pop("barcode")
272+
vals = import_obj._prepare_product_vals(
273+
vals, location_id, speedy
274+
)
275+
if not vals:
276+
logger.warning("Product on line %s skipped", line)
277+
continue
278+
vals["standard_price"] = float(vals["standard_price"])
279+
res = record.write(vals)
280+
if res:
281+
logger.info(
282+
f"{record.display_name}, id {record.id} has been update with line {line}"
283+
)
284+
else:
285+
logger.warning(f"line {line} have done nothing")
267286
continue
268-
res = (
269-
self.env["product.product"]
270-
.browse(speedy_product_list[vals[reference]])
271-
.write(vals)
287+
elif template and vals.get(reference) in speedy_product_list:
288+
location_id = vals.get("location_id") or speedy.get(
289+
"default_location_id"
290+
)
291+
ref_product = vals.pop(reference)
292+
record = self.env["product.product"].browse(
293+
speedy_product_list[ref_product]
272294
)
273-
if res:
274-
logger.info(
275-
f"{res.display_name}, id {res.id} has been update with line {line}"
295+
if record:
296+
if record.location_id and record.location_id != location_id:
297+
location_id = record.location_id
298+
if vals.get("default_code") == record.default_code:
299+
vals.pop("default_code")
300+
if vals.get("barcode") == record.barcode:
301+
vals.pop("barcode")
302+
vals = import_obj._prepare_product_vals(
303+
vals, location_id, speedy
276304
)
277-
else:
278-
logger.warning(f"line {line} have done nothing")
279-
continue
305+
if not vals:
306+
logger.warning("Product on line %s skipped", line)
307+
continue
308+
vals["standard_price"] = float(vals["standard_price"])
309+
res = record.write(vals)
310+
if res:
311+
logger.info(
312+
f"{record.display_name}, id {record.id} has been update with line {line}"
313+
)
314+
else:
315+
logger.warning(f"line {line} have done nothing")
316+
continue
280317
elif (
281318
not template
282319
and vals.get(reference) not in speedy_product_list
@@ -308,27 +345,38 @@ def product_import_generic(self):
308345
template
309346
and vals.get("default_code") in speedy_product_template_list
310347
):
348+
location_id = vals.get("location_id") or speedy.get(
349+
"default_location_id"
350+
)
311351
record = self.env["product.template"].browse(
312352
speedy_product_template_list[vals["default_code"]]
313353
)
314-
if record and not vals.get("location_id"):
315-
vals["location_id"] = record.location_id
316-
vals = import_obj._prepare_product_vals(
317-
vals, vals["location_id"], speedy
318-
)
319-
if not vals:
320-
logger.warning("Product on line %s skipped", line)
321-
continue
354+
ref_product = vals.pop("default_code")
355+
if record:
356+
if record.location_id and record.location_id != location_id:
357+
location_id = record.location_id
358+
if vals.get("barcode") == record.barcode:
359+
vals.pop("barcode")
360+
vals = import_obj._prepare_product_vals(
361+
vals, location_id, speedy
362+
)
363+
if not vals:
364+
logger.warning("Product on line %s skipped", line)
365+
continue
322366

323-
res = record.write(vals)
324-
if res:
325-
logger.info(f"Update {res.name} {res.id} Ok")
326-
continue
367+
res = record.write(vals)
368+
if res:
369+
logger.info(f"Update {record.name} {record.id} Ok")
370+
continue
371+
else:
372+
logger.warning(
373+
f"ERREUR lors de la mise a jour du product line {line}"
374+
)
375+
continue
327376
else:
328-
logger.warning("ERREUR lors de la mise a jour du product")
329-
continue
377+
logger.warning(f"No product found for {line}")
330378

331-
elif not template or template and not variant_att:
379+
elif (not template or template) and not variant_att:
332380
res = import_obj._create_product(vals, speedy)
333381
continue
334382
elif template:

product_import_helper/wizards/import_helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,8 @@ def _prepare_product_vals(self, vals, location_id, speedy):
405405
else:
406406
tag_id = self.env["product.tag"].create({"name": tag})
407407
list_tag_id.append(tag_id.id)
408-
speedy_tags[tag] = tag.id
409-
vals["product_tag_ids"] = Command.set(list_tag_id)
408+
speedy_tags[tag] = tag_id.id
409+
vals["product_tag_ids"] = [Command.set(list_tag_id)]
410410
if vals.get("tags_variant"):
411411
list_tag_id = []
412412
for tag in vals["tags_variant"].split("/"):
@@ -415,8 +415,8 @@ def _prepare_product_vals(self, vals, location_id, speedy):
415415
else:
416416
tag_id = self.env["product.tag"].create({"name": tag})
417417
list_tag_id.append(tag_id.id)
418-
speedy_tags[tag] = tag.id
419-
vals["additional_product_tag_ids"] = Command.set(list_tag_id)
418+
speedy_tags[tag] = tag_id.id
419+
vals["additional_product_tag_ids"] = [Command.set(list_tag_id)]
420420

421421
# Remove all keys that start with supplier_
422422
# vals will keep the original keys

0 commit comments

Comments
 (0)