Skip to content
Merged
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
6 changes: 5 additions & 1 deletion lighting_export_xlsx/models/product_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def export_xlsx(self, template_id=None):
if prod_attachment_ids.mapped("attachment_id"):
non_public = prod_attachment_ids.filtered(lambda x: not x.public)
if non_public:
non_public.sudo().write({"public": True})
ids_list = self.env.context.get("non_public_attachment_ids")
if ids_list is not None:
ids_list.extend(non_public.ids)
else:
non_public.sudo().write({"public": True})
for pa in prod_attachment_ids:
res.append(
OrderedDict(
Expand Down
12 changes: 11 additions & 1 deletion lighting_export_xlsx/report/export_product_xlsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def generate_xlsx_report_ctx(self, workbook, data, objects): # noqa: C901
self._check_duplicate_labels(header, template_id)

# generate data and gather header data
objects_ld = self._generate_products(header, objects.ids, template_id)
non_public_ids = []
objects_ld = self.with_context(
non_public_attachment_ids=non_public_ids
)._generate_products(header, objects.ids, template_id)

# generate xlsx headers according to data
xlsx_header = []
Expand Down Expand Up @@ -108,6 +111,13 @@ def generate_xlsx_report_ctx(self, workbook, data, objects): # noqa: C901
col += 1
row += 1

# make exported attachments public (single write at the end to avoid
# concurrent access issues during batch processing)
if non_public_ids:
self.env["lighting.attachment"].sudo().browse(non_public_ids).write(
{"public": True}
)

def _check_duplicate_labels(self, header, template_id):
seen_labels = {}
for field, meta in header:
Expand Down
Loading