~vauxoo/addons-vauxoo/6.0-trunk

« back to all changes in this revision

Viewing changes to project_task_work/model/project_task_work.py

  • Committer: Gabriela (Vauxoo)
  • Date: 2012-01-02 16:24:49 UTC
  • Revision ID: gabrielaquilarque97@gmail.com-20120102162449-lhxnrtif2ud36du2

[ADD] Added new module invoice_so.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
# -*- encoding: utf-8 -*-
3
 
###########################################################################
4
 
#    Module Writen to OpenERP, Open Source Management Solution
5
 
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
6
 
#    All Rights Reserved
7
 
# Credits######################################################
8
 
#    Coded by: Humberto Arocha <hbto@vauxoo.com>
9
 
#    Planified by: Rafael Silva <rsilvam@vauxoo.com>
10
 
#    Audited by: Nhomar Hernandez <nhomar@vauxoo.com>
11
 
#############################################################################
12
 
#    This program is free software: you can redistribute it and/or modify
13
 
#    it under the terms of the GNU Affero General Public License as published
14
 
#    by the Free Software Foundation, either version 3 of the License, or
15
 
#    (at your option) any later version.
16
 
#
17
 
#    This program is distributed in the hope that it will be useful,
18
 
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 
#    GNU Affero General Public License for more details.
21
 
#
22
 
#    You should have received a copy of the GNU Affero General Public License
23
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
##########################################################################
25
 
 
26
 
import time
27
 
from openerp.osv import osv, fields
28
 
from openerp.tools.translate import _
29
 
 
30
 
 
31
 
class project_task(osv.Model):
32
 
    _inherit = 'project.task'
33
 
 
34
 
    def _get_issue(self, cr, uid, ids, fieldname, arg, context=None):
35
 
        if context is None:
36
 
            context = {}
37
 
        res = {}
38
 
        pi_obj = self.pool.get('project.issue')
39
 
 
40
 
        for id in ids:
41
 
            pi_ids = pi_obj.search(cr, uid, [('task_id', '=', id)]) or []
42
 
            res[id] = pi_ids and pi_ids[0] or None
43
 
 
44
 
        return res
45
 
 
46
 
    def _get_task_in_issue(self, cr, uid, ids, context=None):
47
 
        if context is None:
48
 
            context = {}
49
 
        pi_obj = self.pool.get('project.issue')
50
 
        return [pi_brw.task_id.id for pi_brw in pi_obj.browse(cr, uid, ids,
51
 
                                                              context=context)
52
 
                if pi_brw.task_id]
53
 
 
54
 
    _columns = {
55
 
        'issue_id': fields.function(
56
 
            _get_issue,
57
 
            method=True,
58
 
            type='many2one',
59
 
            relation='project.issue',
60
 
            string='Project issue',
61
 
            store={
62
 
                'project.issue': (_get_task_in_issue, ['task_id'], 15),
63
 
                'project.task': (lambda self, cr, uid, ids, c={}: ids, [], 45),
64
 
            }),
65
 
    }
66
 
 
67
 
 
68
 
class project_task_work(osv.Model):
69
 
    _inherit = 'project.task.work'
70
 
 
71
 
    def _get_project(self, cr, uid, ids, fieldname, arg, context=None):
72
 
        if context is None:
73
 
            context = {}
74
 
        res = {}
75
 
        for ptw_brw in self.browse(cr, uid, ids, context=context):
76
 
 
77
 
            res[ptw_brw.id] = \
78
 
                ptw_brw.task_id and \
79
 
                (ptw_brw.task_id.issue_id and
80
 
                 ptw_brw.task_id.issue_id.project_id and
81
 
                    ptw_brw.task_id.issue_id.project_id.id
82
 
                    or ptw_brw.task_id.project_id and
83
 
                 ptw_brw.task_id.project_id.id)\
84
 
                or None
85
 
 
86
 
        return res
87
 
 
88
 
    def _get_issue(self, cr, uid, ids, fieldname, arg, context=None):
89
 
        if context is None:
90
 
            context = {}
91
 
        res = {}
92
 
        pi_obj = self.pool.get('project.issue')
93
 
        ptw_brws = self.browse(cr, uid, ids, context=context)
94
 
        for ptw_brw in ptw_brws:
