1
1
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>)
2
2
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3
3
4
- from odoo import fields , models
4
+ from odoo import fields , models , api
5
5
6
6
7
7
class ImportPatternWizard (models .TransientModel ):
@@ -14,6 +14,15 @@ class ImportPatternWizard(models.TransientModel):
14
14
_name = "import.pattern.wizard"
15
15
_description = "Import pattern wizard"
16
16
17
+ def _get_model (self ):
18
+ model_name = self .env .context .get ('active_model' )
19
+ active_id = self .env .context .get ('active_id' )
20
+ if model_name == "pattern.config" :
21
+ pattern_config = self .env [model_name ].browse (active_id )
22
+ model_name = pattern_config .resource
23
+ return model_name
24
+
25
+
17
26
pattern_config_id = fields .Many2one (
18
27
comodel_name = "pattern.config" ,
19
28
string = "Import pattern" ,
@@ -23,7 +32,15 @@ class ImportPatternWizard(models.TransientModel):
23
32
)
24
33
import_file = fields .Binary (string = "File to import" , required = True )
25
34
filename = fields .Char ()
35
+ model = fields .Char (default = _get_model )
36
+ no_import_pattern = fields .Boolean (compute = "_compute_no_import_pattern" )
26
37
38
+ @api .depends ("model" )
39
+ def _compute_no_import_pattern (self ):
40
+ for wiz in self :
41
+ wiz .no_import_pattern = not wiz .env ["pattern.config" ].search_count (
42
+ [("resource" , "=" , wiz .model )]
43
+ )
27
44
def action_launch_import (self ):
28
45
"""
29
46
0 commit comments