1
# -*- encoding: utf-8 -*-
1
2
##############################################################################
3
# Copyright (c) 2004-2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
5
# WARNING: This program as such is intended to be used by professional
6
# programmers who take the whole responsability of assessing all potential
7
# consequences resulting from its eventual inadequacies and bugs
8
# End users who are looking for a ready-to-use solution with commercial
9
# garantees and support are strongly adviced to contract a Free Software
12
# This program is Free Software; you can redistribute it and/or
13
# modify it under the terms of the GNU General Public License
14
# as published by the Free Software Foundation; either version 2
15
# of the License, or (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU General Public License for more details.
22
# You should have received a copy of the GNU General Public License
23
# along with this program; if not, write to the Free Software
24
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (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 General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
26
21
##############################################################################
37
32
class purchase_order_line(osv.osv):
38
_name = "purchase.order.line"
39
_inherit = "purchase.order.line"
41
def _amount_line(self, cr, uid, ids, prop, unknow_none,unknow_dict):
43
cur_obj=self.pool.get('res.currency')
44
for line in self.browse(cr, uid, ids):
45
cur = line.order_id.pricelist_id.currency_id
46
res[line.id] = cur_obj.round(cr, uid, cur, line.price_unit * line.product_qty * (1 - (line.discount or 0.0) /100.0))
50
'discount': fields.float('Discount (%)', digits=(16,2)),
51
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal'),
54
'discount': lambda *a: 0.0,
33
_name = "purchase.order.line"
34
_inherit = "purchase.order.line"
36
def _amount_line(self, cr, uid, ids, prop, unknow_none,unknow_dict):
38
cur_obj=self.pool.get('res.currency')
39
for line in self.browse(cr, uid, ids):
40
cur = line.order_id.pricelist_id.currency_id
41
res[line.id] = cur_obj.round(cr, uid, cur, line.price_unit * line.product_qty * (1 - (line.discount or 0.0) /100.0))
45
'discount': fields.float('Discount (%)', digits=(16,2)),
46
'price_subtotal': fields.function(_amount_line, method=True, string='Subtotal'),
49
'discount': lambda *a: 0.0,
56
51
purchase_order_line()
58
53
class purchase_order(osv.osv):
59
_name = "purchase.order"
60
_inherit = "purchase.order"
62
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
63
id_set = ",".join(map(str, ids))
64
sql_req="SELECT s.id,COALESCE(SUM(l.price_unit*l.product_qty*(100.0-l.discount))/100.0,0) AS amount FROM purchase_order s LEFT OUTER JOIN purchase_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id"
67
res = dict(cr.fetchall())
69
cur_obj=self.pool.get('res.currency')
71
order=self.browse(cr, uid, [id])[0]
72
cur=order.pricelist_id.currency_id
73
res[id]=cur_obj.round(cr, uid, cur, res[id])
77
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
79
cur_obj=self.pool.get('res.currency')
80
for order in self.browse(cr, uid, ids):
82
cur=order.pricelist_id.currency_id
83
for line in order.order_line:
84
for c in self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_qty, order.partner_address_id.id, line.product_id):
85
val+= cur_obj.round(cr, uid, cur, c['amount'])
86
res[order.id]=cur_obj.round(cr, uid, cur, val)
90
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
91
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
54
_name = "purchase.order"
55
_inherit = "purchase.order"
57
def _amount_untaxed(self, cr, uid, ids, field_name, arg, context):
58
id_set = ",".join(map(str, ids))
59
sql_req="SELECT s.id,COALESCE(SUM(l.price_unit*l.product_qty*(100.0-l.discount))/100.0,0) AS amount FROM purchase_order s LEFT OUTER JOIN purchase_order_line l ON (s.id=l.order_id) WHERE s.id IN ("+id_set+") GROUP BY s.id"
62
res = dict(cr.fetchall())
64
cur_obj=self.pool.get('res.currency')
66
order=self.browse(cr, uid, [id])[0]
67
cur=order.pricelist_id.currency_id
68
res[id]=cur_obj.round(cr, uid, cur, res[id])
72
def _amount_tax(self, cr, uid, ids, field_name, arg, context):
74
cur_obj=self.pool.get('res.currency')
75
for order in self.browse(cr, uid, ids):
77
cur=order.pricelist_id.currency_id
78
for line in order.order_line:
79
for c in self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_qty, order.partner_address_id.id, line.product_id):
80
val+= cur_obj.round(cr, uid, cur, c['amount'])
81
res[order.id]=cur_obj.round(cr, uid, cur, val)
85
'amount_untaxed': fields.function(_amount_untaxed, method=True, string='Untaxed Amount'),
86
'amount_tax': fields.function(_amount_tax, method=True, string='Taxes'),
90
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: