1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# Copyright (c) 2006 TINY SPRL. (http://tiny.be) All Rights Reserved.
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 report import report_sxw
35
class purchase_order(report_sxw.rml_parse):
36
def __init__(self, cr, uid, name, context):
37
super(purchase_order, self).__init__(cr, uid, name, context)
38
self.localcontext.update({
40
'get_line_tax': self._get_line_tax,
41
'get_tax': self._get_tax,
42
'editor' : self.editor,
43
'purchase' : self.purchase,
47
def editor(self,o_id):
48
self.cr.execute("select distinct p.editor from purchase_order_line pl left join product_product p on (pl.product_id=p.id) where pl.order_id=%d", (o_id,))
49
res = map(lambda x: x[0], self.cr.fetchall())
53
p = self.pool.get('res.partner').browse(self.cr, self.uid, r)
54
editor.append({'id':p.id,'name':p.name})
56
editor.append({'id':False,'name':''})
59
def purchase(self, editor_id, o_id):
61
self.cr.execute("SELECT PL.id FROM purchase_order_line PL,product_product P where P.product_tmpl_id=PL.product_id and PL.order_id=%d and P.editor=%d", (o_id,editor_id or None))
63
self.cr.execute("SELECT PL.id FROM purchase_order_line PL,product_product P where P.product_tmpl_id=PL.product_id and PL.order_id=%d and P.editor is NULL", (o_id,))
64
res = self.cr.fetchall()
65
line_id = map(lambda x: x[0], res)
66
line = self.pool.get('purchase.order.line').browse(self.cr,self.uid,line_id)
69
def author(self,product_id):
71
author_id = self.pool.get('product.product').read(self.cr,self.uid,[product_id])[0];
73
author_name = self.pool.get('library.author').read(self.cr,self.uid,author_id['author_ids']);
77
for a_name in author_name:
78
name_list.append(a_name['name']);
80
return ', '.join(name_list)
83
def _get_line_tax(self, line_obj):
84
self.cr.execute("SELECT tax_id FROM purchase_order_taxe WHERE order_line_id=%d" % (line_obj.id))
85
res = self.cr.fetchall() or None
88
if isinstance(res, list):
89
tax_ids = [t[0] for t in res]
92
res = [tax.name for tax in pooler.get_pool(cr.dbname).get('account.tax').browse(self.cr, self.uid, tax_ids)]
93
return ",\n ".join(res)
95
def _get_tax(self, order_obj):
96
self.cr.execute("SELECT DISTINCT tax_id FROM purchase_order_taxe, purchase_order_line, purchase_order \
97
WHERE (purchase_order_line.order_id=purchase_order.id) AND (purchase_order.id=%d)" % (order_obj.id))
98
res = self.cr.fetchall() or None
101
if isinstance(res, list):
102
tax_ids = [t[0] for t in res]
105
tax_obj = pooler.get_pool(cr.dbname).get('account.tax')
107
for tax in tax_obj.browse(self.cr, self.uid, tax_ids):
108
self.cr.execute("SELECT DISTINCT order_line_id FROM purchase_order_line, purchase_order_taxe \
109
WHERE (purchase_order_taxe.tax_id=%d) AND (purchase_order_line.order_id=%d)" % (tax.id, order_obj.id))
110
lines = self.cr.fetchall() or None
112
if isinstance(lines, list):
113
line_ids = [l[0] for l in lines]
117
for line in pooler.get_pool(cr.dbname).get('purchase.order.line').browse(self.cr, self.uid, line_ids):
118
base += line.price_subtotal
119
res.append({'code':tax.name,
121
'amount':base*tax.amount})
124
report_sxw.report_sxw('report.purchase.order.bookstore','purchase.order','addons/bookstore/report/purchase_order.rml',parser=purchase_order)