~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to purchase_delivery/delivery.py

merging new development from indian accounting

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
5
#                    Fabien Pinckaers <fp@tiny.Be>
 
6
#
 
7
# WARNING: This program as such is intended to be used by professional
 
8
# programmers who take the whole responsability of assessing all potential
 
9
# consequences resulting from its eventual inadequacies and bugs
 
10
# End users who are looking for a ready-to-use solution with commercial
 
11
# garantees and support are strongly adviced to contract a Free Software
 
12
# Service Company
 
13
#
 
14
# This program is Free Software; you can redistribute it and/or
 
15
# modify it under the terms of the GNU General Public License
 
16
# as published by the Free Software Foundation; either version 2
 
17
# of the License, or (at your option) any later version.
 
18
#
 
19
# This program is distributed in the hope that it will be useful,
 
20
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
22
# GNU General Public License for more details.
 
23
#
 
24
# You should have received a copy of the GNU General Public License
 
25
# along with this program; if not, write to the Free Software
 
26
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
27
#
 
28
##############################################################################
 
29
 
 
30
import netsvc
 
31
from osv import fields,osv,orm
 
32
 
 
33
class delivery_grid(osv.osv):
 
34
    _name = "delivery.grid"
 
35
    _inherit = "delivery.grid"
 
36
 
 
37
    def get_price(self, cr, uid, id, order, dt, context):
 
38
        """
 
39
        This is not very clean because the function has to check the type of order.
 
40
        It could be improve by changing the signature of the method and by passing a dict in place of a browse record.
 
41
        """
 
42
        total = 0
 
43
        weight = 0
 
44
        volume = 0
 
45
 
 
46
        for line in order.order_line:
 
47
            if not line.product_id:
 
48
                continue
 
49
            qty = 0.0
 
50
            
 
51
            if order._table_name == "sale.order":
 
52
                qty = line.product_uom_qty
 
53
            else:
 
54
                qty = line.product_qty
 
55
 
 
56
            total += line.price_subtotal or 0.0
 
57
            weight += (line.product_id.weight or 0.0) * qty
 
58
            volume += (line.product_id.volume or 0.0) * qty
 
59
 
 
60
        return self.get_price_from_picking(cr, uid, id, total,weight, volume, context)
 
61
 
 
62
    def get_price_from_picking(self, cr, uid, id, total, weight, volume, context={}):
 
63
        grid = self.browse(cr, uid, id, context)
 
64
 
 
65
        price = 0.0
 
66
        ok = False
 
67
 
 
68
        for line in grid.line_ids:
 
69
            price_dict = {'price': total, 'volume':volume, 'weight': weight, 'wv':volume*weight}
 
70
            test = eval(line.type+line.operator+str(line.max_value), price_dict)
 
71
            if test:
 
72
                if context.has_key('object') and context['object']=='purchase':
 
73
                    price = line.standard_price
 
74
                else:
 
75
                    price = line.list_price
 
76
                if line.price_type=='variable':
 
77
                    price *= price_dict[line.variable_factor]
 
78
                ok = True
 
79
                break
 
80
        if not ok:
 
81
            raise except_osv('No price avaible !', 'No line matched this order in the choosed delivery grids !')
 
82
        return price
 
83
 
 
84
delivery_grid()
 
85
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
86