~jo0thlt/sfsoluciones/mtf

« back to all changes in this revision

Viewing changes to sfs_payment_comission_glp/user_transaction_history.py

  • Committer: contact at zbeanztech
  • Date: 2014-11-07 18:54:14 UTC
  • Revision ID: contact@zbeanztech.com-20141107185414-tzybvn7293tju4ce
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (c) 2014 SF Soluciones.
 
5
#    (http://www.sfsoluciones.com)
 
6
#    contacto@sfsoluciones.com
 
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
 
 
23
from osv import osv, fields
 
24
 
 
25
import openerp.addons.decimal_precision as dp
 
26
 
 
27
class user_transaction_history(osv.osv):
 
28
    _name = 'user.transaction.history'
 
29
    _description = 'Model to keep record of user payments and refund'
 
30
    _rec_name = 'transaction_date'
 
31
    
 
32
    def _get_history(self, cr, uid, ids, context=None):
 
33
        move_line_pool = self.pool.get('account.move.line')
 
34
        history_pool = self.pool.get('user.transaction.history')
 
35
        history_ids = history_pool.search(cr, uid, [('move_line_id', 'in', ids)], context=context)
 
36
        return history_ids
 
37
    
 
38
    def _get_voucher_history(self, cr, uid, ids, context=None):
 
39
        voucher_pool = self.pool.get('account.voucher')
 
40
        history_pool = self.pool.get('user.transaction.history')
 
41
        history_ids = history_pool.search(cr, uid, [('payment_id', 'in', ids)], context=context)
 
42
        return history_ids
 
43
    
 
44
    def _get_transaction_date(self, cr, uid, ids, name, args, context=None):
 
45
        res = {}
 
46
        for history_obj in self.browse(cr, uid, ids, context=context):
 
47
            if history_obj.payment_id:
 
48
                res[history_obj.id] = history_obj.payment_id.date
 
49
            else:
 
50
                res[history_obj.id] = history_obj.move_line_id.date
 
51
        return res
 
52
    
 
53
    _columns = {
 
54
                'user_id': fields.many2one('res.users', 'User'),
 
55
                'transaction_date': fields.function(_get_transaction_date, type="date", string="Transaction Date",
 
56
                                                    store={
 
57
                                                           'account.move.line': (_get_history, ['date'], 10),
 
58
                                                           'account.voucher': (_get_voucher_history, ['date'], 10),
 
59
                                                           'user.transaction.history' : (lambda self, cr, uid, ids, c={}: ids, [], 5),
 
60
                                                           }),
 
61
                'transaction_type': fields.selection([('payment', 'Payment'), ('refund', 'Refund')],
 
62
                                                     'Transaction Type'),
 
63
                'invoice_id': fields.many2one('account.invoice', 'Related Invoice'),
 
64
                'payment_id': fields.many2one('account.voucher', 'Related Payment'),
 
65
                'move_line_id': fields.many2one('account.move.line', 'Related Journal Item'),
 
66
                'amount': fields.float('Amount', digits_compute=dp.get_precision('Account'))
 
67
                }
 
68
user_transaction_history()
 
69
 
 
70
 
 
71
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: