~vauxoo/addons-vauxoo/7.0-acc_invo_vat_required_dev_luis

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
# -*- encoding: utf-8 -*-
###########################################################################
#    Module Writen to OpenERP, Open Source Management Solution
#    Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
#    All Rights Reserved
# Credits######################################################
#    Coded by: Luis Escobar                <luis@vauxoo.com>
#              María Gabriela Quilarque    <gabriela@openerp.com.ve>
#    Planified by: Nhomar Hernandez        <nhomar@openerp.com.ve>
#    Finance by: Helados Gilda, C.A. http://heladosgilda.com.ve
#    Audited by: María Gabriela Quilarque  <gabriela@openerp.com.ve>
#############################################################################
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
##########################################################################


from openerp.osv import osv, fields
import decimal_precision as dp


class project_task(osv.Model):
    _inherit = 'project.task'

    def _hours_get(self, cr, uid, ids, field_names, args, context=None):
        res = {}
        data = super(project_task, self)._hours_get(
            cr, uid, ids, field_names, args, context=context)
        empl_obj = self.pool.get('hr.employee')
        for l in self.browse(cr, uid, ids, context=context):
            try:
                empl_ids = empl_obj.search(cr, uid, [
                                           ('user_id', '=', l.user_id.id)])
                empl = empl_obj.browse(cr, uid, empl_ids)[0]
                cost = empl.product_id.list_price * data[l.id]['total_hours']

            except Exception, e:
                cost = 0.0

            self.write(cr, uid, l.id, {'cost_per_task': cost})

        return data

    def _get_task(self, cr, uid, ids, context=None):
        return super(project_task, self)._get_task(cr, uid, ids,
                                                    context=context)

    _columns = {
        'effective_hours': fields.function(_hours_get, method=True,
                string='Hours Spent', multi='hours',
                help="Computed using the sum of the task work done.",
                store={
                   'project.task': (lambda self, cr, uid, ids, c={}: ids,
                        ['work_ids', 'remaining_hours', 'planned_hours'], 10),
                   'project.task.work': (_get_task, ['hours'], 10),
                   }),
        'total_hours': fields.function(_hours_get, method=True,
                string='Total Hours', multi='hours',
                help="Computed as: Time Spent + Remaining Time.",
                store={
                   'project.task': (lambda self, cr, uid, ids, c={}: ids,
                        ['work_ids', 'remaining_hours', 'planned_hours'], 10),
                   'project.task.work': (_get_task, ['hours'], 10),
                   }),
        'progress': fields.function(_hours_get, method=True,
                string='Progress (%)',
                multi='hours',
                group_operator="avg",
                help="Computed as: Time Spent / Total Time.",
                store={
                    'project.task': (lambda self, cr, uid, ids, c={}: ids,
                        ['work_ids', 'remaining_hours', 'planned_hours',
                                                                'state'], 10),
                    'project.task.work': (_get_task, ['hours'], 10),
                }),
        'delay_hours': fields.function(_hours_get, method=True,
                string='Delay Hours', multi='hours',
                help="Computed as difference of the time estimated by the\
                        project manager and the real time to close the task.",
                store={
                   'project.task': (lambda self, cr, uid, ids, c={}: ids,
                        ['work_ids', 'remaining_hours', 'planned_hours'], 10),
                   'project.task.work': (_get_task, ['hours'], 10),
               }),
        'cost_per_task': fields.float('Cost', readonly=True,
                help="Computed as: Hour Cost multiplied by Job Hours"),

    }