1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6
# Copyright (C) 2010-2010 Camptocamp Austria (<http://www.camptocamp.at>)
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
24
from osv import fields, osv
26
class sale_order(osv.osv):
27
_inherit = "sale.order"
29
def _shipped_rate(self, cr, uid, ids, name, arg, context=None):
36
p.sale_id, sum(m.product_qty), mp.state as mp_state
40
stock_picking p on (p.id=m.picking_id)
42
procurement_order mp on (mp.move_id=m.id)
44
p.type = 'internal' AND
45
p.sale_id IN %s GROUP BY mp.state, p.sale_id''', (tuple(ids),))
46
for oid, nbr, mp_state in cr.fetchall():
47
if mp_state == 'cancel':
49
if mp_state == 'done':
50
res[oid][0] += nbr or 0.0
51
res[oid][1] += nbr or 0.0
53
res[oid][1] += nbr or 0.0
58
res[r] = 100.0 * res[r][0] / res[r][1]
59
for order in self.browse(cr, uid, ids, context=context):
64
def _picked_rate(self, cr, uid, ids, name, arg, context=None):
71
p.sale_id, sum(m.product_qty), mp.state as mp_state
75
stock_picking p on (p.id=m.picking_id)
77
procurement_order mp on (mp.move_id=m.id)
79
p.type != 'internal' AND
80
p.sale_id IN %s GROUP BY mp.state, p.sale_id''', (tuple(ids),))
81
for oid, nbr, mp_state in cr.fetchall():
82
if mp_state == 'cancel':
84
if mp_state == 'done':
85
res[oid][0] += nbr or 0.0
86
res[oid][1] += nbr or 0.0
88
res[oid][1] += nbr or 0.0
93
res[r] = 100.0 * res[r][0] / res[r][1]
94
for order in self.browse(cr, uid, ids, context=context):
100
'shipped_rate': fields.function(_shipped_rate, method=True, string='Shipped', type='float'),
b'\\ No newline at end of file'