Coverage for ingadhoc-odoo-saas-adhoc / saas_provider_upgrade / models / bg_job.py: 35%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-09 18:05 +0000

1############################################################################## 

2# For copyright and license notices, see __manifest__.py file in module root 

3# directory 

4############################################################################## 

5 

6from typing import TYPE_CHECKING 

7 

8from odoo import models 

9 

10if TYPE_CHECKING: 

11 from ..models.saas_upgrade_line_request_run import SaasUpgradeLineRequestRun as UpgradeLineRequestRun 

12from ..exceptions import UpgradeLineException 

13 

14 

15class BgJob(models.Model): 

16 _inherit = "bg.job" 

17 

18 def _handle_job_error(self, error: Exception | str): 

19 """ 

20 Override to add custom error handling for 'saas.upgrade.line.request.run' jobs. 

21 """ 

22 if ( 

23 self.model == "saas.upgrade.line.request.run" 

24 and isinstance(error, UpgradeLineException) 

25 and not error.is_connection_error 

26 ): 

27 self.retry_count = self.max_retries # Prevent further if error is not a connection error 

28 super()._handle_job_error(error) 

29 

30 def fail(self, error_message: str, notify: bool = True): 

31 """ 

32 Override to add custom failure handling for 'saas.upgrade.line.request.run' jobs. 

33 """ 

34 if self.model == "saas.upgrade.line.request.run": 

35 rec: UpgradeLineRequestRun = self._get_records().with_user(self.create_uid) 

36 rec.ensure_one() 

37 rec.set_error(error_message) 

38 notify = False # Suppress notifications for this specific job type 

39 

40 super().fail(error_message, notify=notify)