~openerp-commiter/openobject-addons/v61

« back to all changes in this revision

Viewing changes to pos_invoicing/report/pos_receipt2_ticket.py

  • Committer: Cubic ERP
  • Date: 2012-11-28 17:21:48 UTC
  • Revision ID: info@cubicerp.com-20121128172148-b7l2a4r3upw6shit
[ADD] kfr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
def titlize(journal_name):
 
27
    words = journal_name.split()
 
28
    while words.pop() != 'journal':
 
29
        continue
 
30
    return ' '.join(words)
 
31
 
 
32
class orderB(report_sxw.rml_parse):
 
33
 
 
34
    def __init__(self, cr, uid, name, context):
 
35
        super(orderB, self).__init__(cr, uid, name, context=context)
 
36
 
 
37
        user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid)
 
38
        partner = user.company_id.partner_id
 
39
 
 
40
        self.localcontext.update({
 
41
            'time': time,
 
42
            'convert': self.convert,
 
43
            'day': self.day,
 
44
            'month': self.month,
 
45
            'year': self.year,
 
46
            'disc': self.discount,
 
47
            'net': self.netamount,
 
48
            'untax':self.untax,
 
49
            'get_journal_amt': self._get_journal_amt,
 
50
            'address': partner.address and partner.address[0] or False,
 
51
            'titlize': titlize,
 
52
            'multiplica': self.multiplica,
 
53
        })
 
54
 
 
55
    def convert(self, amount): return self.pool.get('ir.translation').amount_to_text(amount, 'pe', 'Nuevo Sol')
 
56
    
 
57
    def day(self, date): return self.pool.get('ir.translation').date_part(date, 'day', format='number' ,lang='pe')
 
58
    
 
59
    def month(self, date): return self.pool.get('ir.translation').date_part(date, 'month', format='text' ,lang='pe')
 
60
    
 
61
    def year(self, date): return self.pool.get('ir.translation').date_part(date, 'year', format='number' ,lang='pe')
 
62
    
 
63
    def multiplica(self,m,n):
 
64
        return m*n
 
65
 
 
66
    def untax(self, order_id):
 
67
        sql = 'select price_unit, qty from pos_order_line where order_id = %s'
 
68
        self.cr.execute(sql, (order_id,))
 
69
        res = self.cr.fetchall()
 
70
        tsum = 0
 
71
        for line in res:
 
72
             tsum = tsum +line[0] * line[1]
 
73
        return tsum
 
74
        
 
75
    def netamount(self, order_line_id):
 
76
        sql = 'select (qty*price_unit) as net_price from pos_order_line where id = %s'
 
77
        self.cr.execute(sql, (order_line_id,))
 
78
        res = self.cr.fetchone()
 
79
        return res[0]
 
80
 
 
81
    def discount(self, order_id):
 
82
        sql = 'select discount, price_unit, qty from pos_order_line where order_id = %s '
 
83
        self.cr.execute(sql, (order_id,))
 
84
        res = self.cr.fetchall()
 
85
        dsum = 0
 
86
        for line in res:
 
87
            if line[0] != 0:
 
88
                dsum = dsum +(line[2] * (line[0]*line[1]/100))
 
89
        return dsum
 
90
 
 
91
    def _get_journal_amt(self, order_id):
 
92
        data={}
 
93
        sql = """ select aj.name,absl.amount as amt from account_bank_statement as abs
 
94
                        LEFT JOIN account_bank_statement_line as absl ON abs.id = absl.statement_id
 
95
                        LEFT JOIN account_journal as aj ON aj.id = abs.journal_id
 
96
                        WHERE absl.pos_statement_id =%d"""%(order_id)
 
97
        self.cr.execute(sql)
 
98
        data = self.cr.dictfetchall()
 
99
        return data
 
100
 
 
101
report_sxw.report_sxw('report.pos.receipt2.ticket', 'pos.order', 'addons/pos_invoicing/report/pos_receipt2_ticket.rml', parser=orderB, header=False)
 
102
 
 
103
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: