Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lighting_export_xlsx/models/product_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ def export_xlsx(self, template_id=None):
for pa in prod_attachment_ids:
if not pa.public:
pa.sudo().public = True
type_meta = pa.fields_get(["type_id"], ["string"])["type_id"]
pa.fields_get(["type_id"], ["string"])["type_id"]
res.append(
OrderedDict(
[
(type_meta["string"], pa.type_id.display_name),
("URL", pa.url_get(resolution=ta.resolution)),
(
pa.type_id.display_name,
pa.url_get(resolution=ta.resolution),
),
]
)
)
Expand Down
40 changes: 19 additions & 21 deletions lighting_export_xlsx/report/export_product_xlsx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright NuoBiT Solutions - Eric Antones <[email protected]>
# Copyright NuoBiT Solutions - Kilian Niubo <[email protected]>
# Copyright NuoBiT Solutions 2025 - Bijaya Kumal <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import logging

Expand Down Expand Up @@ -32,6 +33,7 @@ def generate_xlsx_report_ctx(self, workbook, data, objects):
objects = self.env[active_model].search(active_domain)
else:
objects = self.env["lighting.product"].browse(data.get("active_ids"))

if data.get("exclude_configurator"):
objects = objects.filtered(lambda x: not x.configurator)

Expand Down Expand Up @@ -90,35 +92,33 @@ def generate_xlsx_report_ctx(self, workbook, data, objects):
row += 1

def _get_meta_num(self, meta, datum, obj_d):
subfields = []
pass

for j, sf in enumerate(datum, 1):
# update x in headers
sf1 = list(sf.keys())
if subfields:
if set(subfields) != set(sf1):
raise Exception("Unexpected Error")
else:
subfields = sf1
if not isinstance(sf, dict) or not sf:
continue
field_name, exportable_value = next(iter(sf.items()))
column_name = f"Attachment{j}/{field_name}"

fnam = "%s%i" % (meta["string"], j)
for k, v in sf.items():
sfkey = "%s/%s" % (fnam, k)
if sfkey in obj_d:
raise Exception("The subfield '%s' is duplicated" % sfkey)
obj_d[sfkey] = v
if column_name in obj_d:
raise Exception(f"The column '{column_name}' already exists")

if not meta["subfields"]:
meta["subfields"] = []
if sfkey not in meta["subfields"]:
meta["subfields"].append(sfkey)
obj_d[column_name] = exportable_value

return max(meta["num"], len(datum)), obj_d
if not meta.get("subfields"):
meta["subfields"] = []
if column_name not in meta["subfields"]:
meta["subfields"].append(column_name)

meta["num"] = max(meta["num"], len(datum))
return meta["num"], obj_d

def _generate_products(self, header, object_ids, template_id):
n = len(object_ids)
_logger.info("Generating %i products..." % n)
th = int(n / 100) or 1
objects_ld = []

for i, obj_id in enumerate(object_ids, 1):
obj = self.env["lighting.product"].browse(obj_id)
obj_d = {}
Expand All @@ -142,9 +142,7 @@ def _generate_products(self, header, object_ids, template_id):
datum = None

if isinstance(datum, (tuple, list)):

meta["num"], obj_d = self._get_meta_num(meta, datum, obj_d)

else:
fkey = meta["string"]
if fkey in obj_d:
Expand Down