95
 
            pi_ids = ptw_brw.task_id and pi_obj.search(cr, uid, [
96
 
                                                       ('task_id', '=',
97
 
                                                        ptw_brw.task_id.id)])\
98
 
                or []
99
 
 
100
 
            res[ptw_brw.id] = pi_ids and pi_ids[0] or None
101
 
        return res
102
 
 
103
 
    def _get_partner(self, cr, uid, ids, fieldname, arg, context=None):
104
 
        if context is None:
105
 
            context = {}
106
 
        res = {}
107
 
        for ptw_brw in self.browse(cr, uid, ids, context=context):
108
 
 
109
 
            res[ptw_brw.id] = \
110
 
                ptw_brw.task_id and \
111
 
                (ptw_brw.task_id.issue_id and
112
 
                 ptw_brw.task_id.issue_id.partner_id and
113
 
                    ptw_brw.task_id.issue_id.partner_id.id
114
 
                    or ptw_brw.task_id.project_id and
115
 
                 ptw_brw.task_id.project_id.partner_id and
116
 
                 ptw_brw.task_id.project_id.partner_id.id
117
 
                    or ptw_brw.task_id.partner_id and
118
 
                 ptw_brw.task_id.partner_id.id
119
 
                 )\
120
 
                or None
121
 
 
122
 
        return res
123
 
 
124
 
    def _get_work_in_task(self, cr, uid, ids, context=None):
125
 
        if context is None:
126
 
            context = {}
127
 
        res = []
128
 
        pt_obj = self.pool.get('project.task')
129
 
        for pt_brw in pt_obj.browse(cr, uid, ids, context=context):
130
 
            res += [work_brw.id for work_brw in pt_brw.work_ids]
131
 
        return list(set(res))
132
 
 
133
 
    def _get_work_in_issue(self, cr, uid, ids, context=None):
134
 
        if context is None:
135
 
            context = {}
136
 
        res = []
137
 
        pi_obj = self.pool.get('project.issue')
138
 
        pt_ids = [pi_brw.task_id.id for pi_brw in pi_obj.browse(
139
 
            cr, uid, ids, context=context) if pi_brw.task_id]
140
 
        return self.pool.get('project.task.work')._get_work_in_task(cr, uid,
141
 
                                                                    pt_ids,
142
 
                                                                    context)
143
 
 
144
 
    _columns = {
145
 
        'project_id': fields.function(
146
 
            _get_project,
147
 
            method=True,
148
 
            type='many2one',
149
 
            relation='project.project',
150
 
            string='Project',
151
 
            store={
152
 
                'project.issue': (_get_work_in_issue, ['task_id',
153
 
                                                       'project_id'], 15),
154
 
                'project.task.work': (lambda self, cr, uid, ids, c={}: ids,
155
 
                                      [], 45),
156
 
            }
157
 
        ),
158
 
        'state': fields.selection([('done', 'Collected'),
159
 
                                   ('draft', 'Uncollected'),
160
 
                                   ('cancel', 'Cancel'), ],
161
 
                                  readonly=False,
162
 
                                  required=True,
163
 
                                  string='State'),
164
 
        'issue_id': fields.function(
165
 
            _get_issue,
166
 
            method=True,
167
 
            type='many2one',
168
 
            relation='project.issue',
169
 
            string='Project Issue',
170
 
            store={
171
 
                'project.issue': (_get_work_in_issue, [], 15),
172
 
                'project.task': (_get_work_in_task, [], 30),
173
 
                'project.task.work': (lambda self, cr, uid, ids, c={}: ids,
174
 
                                      [], 45),
175
 
            }
176
 
        ),
177
 
        'partner_id': fields.function(
178
 
            _get_partner,
179
 
            method=True,
180
 
            type='many2one',
181
 
            relation='res.partner',
182
 
            string='Partner',
183
 
            store={
184
 
                'project.issue': (_get_work_in_issue, [], 15),
185
 
                'project.task': (_get_work_in_task, [], 30),
186
 
                'project.task.work': (lambda self, cr, uid, ids, c={}: ids,
187
 
                                      [], 45),
188
 
            }
189
 
        ),
190
 
        'name': fields.text('Work summary'),
191
 
    }
192
 
 
193
 
    _defaults = {
194
 
        'state': 'draft',
195
 
    }