| OLD | NEW |
| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 actual_start_date = fields.Function('get_function_fields', | 54 actual_start_date = fields.Function('get_function_fields', |
| 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', string='Requests', | 64 requests = fields.Function('get_function_fields', type='many2many', |
| 65 type='one2many', relation='res.request') | 65 string='Requests', fnct_inv='set_function_fields', |
| 66 relation='res.request') |
| 66 | 67 |
| 67 def __init__(self): | 68 def __init__(self): |
| 68 super(Work, self).__init__() | 69 super(Work, self).__init__() |
| 69 self._constraints += [ | 70 self._constraints += [ |
| 70 ('check_recursion', 'recursive_dependency'), | 71 ('check_recursion', 'recursive_dependency'), |
| 71 ] | 72 ] |
| 72 self._error_messages.update({ | 73 self._error_messages.update({ |
| 73 'recursive_dependency': 'You can not create recursive ' | 74 'recursive_dependency': 'You can not create recursive ' |
| 74 'dependencies!', | 75 'dependencies!', |
| 75 }) | 76 }) |
| 76 | 77 |
| 77 def check_recursion(self,cursor, user, ids, parent='parent'): | 78 def check_recursion(self,cursor, user, ids, parent='parent'): |
| 78 return super(Work, self).check_recursion(cursor, user, ids, | 79 return super(Work, self).check_recursion(cursor, user, ids, |
| 79 parent='successors') | 80 parent='successors') |
| 80 | 81 |
| 81 def get_function_fields(self, cursor, user, ids, names, args, context=None): | 82 def get_function_fields(self, cursor, user, ids, names, args, context=None): |
| 82 ''' | 83 ''' |
| 83 Function to compute function fields | 84 Function to compute function fields |
| 84 | 85 |
| 85 :param cursor: the database cursor | 86 :param cursor: the database cursor |
| 86 :param user: the user id | 87 :param user: the user id |
| 87 :param ids: the ids of the works | 88 :param ids: the ids of the works |
| 88 :param names: the list of field name to compute | 89 :param names: the list of field name to compute |
| 89 :param args: optional argument | 90 :param args: optional argument |
| 90 :param context: the context | 91 :param context: the context |
| 91 :return: a dictionary with all field names as key and | 92 :return: a dictionary with all field names as key and |
| 92 a dictionary as value with id as key | 93 a dictionary as value with id as key |
| 93 ''' | 94 ''' |
| 95 req_ref_obj = self.pool.get('res.request.reference') |
| 96 |
| 94 res = {} | 97 res = {} |
| 95 | 98 |
| 99 if 'requests' in names: |
| 100 requests = dict((i, []) for i in ids) |
| 96 | 101 |
| 97 if 'requests' in names: | 102 for i in range(0, len(ids), cursor.IN_MAX): |
| 98 req_ref_obj = self.pool.get('res.request.reference') | 103 sub_ids = ids[i:i + cursor.IN_MAX] |
| 99 req_ref_ids = req_ref_obj.search(cursor, user, [ | |
| 100 ('reference', 'in', ['project.work,' + str(i) for i in ids])
, | |
| 101 ], context=context) | |
| 102 req_refs = req_ref_obj.browse(cursor, user, req_ref_ids, | |
| 103 context=context) | |
| 104 requests = defaultdict(list) | |
| 105 | 104 |
| 106 for req_ref in req_refs: | 105 req_ref_ids = req_ref_obj.search(cursor, user, [ |
| 107 work_id = int(req_ref.reference.split(',')[1]) | 106 ('reference', 'in', [ |
| 108 requests[work_id].append(req_ref.request.id) | 107 'project.work,%s' % i for i in sub_ids |
| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 works = self.browse(cursor, user, ids, context=context) | 170 works = self.browse(cursor, user, ids, context=context) |
| 164 for work in works: | 171 for work in works: |
| 165 values[work.id] = work[db_field] \ | 172 values[work.id] = work[db_field] \ |
| 166 and work[db_field].date() or None | 173 and work[db_field].date() or None |
| 167 res[fun_field] = values | 174 res[fun_field] = values |
| 168 | 175 |
| 169 return res | 176 return res |
| 170 | 177 |
| 171 def set_function_fields(self, cursor, user, id, name, value, arg, | 178 def set_function_fields(self, cursor, user, id, name, value, arg, |
| 172 context=None): | 179 context=None): |
| 180 request_obj = self.pool.get('res.request') |
| 181 req_ref_obj = self.pool.get('res.request.reference') |
| 182 |
| 183 if name == 'requests': |
| 184 work = self.browse(cursor, user, id, context=context) |
| 185 currents = dict((req.id, req) for req in work.requests) |
| 186 for v in value: |
| 187 to_unlink = [] |
| 188 to_link = [] |
| 189 operator = v[0] |
| 190 |
| 191 ids = len(v) > 1 and v[1] or [] |
| 192 if operator == 'set': |
| 193 to_link.extend((i for i in ids if i not in currents)) |
| 194 to_unlink.extend((i for i in currents if i not in ids)) |
| 195 elif operator == 'add': |
| 196 to_link.extend((i for i in ids if i not in currents)) |
| 197 elif operator == 'unlink': |
| 198 to_unlink.extend((i for i in ids if i in currents)) |
| 199 elif operator == 'unlink_all': |
| 200 to_unlink.extend(currents) |
| 201 elif operator == 'delete': |
| 202 request_obj.delete(cursor, user, to_delete, context=context) |
| 203 else: |
| 204 raise Exception('Operation not supported') |
| 205 |
| 206 req_ref_ids = [] |
| 207 for i in to_unlink: |
| 208 request = currents[i] |
| 209 for ref in request.references: |
| 210 if int(ref.reference.split(',')[1]) == id: |
| 211 req_ref_ids.append(ref.id) |
| 212 req_ref_obj.delete(cursor, user, req_ref_ids, |
| 213 context=context) |
| 214 |
| 215 for i in to_link: |
| 216 req_ref_obj.create(cursor, user, { |
| 217 'request': i, |
| 218 'reference': 'project.work,%s' % id, |
| 219 }, context=context) |
| 220 return |
| 173 | 221 |
| 174 fun_fields = ('actual_start_date', 'actual_finish_date', | 222 fun_fields = ('actual_start_date', 'actual_finish_date', |
| 175 'constraint_start_date', 'constraint_finish_date') | 223 'constraint_start_date', 'constraint_finish_date') |
| 176 db_fields = ('actual_start_time', 'actual_finish_time', | 224 db_fields = ('actual_start_time', 'actual_finish_time', |
| 177 'constraint_start_time', 'constraint_finish_time') | 225 'constraint_start_time', 'constraint_finish_time') |
| 178 for fun_field, db_field in zip(fun_fields, db_fields): | 226 for fun_field, db_field in zip(fun_fields, db_fields): |
| 179 if fun_field == name: | 227 if fun_field == name: |
| 180 self.write(cursor, user, id, {db_field: value}, context=context) | 228 self.write(cursor, user, id, {db_field: value}, context=context) |
| 181 break | 229 break |
| 182 | 230 |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 687 }, | 735 }, |
| 688 }, | 736 }, |
| 689 } | 737 } |
| 690 | 738 |
| 691 def _leveling(self, cursor, user, data, context=None): | 739 def _leveling(self, cursor, user, data, context=None): |
| 692 work_obj = self.pool.get('project.work') | 740 work_obj = self.pool.get('project.work') |
| 693 work_obj.create_leveling(cursor, user, data['id'], context=context) | 741 work_obj.create_leveling(cursor, user, data['id'], context=context) |
| 694 return {} | 742 return {} |
| 695 | 743 |
| 696 Leveling() | 744 Leveling() |
| OLD | NEW |