diff --git a/lighting_export_xlsx/models/product_attachment.py b/lighting_export_xlsx/models/product_attachment.py index a75c94eb..fe788b12 100644 --- a/lighting_export_xlsx/models/product_attachment.py +++ b/lighting_export_xlsx/models/product_attachment.py @@ -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( diff --git a/lighting_export_xlsx/report/export_product_xlsx.py b/lighting_export_xlsx/report/export_product_xlsx.py index af393e8a..54bb414c 100644 --- a/lighting_export_xlsx/report/export_product_xlsx.py +++ b/lighting_export_xlsx/report/export_product_xlsx.py @@ -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 = [] @@ -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: