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