Merge lp:~unifield-team/unifield-server/us-1262 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merge reported by: jftempo
Merged at revision: not available
Proposed branch: lp:~unifield-team/unifield-server/us-1262
Merge into: lp:unifield-server
Diff against target: 171 lines (+61/-10)
3 files modified
bin/addons/mission_stock/mission_stock.py (+17/-5)
bin/addons/mission_stock/mission_stock_view.xml (+4/-2)
bin/addons/mission_stock/wizard/mission_stock_wizard.py (+40/-3)
To merge this branch: bzr merge lp:~unifield-team/unifield-server/us-1262
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+294399@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/mission_stock/mission_stock.py'
2--- bin/addons/mission_stock/mission_stock.py 2016-04-14 17:10:49 +0000
3+++ bin/addons/mission_stock/mission_stock.py 2016-05-11 16:11:58 +0000
4@@ -49,6 +49,13 @@
5
6 _columns = {
7 'report_id': fields.many2one('stock.mission.report', "Report"),
8+ 'done_ok': fields.boolean(string='Processing done'),
9+ 'start_date': fields.datetime(string='Start date'),
10+ }
11+
12+ _defaults = {
13+ 'done_ok': lambda *a: False,
14+ 'start_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
15 }
16
17 def create(self, cr, uid, ids, context=None):
18@@ -59,7 +66,7 @@
19 return
20
21 def _already_processed(self, cr, uid, id, context=None):
22- report_ids = self.search(cr, 1, [('report_id', '=', id)], context=context)
23+ report_ids = self.search(cr, 1, [('report_id', '=', id), ('done_ok', '=', True)], context=context)
24 if report_ids:
25 return True
26 return False
27@@ -236,6 +243,12 @@
28 if context.get('update_full_report'):
29 report_ids = full_report_ids
30
31+ if not context.get('update_full_report'):
32+ all_report_ids = report_ids + full_report_ids
33+ for report_id in all_report_ids:
34+ # register immediately this report id into the table temp
35+ msr_in_progress.create(cr, uid, report_id, context)
36+
37 product_ids = self.pool.get('product.product').search(cr, uid, [], context=context)
38 product_values = {}
39 temp_prods = self.pool.get('product.product').read(cr, uid, product_ids, ['product_amc', 'reviewed_consumption'], context=context)
40@@ -264,8 +277,6 @@
41 #US-1218: If this report is previously processed, then do not redo it again for this transaction!
42 if msr_in_progress._already_processed(cr, uid, report['id'], context):
43 continue
44- # register immediately this report id into the table temp
45- msr_in_progress.create(cr, uid, report['id'], context)
46
47 logging.getLogger('MSR').info("""___ updating the report lines of the report: %s, at %s (this may take very long time!)""" % (report['id'], time.strftime('%Y-%m-%d %H:%M:%S')))
48 if context.get('update_full_report'):
49@@ -277,14 +288,15 @@
50 # Update all lines
51 self.update_lines(cr, uid, [report['id']])
52
53- self.write(cr, uid, [report['id']], {'export_ok': False}, context=context)
54+ msr_ids = msr_in_progress.search(cr, uid, [('report_id', '=', report['id'])], context=context)
55+ msr_in_progress.write(cr, uid, msr_ids, {'done_ok': True}, context=context)
56+
57 logging.getLogger('MSR').info("""___ exporting the report lines of the report %s to csv, at %s""" % (report['id'], time.strftime('%Y-%m-%d %H:%M:%S')))
58 self._get_export_csv(cr, uid, report['id'], product_values, context=context)
59 # Update the update date on report
60 self.write(cr, uid, [report['id']], {'last_update': time.strftime('%Y-%m-%d %H:%M:%S')}, context=context)
61 logging.getLogger('MSR').info("""___ finished processing completely for the report: %s, at %s \n""" % (report['id'], time.strftime('%Y-%m-%d %H:%M:%S')))
62
63-
64 # After update of all normal reports, update the full view report
65 if not context.get('update_full_report'):
66 c = context.copy()
67
68=== modified file 'bin/addons/mission_stock/mission_stock_view.xml'
69--- bin/addons/mission_stock/mission_stock_view.xml 2014-03-20 15:48:04 +0000
70+++ bin/addons/mission_stock/mission_stock_view.xml 2016-05-11 16:11:58 +0000
71@@ -12,6 +12,8 @@
72 <separator colspan="4" string="Mission stock" />
73 <field name="report_id" widget="selection" on_change="report_change(report_id)" />
74 <field name="last_update" />
75+ <label colspan="2" />
76+ <field name="processed_value" string="Updating..." />
77 <separator colspan="4" string="Stock valuation" />
78 <field name="with_valuation" />
79 <separator colspan="4" string="Split Stock" />
80@@ -19,8 +21,8 @@
81 <separator colspan="4" string="Actions" />
82 <button name="update" string="Update (in background)" type="object" colspan="4" icon="gtk-remove" />
83 <button special="cancel" string="Close window" icon="gtk-cancel" />
84- <button name="open_xml_file" string="Open XML file" type="object" icon="gtk-print" colspan="1" attrs="{'readonly': [('export_ok', '=', False)]}" />
85- <button name="open_products_view" string="Open report" type="object" icon="gtk-go-forward" colspan="2" />
86+ <button name="open_xml_file" string="Open XML file" type="object" icon="gtk-print" colspan="1" attrs="{'readonly': ['|', ('processed_value', '!=', 'Done'), ('export_ok', '=', False)]}" />
87+ <button name="open_products_view" string="Open report" type="object" icon="gtk-go-forward" colspan="2" attrs="{'readonly': [('processed_value', '!=', 'Done')]}" />
88 </form>
89 </field>
90 </record>
91
92=== modified file 'bin/addons/mission_stock/wizard/mission_stock_wizard.py'
93--- bin/addons/mission_stock/wizard/mission_stock_wizard.py 2014-04-09 09:21:40 +0000
94+++ bin/addons/mission_stock/wizard/mission_stock_wizard.py 2016-05-11 16:11:58 +0000
95@@ -28,6 +28,32 @@
96 class mission_stock_wizard(osv.osv_memory):
97 _name = 'mission.stock.wizard'
98
99+ def _get_processed_value(self, cr, uid, report_id, context=None, state=False):
100+ """
101+ Returns the progression of the update
102+ :param cr: Cursor to the database
103+ :param uid: ID of the res.users that calls this method
104+ :param report_id: ID of mission.stock.report to compute
105+ :param context: Context of the call
106+ :return: The percentage of processed lines
107+ """
108+ msr_in_progress = self.pool.get('msr_in_progress')
109+ date_tools = self.pool.get('date.tools')
110+
111+ if context is None:
112+ context = {}
113+
114+ if msr_in_progress._already_processed(cr, 1, report_id, context=context):
115+ return state and 'done' or _('Done')
116+
117+ msr_ids = msr_in_progress.search(cr, 1, [('report_id', '=', report_id)], context=context)
118+ if msr_ids:
119+ st_date = date_tools.get_date_formatted(cr, uid, d_type='datetime',
120+ datetime=msr_in_progress.browse(cr, uid, msr_ids[0], context=context).start_date)
121+ return state and 'progress' or _('In progress since %s') % st_date
122+
123+ return state and 'done' or _('Done')
124+
125 _columns = {
126 'report_id': fields.many2one(
127 'stock.mission.report',
128@@ -56,12 +82,18 @@
129 string='Filename',
130 size=256,
131 ),
132+ 'processed_value': fields.char(
133+ string='Processing',
134+ size=128,
135+ readonly=True,
136+ ),
137 }
138
139 _defaults = {
140 'with_valuation': lambda *a: 'false',
141 'split_stock': lambda *a: 'false',
142 'fname': lambda *a: 'Mission stock report',
143+ 'processed_value': lambda *a: _('Not started'),
144 }
145
146 def default_get(self, cr, uid, fields_list, context=None):
147@@ -79,7 +111,8 @@
148 res['report_id'] = local_id[0]
149 report = self.pool.get('stock.mission.report').browse(cr, uid, local_id[0], context=context)
150 res['last_update'] = report.last_update
151- res['export_ok'] = report.export_ok
152+ res['export_ok'] = report.export_ok and self._get_processed_value(cr, uid, local_id[0], context=context, state=True) == 'done'
153+ res['processed_value'] = self._get_processed_value(cr, uid, local_id[0], context=context)
154
155 return res
156
157@@ -90,9 +123,13 @@
158 v = {}
159 if report_id:
160 report = self.pool.get('stock.mission.report').browse(cr, uid, report_id, context=context)
161- v.update({'last_update': report.last_update, 'export_ok': report.export_ok})
162+ v.update({
163+ 'last_update': report.last_update,
164+ 'export_ok': report.export_ok and self._get_processed_value(cr, uid, report_id, context=context, state=True) == 'done',
165+ 'processed_value': self._get_processed_value(cr, uid, report_id, context=context)
166+ })
167 else:
168- v.update({'last_update': False, 'export_ok': False})
169+ v.update({'last_update': False, 'export_ok': False, 'processed_value': _('No report selected')})
170
171 return {'value': v}
172

Subscribers

People subscribed via source and target branches

to all changes: