1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2009 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/>.
21
##############################################################################
24
from report import report_sxw
28
class order(report_sxw.rml_parse):
29
def __init__(self, cr, uid, name, context):
30
super(order, self).__init__(cr, uid, name, context)
31
self.localcontext.update({
33
'get_line_tax': self._get_line_tax,
34
'get_tax': self._get_tax,
35
'get_product_code': self._get_product_code,
37
def _get_line_tax(self, line_obj):
38
self.cr.execute("SELECT tax_id FROM purchase_order_taxe WHERE order_line_id=%s", (line_obj.id))
39
res = self.cr.fetchall() or None
42
if isinstance(res, list):
43
tax_ids = [t[0] for t in res]
46
res = [tax.name for tax in pooler.get_pool(cr.dbname).get('account.tax').browse(self.cr, self.uid, tax_ids)]
47
return ",\n ".join(res)
49
def _get_tax(self, order_obj):
50
self.cr.execute("SELECT DISTINCT tax_id FROM purchase_order_taxe, purchase_order_line, purchase_order \
51
WHERE (purchase_order_line.order_id=purchase_order.id) AND (purchase_order.id=%s)", (order_obj.id))
52
res = self.cr.fetchall() or None
55
if isinstance(res, list):
56
tax_ids = [t[0] for t in res]
59
tax_obj = pooler.get_pool(cr.dbname).get('account.tax')
61
for tax in tax_obj.browse(self.cr, self.uid, tax_ids):
62
self.cr.execute("SELECT DISTINCT order_line_id FROM purchase_order_line, purchase_order_taxe \
63
WHERE (purchase_order_taxe.tax_id=%s) AND (purchase_order_line.order_id=%s)", (tax.id, order_obj.id))
64
lines = self.cr.fetchall() or None
66
if isinstance(lines, list):
67
line_ids = [l[0] for l in lines]
71
for line in pooler.get_pool(cr.dbname).get('purchase.order.line').browse(self.cr, self.uid, line_ids):
72
base += line.price_subtotal
73
res.append({'code':tax.name,
75
'amount':base*tax.amount})
77
def _get_product_code(self, product_id, partner_id):
78
product_obj=pooler.get_pool(self.cr.dbname).get('product.product')
79
return product_obj._product_code(self.cr, self.uid, [product_id], name=None, arg=None, context={'partner_id': partner_id})[product_id]
81
report_sxw.report_sxw('report.purchase.order','purchase.order','addons/purchase/report/order.rml',parser=order)
83
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: