report merge
[odoo/odoo.git] / addons / point_of_sale / report / pos_receipt_with_remboursment.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #    
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
19 #
20 ##############################################################################
21
22 import time
23 from report import report_sxw
24 import pooler
25
26
27 class order(report_sxw.rml_parse):
28
29     def __init__(self, cr, uid, name, context):
30         super(order, self).__init__(cr, uid, name, context)
31
32         user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid)
33         partner = user.company_id.partner_id
34
35         self.localcontext.update({
36             'time': time,
37             'disc': self.discount,
38             'net': self.netamount,
39             'get_journal_amt': self._get_journal_amt,
40             'address': partner.address and partner.address[0] or False,
41         })
42
43     def netamount(self, order_line_id):
44         sql = 'select (qty*price_unit) as net_price from pos_order_line where id = %s'
45         self.cr.execute(sql, (order_line_id,))
46         res = self.cr.fetchone()
47         return res[0]
48
49     def discount(self, order_id):
50         sql = 'select discount, price_unit, qty from pos_order_line where order_id = %s '
51         self.cr.execute(sql, (order_id,))
52         res = self.cr.fetchall()
53         dsum = 0
54         for line in res:
55             if line[0] != 0:
56                 dsum = dsum +(line[2] * (line[0]*line[1]/100))
57         return dsum
58     def _get_journal_amt(self, order_id):
59         lst=[]
60         sql = """ select aj.name from account_bank_statement as abs
61                     LEFT JOIN account_bank_statement_line as absl ON abs.id = absl.statement_id
62                     LEFT JOIN account_journal as aj ON aj.id = abs.journal_id
63                     WHERE absl.pos_statement_id = %d"""%(order_id.id)
64         self.cr.execute(sql)
65         res = self.cr.fetchone()
66         lst.append(res[0])
67         sql2 = """ select sum(absl.amount) as amt from account_bank_statement as abs
68                     LEFT JOIN account_bank_statement_line as absl ON abs.id = absl.statement_id
69                     LEFT JOIN account_journal as aj ON aj.id = abs.journal_id
70                     where aj.name = '%s' """%(res[0])
71         self.cr.execute(sql2)
72         res1 = self.cr.fetchone()
73         lst.append(res1[0])
74         return lst
75
76 report_sxw.report_sxw('report.pos.receipt.with.remboursment', 'pos.order', 'addons/point_of_sale/report/pos_receipt_with_remboursment.rml', parser=order, header=False)
77
78 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
79