Skip to content

Commit afce348

Browse files
committed
Modif reference and product
1 parent 1ccdd2b commit afce348

File tree

3 files changed

+52
-30
lines changed

3 files changed

+52
-30
lines changed

import_helper_generic/wizards/import_helper_generic.py

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"attributes",
3838
"ref_supplier",
3939
"ref_template",
40+
"Colonnes:",
4041
]
4142

4243

@@ -149,6 +150,7 @@ def prepare_speedy_attribute_value(self):
149150
def check_vals_product(self, vals):
150151
variant_att = ()
151152
list_attribute_ids = {}
153+
template = False
152154
if "attributes" in vals:
153155
speedy_attribute_value = self.prepare_speedy_attribute_value()
154156
variant_att = vals["attributes"].split("/")
@@ -169,10 +171,12 @@ def check_vals_product(self, vals):
169171
speedy_partner_id = self.speedy_partner_id()
170172
if vals["ref_supplier"] in speedy_partner_id:
171173
vals["supplier_id"] = speedy_partner_id[vals["ref_supplier"]]
174+
if vals.get("Colonnes:") == "product.template":
175+
template = True
172176
for i in LIST_COL_POP:
173177
if vals.get(i):
174178
vals.pop(i)
175-
return vals, variant_att, list_attribute_ids
179+
return vals, variant_att, list_attribute_ids, template
176180

177181
def product_import_generic(self):
178182
fileobj = NamedTemporaryFile(
@@ -187,10 +191,19 @@ def product_import_generic(self):
187191
speedy = import_obj._prepare_speedy(aiengine="NONE")
188192
line = 0
189193
colonnes = []
194+
reference = ""
195+
for row in reader.iter_rows(min_row=1, max_row=2, max_col=6, values_only=True):
196+
if row[0] == "Infotmation":
197+
if row[1] == "Champ de reference":
198+
reference = row[2]
190199
product_ids = self.env["product.product"].search([])
191200
speedy_product_list = {}
192-
for p in product_ids:
193-
speedy_product_list[p.default_code] = p.id
201+
if reference == "default_code":
202+
for p in product_ids:
203+
speedy_product_list[p.default_code] = p.id
204+
if reference == "barcode":
205+
for p in product_ids:
206+
speedy_product_list[p.barcode] = p.id
194207
product_template_ids = self.env["product.template"].search([])
195208
speedy_product_template_list = {}
196209
for p in product_template_ids:
@@ -205,8 +218,7 @@ def product_import_generic(self):
205218
else:
206219
colonnes.append("empty")
207220
continue
208-
209-
if row[1]:
221+
if row[0]:
210222
line += 1
211223
vals["line"] = line
212224
for c in range(len(row)):
@@ -219,27 +231,29 @@ def product_import_generic(self):
219231
vals["product_tmpl_id"] = speedy_product_template_list[
220232
vals["ref_template"]
221233
]
222-
vals, variant_att, list_attribue_ids = self.check_vals_product(vals)
223-
if (
224-
not vals.get("product_tmpl_id")
225-
and vals["default_code"] in speedy_product_template_list
226-
):
227-
location_id = vals.get("location_id") or speedy.get(
228-
"default_location_id"
229-
)
230-
vals = import_obj._prepare_product_vals(vals, location_id, speedy)
231-
res = (
232-
self.env["product.template"]
233-
.browse(speedy_product_list[vals["default_code"]])
234-
.write(vals)
235-
)
236-
if res:
237-
logger.info(
238-
f"{res.display_name},id {res.id} has been update with line {line}"
239-
)
240-
else:
241-
logger.warning(f"line {line} have done nothing")
242-
elif vals["default_code"] in speedy_product_list:
234+
vals, variant_att, list_attribue_ids, template = (
235+
self.check_vals_product(vals)
236+
)
237+
# if (
238+
# not vals.get("product_tmpl_id")
239+
# and vals["default_code"] in speedy_product_template_list
240+
# ):
241+
# location_id = vals.get("location_id") or speedy.get(
242+
# "default_location_id"
243+
# )
244+
# vals = import_obj._prepare_product_vals(vals, location_id, speedy)
245+
# res = (
246+
# self.env["product.template"]
247+
# .browse(speedy_product_list[vals["default_code"]])
248+
# .write(vals)
249+
# )
250+
# if res:
251+
# logger.info(
252+
# f"{res.display_name},id {res.id} has been update with line {line}"
253+
# )
254+
# else:
255+
# logger.warning(f"line {line} have done nothing")
256+
if not template and vals.get(reference) in speedy_product_list:
243257
location_id = vals.get("location_id") or speedy.get(
244258
"default_location_id"
245259
)
@@ -255,7 +269,11 @@ def product_import_generic(self):
255269
)
256270
else:
257271
logger.warning(f"line {line} have done nothing")
258-
elif vals.get("product_tmpl_id"):
272+
elif (
273+
not template
274+
and vals.get(reference) not in speedy_product_list
275+
and vals.get("product_tmpl_id")
276+
):
259277
location_id = vals.get("location_id") or speedy.get(
260278
"default_location_id"
261279
)
@@ -274,7 +292,9 @@ def product_import_generic(self):
274292
vals["standard_price"]
275293
)
276294
p.write(vals)
277-
else:
295+
elif not template:
296+
res = import_obj._create_product(vals, speedy)
297+
elif template:
278298
location_id = vals.get("location_id") or speedy.get(
279299
"default_location_id"
280300
)
@@ -293,6 +313,8 @@ def product_import_generic(self):
293313
logger.info(f"{p_tmpl.id} has been create")
294314
else:
295315
logger.warning("nothing")
316+
else:
317+
logger.warning(f"NO PRODUCT IMPORTED line {line} Name {row[1]}")
296318
else:
297319
break
298320
action = import_obj._result_action(speedy)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#from . import product_attribute_value
1+
from . import product_attribute_value
22
from . import import_helper

product_import_helper/wizards/product_attribute_value.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ class ProductAttributeValue(models.Model):
1313
@api.depends("attribute_id.name", "name")
1414
def _compute_fullname(self):
1515
for record in self:
16-
record.fullname = f"{record.attribute_id.name} : {record.name}"
16+
record.fullname = f"{record.attribute_id.name} :{record.name}"

0 commit comments

Comments
 (0)