~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to point_of_sale/report/pos_payment_report_user.py

  • Committer: Fabien Pinckaers
  • Date: 2010-01-21 08:27:34 UTC
  • mfrom: (2770.1.18 trunk)
  • Revision ID: fp@tinyerp.com-20100121082734-up8syb6019o9q25d
merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
##############################################################################
 
22
import time
 
23
from report import report_sxw
 
24
 
 
25
class pos_payment_report_user(report_sxw.rml_parse):
 
26
 
 
27
    def __init__(self, cr, uid, name, context):
 
28
        super(pos_payment_report_user, self).__init__(cr, uid, name, context)
 
29
        self.total = 0.0
 
30
        self.localcontext.update({
 
31
                'time': time,
 
32
                'pos_payment_user': self.__pos_payment_user__,
 
33
                'pos_payment_user_total':self.__pos_payment_user__total__,
 
34
                })
 
35
 
 
36
    def __pos_payment_user__(self,form):
 
37
        data={}
 
38
        ids = form['user_id'][0][-1]
 
39
        idss = map(str, ids)
 
40
        sql = "select pt.name,pol.qty,pol.discount,pol.price_unit, " \
 
41
                         "(pol.price_unit * pol.qty * (1 - (pol.discount) / 100.0)) as total  " \
 
42
                         "from pos_order as po,pos_order_line as pol,product_product as pp,product_template as pt " \
 
43
                         "where pt.id=pp.product_tmpl_id and pp.id=pol.product_id and po.id = pol.order_id  " \
 
44
                         "and po.state in ('paid','invoiced') and to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::date = current_date " \
 
45
                         "and po.user_id in (%s)" % (",".join(idss), )
 
46
        self.cr.execute (sql)
 
47
        data=self.cr.dictfetchall()
 
48
        return data
 
49
    def __pos_payment_user__total__(self,form):
 
50
        res=[]
 
51
        ids = form['user_id'][0][-1]
 
52
        idss = map(str, ids)
 
53
        self.cr.execute ("select sum(pol.price_unit * pol.qty * (1 - (pol.discount) / 100.0)) " \
 
54
                         "from pos_order as po,pos_order_line as pol,product_product as pp,product_template as pt " \
 
55
                         "where pt.id=pp.product_tmpl_id and pp.id=pol.product_id and po.id = pol.order_id " \
 
56
                         "and po.state='paid' and to_char(date_trunc('day',po.date_order),'YYYY-MM-DD')::date = current_date " \
 
57
                         "and po.user_id in (%s)" % (",".join(idss), ))
 
58
        res=self.cr.fetchone()
 
59
        res = res and res[0] or None
 
60
 
 
61
        return res
 
62
 
 
63
 
 
64
report_sxw.report_sxw('report.pos.payment.report.user', 'pos.order', 'addons/point_of_sale/report/pos_payment_report_user.rml', parser=pos_payment_report_user)
 
65
 
 
66
 
 
67
 
 
68
 
 
69
 
 
70
 
 
71
 
 
72
 
 
73
 
 
74
 
 
75
 
 
76
 
 
77
 
 
78
 
 
79
 
 
80