1
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# $Id: partner.py 1007 2005-07-25 13:18:09Z kayhman $
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
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.
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.
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.
28
##############################################################################
30
from osv import fields,osv
32
from tools import config
35
class sale_order_line(osv.osv):
36
_name = "sale.order.line"
37
_inherit = "sale.order.line"
38
def _product_margin(self, cr, uid, ids, field_name, arg, context):
40
for line in self.browse(cr, uid, ids):
43
res[line.id] = round((line.price_unit*line.product_uos_qty*(100.0-line.discount)/100.0) -(line.product_id.standard_price*line.product_uos_qty),2)
47
'margin': fields.function(_product_margin, method=True, string='Margin'),
51
class sale_order(osv.osv):
53
_inherit = "sale.order"
55
def _product_margin(self, cr, uid, ids, field_name, arg, context):
56
id_set = ",".join(map(str, ids))
60
COALESCE(SUM(l.price_unit*l.product_uos_qty*(100-l.discount)/100.0 - t.standard_price * l.product_uos_qty),0)::decimal(16,2) AS amount
63
LEFT OUTER JOIN sale_order_line l ON (s.id=l.order_id)
64
LEFT JOIN product_product p ON (p.id=l.product_id)
65
LEFT JOIN product_template t ON (t.id=p.product_tmpl_id)
67
s.id IN ("""+id_set+""") GROUP BY s.id """)
68
res = dict(cr.fetchall())
72
'margin': fields.function(_product_margin, method=True, string='Margin'),