Merge lp:~jfb-tempo-consulting/unifield-web/US-6032 into lp:unifield-web

Proposed by jftempo
Status: Merged
Merged at revision: 4969
Proposed branch: lp:~jfb-tempo-consulting/unifield-web/US-6032
Merge into: lp:unifield-web
Diff against target: 129 lines (+77/-0)
1 file modified
addons/openerp/controllers/database.py (+77/-0)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-web/US-6032
Reviewer Review Type Date Requested Status
UniField Dev Team Pending
Review via email: mp+370757@code.launchpad.net
To post a comment you must log in.
4971. By jftempo

Auto instance create if auto patch true, check that auto sync is true

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/openerp/controllers/database.py'
2--- addons/openerp/controllers/database.py 2019-05-23 08:14:46 +0000
3+++ addons/openerp/controllers/database.py 2019-08-08 15:43:48 +0000
4@@ -41,6 +41,7 @@
5 from ConfigParser import NoOptionError, NoSectionError
6 import threading
7
8+TRUE_LIST = (True, 'True', 'true', 'TRUE', 'Yes', 'YES', 'yes')
9 def get_lang_list():
10 langs = [('en_US', 'English (US)')]
11 try:
12@@ -358,6 +359,27 @@
13 self.msg = {'message': ustr(_('The option \'%s\' from section \'[%s]\' have to be one of those values: %r. (currently it is \'%s\').') % (option, section, possible_values, value)),
14 'title': ustr(_('Wrong option'))}
15
16+ def check_date_time(self, config, section, option, time_format):
17+ if not config.has_option(section, option):
18+ return True
19+ value = config.get(section, option)
20+ if value:
21+ try:
22+ time.strptime(value, time_format)
23+ except:
24+ return False
25+ return True
26+
27+ def check_datetime(self, config, section, option):
28+ if not self.check_date_time(config, section, option, '%Y-%m-%d %H:%M'):
29+ self.msg = {'message': ustr(_('The option \'%s\' from section \'[%s]\' datetime format expected YYY-MM-DD HH:MM') % (option, section)),
30+ 'title': ustr(_('Wrong format'))}
31+
32+ def check_time(self, config, section, option):
33+ if not self.check_date_time(config, section, option, '%H:%M'):
34+ self.msg = {'message': ustr(_('The option \'%s\' from section \'[%s]\' time format expected HH:MM') % (option, section)),
35+ 'title': ustr(_('Wrong format'))}
36+
37 def check_config_file(self, file_path):
38 '''
39 perform some basic checks to avoid crashing later
40@@ -416,6 +438,8 @@
41 ('partner', 'external_account_payable'),
42 ('partner', 'internal_account_receivable'),
43 ('partner', 'internal_account_payable'),
44+ ('autosync', 'interval_nb'),
45+ ('stockmission', 'interval_nb'),
46 )
47 for section, option in not_empty_int_option_list:
48 self.check_mandatory_int(config, section, option)
49@@ -427,6 +451,8 @@
50 ('instance', 'instance_level', ('coordo', 'project')),
51 ('instance', 'lang', ('fr_MF', 'es_MF', 'en_MF')),
52 ('backup', 'auto_bck_interval_unit', ('minutes', 'hours', 'work_days', 'days', 'weeks', 'months')),
53+ ('autosync', 'interval_unit', ('minutes', 'hours', 'work_days', 'days', 'weeks', 'months')),
54+ ('stockmission', 'interval_unit', ('minutes', 'hours', 'work_days', 'days', 'weeks', 'months')),
55 ('reconfigure', 'delivery_process', ('complex', 'simple')),
56 )
57 for section, option, possible_values in possible_value_list:
58@@ -434,6 +460,19 @@
59 if self.msg:
60 return
61
62+ check_format = [
63+ ('backup', 'auto_bck_next_exec_date', self.check_datetime),
64+ ('autosync', 'next_exec_date', self.check_datetime),
65+ ('stockmission', 'next_exec_date', self.check_datetime),
66+ ('silentupgrade', 'hour_from', self.check_time),
67+ ('silentupgrade', 'hour_to', self.check_time),
68+
69+ ]
70+ for section, option, check_fct in check_format:
71+ check_fct(config, section, option)
72+ if self.msg:
73+ return
74+
75 if config.get('instance', 'instance_level') == 'project':
76 if len(config.get('instance', 'group_names').split(',')) != 3:
77 self.msg = {
78@@ -462,6 +501,27 @@
79 }
80 return
81
82+ # silent uprade True only if autosync True
83+ if (not config.has_option('silentupgrade', 'active') or config.get('silentupgrade', 'active') in TRUE_LIST) and config.has_option('autosync', 'active') and config.get('autosync', 'active') not in TRUE_LIST:
84+ self.msg = {
85+ 'message': _('Silent Upgrade active value and Autosync active value are not consistent '),
86+ 'title': _('Auto sync / silent upgrade'),
87+ }
88+ return
89+
90+ # check date betweens auto patch and sync scheduler
91+ if config.has_option('autosync', 'next_exec_date') and config.has_option('silentupgrade', 'hour_to') and config.has_option('silentupgrade', 'hour_from'):
92+ if (not config.has_option('autosync', 'active') or config.get('autosync', 'active') in TRUE_LIST) and (not config.has_option('silentupgrade', 'active') or config.get('silentupgrade', 'active') in TRUE_LIST):
93+ time_from = time.strptime(config.get('silentupgrade', 'hour_from'), '%H:%M')
94+ time_to = time.strptime(config.get('silentupgrade', 'hour_to'), '%H:%M')
95+ if not server_rpc.execute('object', 'execute', 'sync.client.sync_server_connection', 'is_automatic_patching_allowed',
96+ config.get('autosync', 'next_exec_date'), True, time_from.tm_hour + time_from.tm_min/60. , time_to.tm_hour + time_to.tm_min/60.
97+ ):
98+ self.msg = {
99+ 'message': _('"Scheduler autosync next date" and "Silent Upgrade interval" are not consistent'),
100+ 'title': _('Auto sync / silent upgrade'),
101+ }
102+ return
103 config_groups = config.get('instance', 'group_names').split(',')
104 found_group = []
105 groups_ids = server_rpc.execute('object', 'execute', 'sync.server.entity_group', 'search', [('name', 'in', config_groups)])
106@@ -495,6 +555,23 @@
107 }
108 return
109
110+ import_path = os.path.join(os.path.dirname(file_path), 'import')
111+ if os.path.exists(import_path):
112+ for file_name in os.listdir(import_path):
113+ if not file_name.endswith('.csv'):
114+ self.msg = {
115+ 'message': 'File to import %s: incorrect name (must end with .csv:' % file_name,
116+ 'title': 'File name error',
117+ }
118+ return
119+ import_object = file_name.split('.csv')[0]
120+ if not server_rpc.execute('object', 'execute', 'ir.model', 'search', [('model', '=', import_object)]):
121+ self.msg = {
122+ 'message': 'File to import %s: incorrect name object %s does not exist' % (file_name, import_object),
123+ 'title': 'File name error',
124+ }
125+ return
126+
127
128 except NoOptionError as e:
129 self.msg = {'message': ustr(_('No option \'%s\' found for the section \'[%s]\' in the config file \'%s\'') % (e.option, e.section, file_path)),

Subscribers

People subscribed via source and target branches