Merge lp:~jfb-tempo-consulting/unifield-server/US-9570 into lp:unifield-server

Proposed by jftempo
Status: Needs review
Proposed branch: lp:~jfb-tempo-consulting/unifield-server/US-9570
Merge into: lp:unifield-server
Diff against target: 83 lines (+55/-1)
2 files modified
bin/addons/msf_profile/data/patches.xml (+4/-0)
bin/addons/msf_profile/msf_profile.py (+51/-1)
To merge this branch: bzr merge lp:~jfb-tempo-consulting/unifield-server/US-9570
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+415725@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/msf_profile/data/patches.xml'
2--- bin/addons/msf_profile/data/patches.xml 2022-02-14 08:43:31 +0000
3+++ bin/addons/msf_profile/data/patches.xml 2022-02-17 09:56:09 +0000
4@@ -749,5 +749,9 @@
5 <record id="us_9143_oca_change_dest_on_esc_po" model="patch.scripts">
6 <field name="method">us_9143_oca_change_dest_on_esc_po</field>
7 </record>
8+
9+ <record id="us_9570_ocb_auto_sync_time" model="patch.scripts">
10+ <field name="method">us_9570_ocb_auto_sync_time</field>
11+ </record>
12 </data>
13 </openerp>
14
15=== modified file 'bin/addons/msf_profile/msf_profile.py'
16--- bin/addons/msf_profile/msf_profile.py 2022-02-16 10:03:13 +0000
17+++ bin/addons/msf_profile/msf_profile.py 2022-02-17 09:56:09 +0000
18@@ -38,7 +38,9 @@
19 import cStringIO
20 import csv
21 import zlib
22-
23+import random
24+from datetime import datetime
25+from dateutil.relativedelta import relativedelta
26
27 class patch_scripts(osv.osv):
28 _name = 'patch.scripts'
29@@ -55,6 +57,54 @@
30 }
31
32 # UF24.0
33+ def us_9570_ocb_auto_sync_time(self, cr, uid, *a, **b):
34+ entity_obj = self.pool.get('sync.client.entity')
35+ if entity_obj and entity_obj.get_entity(cr, uid).oc == 'ocb':
36+ cr.execute("SAVEPOINT us_9570")
37+ cron_obj = self.pool.get('ir.cron')
38+ cron_dom = [('model', '=', 'sync.client.entity'), ('function', '=', 'sync_threaded')]
39+ cron_id = cron_obj.search(cr, uid, cron_dom + [('active', 'in', ['t', 'f'])])
40+ if not cron_id:
41+ self.log_info(cr, uid, 'US-9570: patch not applied, cron job not found !')
42+ return True
43+ if len(cron_id) > 1:
44+ cron_id = cron_obj.search(cr, uid, cron_dom + [('active', '=', True)])
45+ if not cron_id or len(cron_id) > 1:
46+ self.log_info(cr, uid, 'US-9570: patch not applied, multiple cron found !')
47+ return True
48+
49+ cron = cron_obj.browse(cr, uid, cron_id[0])
50+ if cron.interval_number == 12 and cron.interval_type == 'hours':
51+ nextcall = datetime.strptime(cron.nextcall, '%Y-%m-%d %H:%M:%S')
52+ if 7 * 60 <= nextcall.hour * 60 + nextcall.minute < 9 * 60 or \
53+ 19 * 60 <= nextcall.hour * 60 + nextcall.minute < 21 * 60:
54+ self.log_info(cr, uid, 'US-9570: patch not applied, conditions already met')
55+ return True
56+
57+ now = datetime.now()
58+ minute = random.randint(1, 59)
59+ if now.hour < 5:
60+ hour = random.randint(7 , 8)
61+ days = 0 # same day
62+ elif now.hour < 17:
63+ hour = random.randint(19 ,20)
64+ days = 0 # same day
65+ else:
66+ hour = random.randint(7 , 8)
67+ days = 1 # next day
68+
69+ cr.execute('update sync_client_sync_server_connection set automatic_patching_hour_from=19, automatic_patching_hour_to=8')
70+ nextcall_to_set = (now+relativedelta(hour=hour, minute=minute, days=days)).strftime('%Y-%m-%d %H:%M:%S')
71+ try:
72+ cron_obj.write(cr, uid, cron.id, {'nextcall': nextcall_to_set, 'interval_number': 12, 'interval_type': 'hours'})
73+ self.log_info(cr, uid, 'US-9570: patch applied %s' % nextcall_to_set)
74+ except:
75+ cr.execute("ROLLBACK TO SAVEPOINT us_9570")
76+ self.log_info(cr, uid, 'US-9570: patch not applied, error during save !')
77+
78+ return True
79+
80+
81 def us_9577_display_manual_cv(self, cr, uid, *a, **b):
82 cr.execute("UPDATE account_commitment SET cv_flow_type='supplier' WHERE cv_flow_type IS NULL")
83 self.log_info(cr, uid, '%d manual CV visible' % (cr.rowcount,))

Subscribers

People subscribed via source and target branches