1
# -*- coding: utf-8 -*-
2
#################################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2011 Julius Network Solutions SARL <contact@julius.fr>
7
# This program is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20
#################################################################################
23
from osv import fields, osv
24
from tools.translate import _
26
class partner_contract(osv.osv):
27
_inherit = "contract.contract"
28
_description = "Parnter Contract"
30
"""This function computes the month prices and worked hours for a contract"""
31
def _package_compute(self, cr, uid, ids, name, args, context=None):
33
for contract in self.browse(cr,uid,ids, context=context):
40
"""If the contract is linked with another, the program takes the linked contract
41
usual hours to compute shared hours."""
42
if contract.contract_linked :
43
usual_hours_link = contract.contract_linked.usual_hours_ids
47
for usual_hour in contract.usual_hours_ids :
48
"""for each usual hour in the contract, the program computes its duration, the responsible
49
presence hours and the time shared between the current usual hour and the corresponding one
50
in the linked contract."""
51
temp = self._usual_hour(usual_hour,usual_hours_link)
52
duration += temp['duration']
53
shared += temp['shared']
54
presence += usual_hour.responsible_hours
56
"""The times are working times are balanced with the responsible hours and shared hours rates."""
57
if contract.contract_linked :
58
full_hours_worked = duration - (1 - float(contract.contract_linked_rate) / 100) * shared
60
full_hours_worked = duration -1.0 / 3 * presence
62
monthly_package = (float(full_hours_worked) * float(contract.worked_weeks)/ 12)
63
monthly_fee = monthly_package*contract.net_rate
65
'monthly_fee': monthly_fee,
66
'monthly_package': monthly_package,
67
'hours_per_week': full_hours_worked,
71
def onchange_linked_contract(self, cr, uid, ids, worked_weeks, total_weeks, net_rate,name, contract_linked, contract_linked_rate):
72
self.modif_linked_contract(cr, uid, ids, contract_linked, contract_linked_rate)
73
return self.onchange_compute(cr, uid, ids, worked_weeks, total_weeks, net_rate, name, contract_linked, contract_linked_rate)
75
def onchange_linked_contract_rate(self, cr, uid, ids, worked_weeks, total_weeks, net_rate,name, contract_linked, contract_linked_rate):
77
cr.execute('''update partner_contract set contract_linked_rate=100-%s where contract_linked = %s''' % (contract_linked_rate,id))
78
return self.onchange_compute(cr, uid, ids, worked_weeks, total_weeks, net_rate, name, contract_linked, contract_linked_rate)
80
"""This function returns for an usual_hours A and a list of usual_hour, the duration of A and the time shared between A and the list"""
81
def _usual_hour(self,usual_hour,susual_hours):
83
begin = usual_hour.hour_from
84
end = usual_hour.hour_to
85
day_of_week = usual_hour.day_of_week
87
presence = usual_hour.responsible_hours
91
for susual_hour in susual_hours :
92
if susual_hour.day_of_week == day_of_week and susual_hour.hour_from <= end and susual_hour.hour_to>= begin :
93
shared += min(susual_hour.hour_to,end)-max(susual_hour.hour_from,begin)
96
return {'shared' : shared, 'duration' : duration, 'presence' : presence}
98
def _get_period_ids(self, cr, uid, ids, field_name, arg, context={}):
100
period_obj = self.pool.get('service.period')
101
for record in self.browse(cr, uid, ids, context):
102
read = self.read(cr, uid, [record.id],['partner_id'])[0]
103
if read['partner_id']:
104
period_ids = period_obj.search(cr, uid, [
105
('partner_id.id','=',read['partner_id'][0]),
106
('type','=','partner'),
108
result[record.id] = period_ids
110
result[record.id] = []
115
'user_id': fields.many2one('res.users', 'Manager'),
116
'gross_rate':fields.float('Gross rate'),
117
'net_rate':fields.float('Net rate'),
118
'worked_weeks':fields.integer('Number of worked weeks', size=2),
119
'sale_order_id': fields.many2one('sale.order', 'Quotation'),
120
'monthly': fields.boolean('Monthly'),
121
'employee_id': fields.many2many('hr.employee', 'worker_contract_rel', 'contract_id', 'employee_id', 'Workers'),
122
'agency' : fields.many2one('res.partner.address', 'Agency'),
123
'main_contract' : fields.boolean('Main contract'),
124
'period_ids' : fields.function(_get_period_ids, method=True, type='many2many', relation="service.period", string="Periods"),
128
'user_id': lambda obj, cr, uid, context: uid,
129
'active': lambda *a: True
134
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:heures effectives / semaine x Nbre semaines travaillees / an / 12