Coverage for ingadhoc-odoo-saas-adhoc / saas_provider_upgrade / models / major_version_change.py: 55%

41 statements  

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

1from odoo import _, api, fields, models 

2from odoo.exceptions import ValidationError 

3 

4 

5class MajorVersionChange(models.Model): 

6 _name = "major.version.change" 

7 _description = "Major Version Change" 

8 _inherit = ["mail.thread", "mail.activity.mixin"] 

9 

10 model_type = fields.Selection( 

11 [ 

12 ("field", "Field"), 

13 ("model", "Model"), 

14 ("selection_value", "Selection Value"), 

15 ("method", "Method"), 

16 ("xmlid", "XMLID"), 

17 ], 

18 required=True, 

19 ) 

20 change_type = fields.Selection( 

21 [ 

22 ("add", "Add"), 

23 ("remove", "Remove"), 

24 ("rename", "Rename"), 

25 ("upgrade", "Upgrade"), 

26 ("change_type", "Change Type"), 

27 ], 

28 required=True, 

29 help=""" 

30 add: New field/model/selection_value/method/xmlid 

31 remove: Field/model/selection_value/method/xmlid removed 

32 rename: field/model/selection_value/method renamed 

33 upgrade: Only for XML records with 'no_update=1' that changed 

34 change_type: Field type changed (e.g. Char to Selection) 

35 """, 

36 ) 

37 old_name = fields.Char(copy=False) 

38 new_name = fields.Char(copy=False) 

39 notes = fields.Html() 

40 major_version_id = fields.Many2one( 

41 "saas.odoo.major_version", 

42 required=True, 

43 ondelete="cascade", 

44 ) 

45 model = fields.Char() 

46 field = fields.Char() 

47 adhoc_module_id = fields.Many2one("adhoc.module.module") 

48 adhoc_product_id = fields.Many2one( 

49 "adhoc.product", 

50 compute="_compute_adhoc_product", 

51 store=True, 

52 readonly=False, 

53 domain=[("parent_id", "!=", False), ("type", "=", "horizontal")], 

54 ) 

55 

56 _unique_record_per_group = models.Constraint( 

57 "UNIQUE(major_version_id, model_type, model, field, change_type, old_name, new_name)", 

58 "A record with this name and model already exists for this version", 

59 ) 

60 

61 @api.depends("adhoc_module_id.adhoc_product_id") 

62 def _compute_adhoc_product(self) -> None: 

63 for rec in self.filtered("adhoc_module_id.adhoc_product_id"): 

64 rec.adhoc_product_id = rec.adhoc_module_id.adhoc_product_id 

65 

66 @api.constrains("model_type", "change_type") 

67 def _check_required_fields(self) -> None: 

68 for rec in self: 

69 if rec.model_type != "xmlid" and rec.change_type == "upgrade": 69 ↛ 70line 69 didn't jump to line 70 because the condition on line 69 was never true

70 raise ValidationError(_("'Upgrade' change_type is only valid for model_type 'xmlid'")) 

71 if rec.model_type != "field" and rec.change_type == "change_type": 71 ↛ 72line 71 didn't jump to line 72 because the condition on line 71 was never true

72 raise ValidationError(_("'Change_type' change_type is only valid for model_type 'field'")) 

73 

74 def name_get(self) -> list: 

75 if not self.ids: 

76 return [] 

77 result = [] 

78 for rec in self: 

79 name = f"[{rec.major_version_id.name}][{str(rec.change_type)[:3].upper()}] {rec.model or ''}: {rec.old_name or ''} - {rec.new_name or ''}" 

80 if not rec.old_name or not rec.new_name: 

81 name = name.replace(" - ", "") 

82 name = name.replace(" : ", " ") 

83 result.append((rec.id, name)) 

84 return result 

85 

86 def open_module_repository(self) -> dict: 

87 return self.adhoc_module_id.repository_id.open_repository()