~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to project_task_work/model/project_task_work.py

  • Committer: Nhomar Hernandez
  • Date: 2013-04-19 20:33:12 UTC
  • mfrom: (542.1.314 addons-vauxoo)
  • Revision ID: nhomar@gmail.com-20130419203312-o35v7dn79l6vur0t
[MERGE - PEP8 AND V7-MIG] All migrated to V7 Just
improved osv.osv => osv.Model, osv.osv_memory => osv.TransientModel
import inside openerp.* enviroment
Erased class instansiation no necesarry anymore in V7
AUTOPEP8 run, Left PEP8 long lines manually.

Show diffs side-by-side

added added

removed removed

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