Skip to content

Commit 80131ad

Browse files
joa-adhocnicomacr
authored andcommitted
[UPD] base_bg,account_statement_import_sheet_file_bg: Update bg_enqueue method to include job reference and adapt AccountStatementImport enqueue usage
1 parent 66e2965 commit 80131ad

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

account_statement_import_sheet_file_bg/models/account_statement_import.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,15 @@ def import_file_button(self, wizard_data=None):
7171
"statement_filename": self.statement_filename,
7272
"sheet_mapping_id": self.sheet_mapping_id.id if self.sheet_mapping_id else False,
7373
}
74-
return self.env[self._name].bg_enqueue("import_file_button", wizard_data=wizard_data)
74+
res, _ = self.env[self._name].bg_enqueue("import_file_button", wizard_data=wizard_data)
75+
return res
7576
# No sheet_mapping_id, pass basic data
7677
wizard_data = {
7778
"statement_file": self.statement_file,
7879
"statement_filename": self.statement_filename,
7980
}
80-
return self.env[self._name].bg_enqueue("import_file_button", wizard_data=wizard_data)
81+
res, _ = self.env[self._name].bg_enqueue("import_file_button", wizard_data=wizard_data)
82+
return res
8183
else:
8284
# Running in background job - recreate wizard from passed data
8385
part_number = None

base_bg/models/base_bg.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BaseBg(models.AbstractModel):
1414
_description = "Background Job Mixin"
1515

1616
@api.model
17-
def bg_enqueue(self, method: str, *args, **kwargs):
17+
def bg_enqueue(self, method: str, *args, **kwargs) -> tuple[dict, models.BaseModel]:
1818
"""
1919
Enqueue a background job for execution.
2020
@@ -46,20 +46,23 @@ def bg_enqueue(self, method: str, *args, **kwargs):
4646
# Serialize arguments
4747
job_vals["args_json"] = list(args) if args else []
4848
job_vals["kwargs_json"] = kwargs
49-
self.env["bg.job"].create(job_vals)
49+
job = self.env["bg.job"].create(job_vals)
5050
self.sudo()._trigger_crons()
5151
title = _("Process sent to background successfully")
5252
message = _("You will be notified when it is done.")
53-
return {
54-
"type": "ir.actions.client",
55-
"tag": "display_notification",
56-
"params": {
57-
"title": title,
58-
"type": "success",
59-
"message": message,
60-
"next": {"type": "ir.actions.act_window_close"},
53+
return (
54+
{
55+
"type": "ir.actions.client",
56+
"tag": "display_notification",
57+
"params": {
58+
"title": title,
59+
"type": "success",
60+
"message": message,
61+
"next": {"type": "ir.actions.act_window_close"},
62+
},
6163
},
62-
}
64+
job,
65+
)
6366

6467
def _trigger_crons(self):
6568
"""

0 commit comments

Comments
 (0)