Skip to content

Commit

Permalink
[FIX] base_import_async: remove default values from context when crea…
Browse files Browse the repository at this point in the history
…ting the attachment.

Some default values might be present in context depending on the action we came from
when clicking on 'import' button. These default values are not intended to
be default values for the ir.attachment record.
In some cases they cause an error because a field with the same name exists on
ir.attachment, as for e.g. the 'default_type'='opportunity' value
present in the standard crm.lead action context.
  • Loading branch information
marielejeune committed Apr 14, 2023
1 parent 0bf3a1a commit 48f41dd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions base_import_async/models/base_import_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,14 @@ def _create_csv_attachment(self, fields, data, options, file_name):
writer.writerow(fields)
for row in data:
writer.writerow(row)
# create attachment
# create attachment. Remove default values from context
context = self.env.context
context_copy = {}

Check warning on line 93 in base_import_async/models/base_import_import.py

View check run for this annotation

Codecov / codecov/patch

base_import_async/models/base_import_import.py#L92-L93

Added lines #L92 - L93 were not covered by tests
for key in context.keys():
if not key.startswith("default_"):
context_copy[key] = context[key]

Check warning on line 96 in base_import_async/models/base_import_import.py

View check run for this annotation

Codecov / codecov/patch

base_import_async/models/base_import_import.py#L96

Added line #L96 was not covered by tests
datas = base64.encodebytes(f.getvalue().encode(encoding))
attachment = self.env["ir.attachment"].create(
attachment = self.env["ir.attachment"].with_context(context_copy).create(

Check warning on line 98 in base_import_async/models/base_import_import.py

View check run for this annotation

Codecov / codecov/patch

base_import_async/models/base_import_import.py#L98

Added line #L98 was not covered by tests
{"name": file_name, "datas": datas}
)
return attachment
Expand Down

0 comments on commit 48f41dd

Please sign in to comment.