Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(18)

Delta Between Two Patch Sets: work.py

Issue 91043: Work - request relation, m2m implementation (Closed)
Left Patch Set: Modifified wrt to comments Created 5 months ago
Right Patch Set: Use IN_MAX for computing requests field. Removed needless to_delete. Created 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #This file is part of Tryton. The COPYRIGHT file at the top level of 1 #This file is part of Tryton. The COPYRIGHT file at the top level of
2 #this repository contains the full copyright notices and license terms. 2 #this repository contains the full copyright notices and license terms.
3 3
4 from trytond.model import ModelView, ModelSQL, fields 4 from trytond.model import ModelView, ModelSQL, fields
5 from trytond.wizard import Wizard 5 from trytond.wizard import Wizard
6 from datetime import datetime, timedelta 6 from datetime import datetime, timedelta
7 from collections import deque, defaultdict 7 from collections import deque, defaultdict
8 from heapq import heappop, heappush 8 from heapq import heappop, heappush
9 9
10 def intfloor(x): 10 def intfloor(x):
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 type='date', string='Actual Start', fnct_inv='set_function_fields') 55 type='date', string='Actual Start', fnct_inv='set_function_fields')
56 actual_finish_date = fields.Function('get_function_fields', 56 actual_finish_date = fields.Function('get_function_fields',
57 type='date', string='Actual Finish', fnct_inv='set_function_fields') 57 type='date', string='Actual Finish', fnct_inv='set_function_fields')
58 constraint_start_date = fields.Function('get_function_fields', 58 constraint_start_date = fields.Function('get_function_fields',
59 type='date', string='Constraint Start', depends=[ 'type'], 59 type='date', string='Constraint Start', depends=[ 'type'],
60 fnct_inv='set_function_fields') 60 fnct_inv='set_function_fields')
61 constraint_finish_date = fields.Function('get_function_fields', 61 constraint_finish_date = fields.Function('get_function_fields',
62 type='date', string='Constraint Finish', depends=[ 'type'], 62 type='date', string='Constraint Finish', depends=[ 'type'],
63 fnct_inv='set_function_fields') 63 fnct_inv='set_function_fields')
64 requests = fields.Function('get_function_fields', type='many2many', 64 requests = fields.Function('get_function_fields', type='many2many',
65 string='Requests', fnct_inv='set_function_fields', 65 string='Requests', fnct_inv='set_function_fields',
ced 2009/07/03 17:21:43 I think it is better to use a widget one2many in v
66 relation='res.request') 66 relation='res.request')
67 67
68 def __init__(self): 68 def __init__(self):
69 super(Work, self).__init__() 69 super(Work, self).__init__()
70 self._constraints += [ 70 self._constraints += [
71 ('check_recursion', 'recursive_dependency'), 71 ('check_recursion', 'recursive_dependency'),
72 ] 72 ]
73 self._error_messages.update({ 73 self._error_messages.update({
74 'recursive_dependency': 'You can not create recursive ' 74 'recursive_dependency': 'You can not create recursive '
75 'dependencies!', 75 'dependencies!',
(...skipping 15 matching lines...) Expand all
91 :param context: the context 91 :param context: the context
92 :return: a dictionary with all field names as key and 92 :return: a dictionary with all field names as key and
93 a dictionary as value with id as key 93 a dictionary as value with id as key
94 ''' 94 '''
95 req_ref_obj = self.pool.get('res.request.reference') 95 req_ref_obj = self.pool.get('res.request.reference')
96 96
97 res = {} 97 res = {}
98 98
99 if 'requests' in names: 99 if 'requests' in names:
100 requests = dict((i, []) for i in ids) 100 requests = dict((i, []) for i in ids)
101 req_ref_ids = req_ref_obj.search(cursor, user, [ 101
102 ('reference', 'in', ['project.work,%s' % i for i in ids]), 102 for i in range(0, len(ids), cursor.IN_MAX):
ced 2009/07/03 17:21:43 You should create a loop with cursor.IN_MAX for lo
103 ], context=context) 103 sub_ids = ids[i:i + cursor.IN_MAX]
104 req_refs = req_ref_obj.browse(cursor, user, req_ref_ids, 104
105 context=context) 105 req_ref_ids = req_ref_obj.search(cursor, user, [
106 for req_ref in req_refs: 106 ('reference', 'in', [
107 _, work_id = req_ref.reference.split(',') 107 'project.work,%s' % i for i in sub_ids
108 requests[int(work_id)].append(req_ref.request.id) 108 ]
109 ),
110 ], context=context)
111 req_refs = req_ref_obj.browse(cursor, user, req_ref_ids,
112 context=context)
113 for req_ref in req_refs:
114 _, work_id = req_ref.reference.split(',')
115 requests[int(work_id)].append(req_ref.request.id)
109 116
110 res['requests'] = requests 117 res['requests'] = requests
111 118
112 if 'duration' in names: 119 if 'duration' in names:
113 all_ids = self.search(cursor, user, [ 120 all_ids = self.search(cursor, user, [
114 ('parent', 'child_of', ids), 121 ('parent', 'child_of', ids),
115 ('active', '=', True)], context=context) + ids 122 ('active', '=', True)], context=context) + ids
116 all_ids = list(set(all_ids)) 123 all_ids = list(set(all_ids))
117 124
118 works = self.browse(cursor, user, all_ids, context=context) 125 works = self.browse(cursor, user, all_ids, context=context)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 context=None): 179 context=None):
173 request_obj = self.pool.get('res.request') 180 request_obj = self.pool.get('res.request')
174 req_ref_obj = self.pool.get('res.request.reference') 181 req_ref_obj = self.pool.get('res.request.reference')
175 182
176 if name == 'requests': 183 if name == 'requests':
177 work = self.browse(cursor, user, id, context=context) 184 work = self.browse(cursor, user, id, context=context)
178 currents = dict((req.id, req) for req in work.requests) 185 currents = dict((req.id, req) for req in work.requests)
179 for v in value: 186 for v in value:
180 to_unlink = [] 187 to_unlink = []
181 to_link = [] 188 to_link = []
182 to_delete = []
183 operator = v[0] 189 operator = v[0]
190
184 ids = len(v) > 1 and v[1] or [] 191 ids = len(v) > 1 and v[1] or []
185 if operator == 'set': 192 if operator == 'set':
ced 2009/07/03 17:21:43 I think it should be better to have the same behav
bch 2009/07/06 08:50:42 On 2009/07/03 17:21:43, ced wrote: > I think it sh
ced 2009/07/06 09:02:11 Exactly, we must have the same behavior.
186 to_link.extend((i for i in ids if i not in currents)) 193 to_link.extend((i for i in ids if i not in currents))
187 to_unlink.extend((i for i in currents if i not in ids)) 194 to_unlink.extend((i for i in currents if i not in ids))
188 elif operator == 'add': 195 elif operator == 'add':
189 to_link.extend((i for i in ids if i not in currents)) 196 to_link.extend((i for i in ids if i not in currents))
190 elif operator == 'unlink': 197 elif operator == 'unlink':
191 to_unlink.extend((i for i in ids if i in currents)) 198 to_unlink.extend((i for i in ids if i in currents))
192 elif operator == 'unlink_all': 199 elif operator == 'unlink_all':
193 to_unlink.extend(currents) 200 to_unlink.extend(currents)
194 elif operator == 'delete': 201 elif operator == 'delete':
195 to_delete.extend((i for i in ids if i in currents)) 202 request_obj.delete(cursor, user, to_delete, context=context)
196 else: 203 else:
197 raise Exception('Operation not supported') 204 raise Exception('Operation not supported')
198 205
199 if to_delete: 206 req_ref_ids = []
200 request_obj.delete(cursor, user, to_delete, context=context) 207 for i in to_unlink:
201 208 request = currents[i]
202 if to_unlink: 209 for ref in request.references:
203 req_ref_ids = [] 210 if int(ref.reference.split(',')[1]) == id:
204 for i in to_unlink: 211 req_ref_ids.append(ref.id)
205 request = currents[i] 212 req_ref_obj.delete(cursor, user, req_ref_ids,
206 for ref in request.references: 213 context=context)
207 if int(ref.reference.split(',')[1]) == id: 214
208 req_ref_ids.append(ref.id)
209 req_ref_obj.delete(cursor, user, req_ref_ids,
210 context=context)
211 for i in to_link: 215 for i in to_link:
212 req_ref_obj.create(cursor, user, { 216 req_ref_obj.create(cursor, user, {
213 'request': i, 217 'request': i,
214 'reference': 'project.work,%s' % id, 218 'reference': 'project.work,%s' % id,
215 }, context=context) 219 }, context=context)
216 return 220 return
217
218 221
219 fun_fields = ('actual_start_date', 'actual_finish_date', 222 fun_fields = ('actual_start_date', 'actual_finish_date',
220 'constraint_start_date', 'constraint_finish_date') 223 'constraint_start_date', 'constraint_finish_date')
221 db_fields = ('actual_start_time', 'actual_finish_time', 224 db_fields = ('actual_start_time', 'actual_finish_time',
222 'constraint_start_time', 'constraint_finish_time') 225 'constraint_start_time', 'constraint_finish_time')
223 for fun_field, db_field in zip(fun_fields, db_fields): 226 for fun_field, db_field in zip(fun_fields, db_fields):
224 if fun_field == name: 227 if fun_field == name:
225 self.write(cursor, user, id, {db_field: value}, context=context) 228 self.write(cursor, user, id, {db_field: value}, context=context)
226 break 229 break
227 230
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 to_update.add(work.parent.id) 643 to_update.add(work.parent.id)
641 to_update.update(c.id for c in work.parent.children \ 644 to_update.update(c.id for c in work.parent.children \
642 if c.id not in ids) 645 if c.id not in ids)
643 res = super(Work, self).delete(cursor, user, ids, context=context) 646 res = super(Work, self).delete(cursor, user, ids, context=context)
644 647
645 for work_id in to_update: 648 for work_id in to_update:
646 self.reset_leveling(cursor, user, work_id, context=context) 649 self.reset_leveling(cursor, user, work_id, context=context)
647 self.compute_dates(cursor, user, work_id, context=context) 650 self.compute_dates(cursor, user, work_id, context=context)
648 651
649 return res 652 return res
650 Work() 653 Work()
ced 2009/07/03 17:21:43 Remove the space in an other commit.
651 654
652 655
656
653 class PredecessorSuccessor(ModelSQL): 657 class PredecessorSuccessor(ModelSQL):
654 'Predecessor - Successor' 658 'Predecessor - Successor'
655 _name = 'project.predecessor_successor' 659 _name = 'project.predecessor_successor'
656 _description = __doc__ 660 _description = __doc__
657 661
658 predecessor = fields.Many2One('project.work', 'Predecessor', 662 predecessor = fields.Many2One('project.work', 'Predecessor',
659 ondelete='CASCADE', required=True, select=1) 663 ondelete='CASCADE', required=True, select=1)
660 successor = fields.Many2One('project.work', 'Successor', 664 successor = fields.Many2One('project.work', 'Successor',
661 ondelete='CASCADE', required=True, select=1) 665 ondelete='CASCADE', required=True, select=1)
662 666
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
731 }, 735 },
732 }, 736 },
733 } 737 }
734 738
735 def _leveling(self, cursor, user, data, context=None): 739 def _leveling(self, cursor, user, data, context=None):
736 work_obj = self.pool.get('project.work') 740 work_obj = self.pool.get('project.work')
737 work_obj.create_leveling(cursor, user, data['id'], context=context) 741 work_obj.create_leveling(cursor, user, data['id'], context=context)
738 return {} 742 return {}
739 743
740 Leveling() 744 Leveling()
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497