~serpent-consulting-services/openerp-usa/fix-shipping_api_ups_cc

« back to all changes in this revision

Viewing changes to account_voucher_credits_us/wizard/account_post_voucher.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

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) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
6
 
#    Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.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 fields, osv
24
 
from tools.translate import _
25
 
 
26
 
class account_post_voucher(osv.osv_memory):
27
 
    _name = 'account.post.voucher'
28
 
    _description = 'Account Pay Voucher'
29
 
    _columns = {
30
 
        'total_paid': fields.float('Total Received'),
31
 
        'total_allocated': fields.float('Total Allocated'),
32
 
        'ok_to_go': fields.float('OK to Go'),
33
 
         }
34
 
 
35
 
    def _get_total_paid(self, cr, uid, context=None):
36
 
        """
37
 
        @param cr: current row of the database
38
 
        @param uid: id of the user currently logged in
39
 
        @param context: context
40
 
        @return: total amount
41
 
        """
42
 
        if context is None:
43
 
            context = {}
44
 
        obj_voucher = self.pool.get('account.voucher')
45
 
        amount = 0.00
46
 
        if context.get('active_id'):
47
 
            amount = obj_voucher.browse(cr, uid, context['active_id'], context=context).amount 
48
 
        return amount
49
 
 
50
 
    def _get_total_allocated(self, cr, uid, context=None):
51
 
        """
52
 
        @param cr: current row of the database
53
 
        @param uid: id of the user currently logged in
54
 
        @param context: context
55
 
        @return: total allocated amount
56
 
        """
57
 
        if context is None:
58
 
            context = {}
59
 
        obj_voucher = self.pool.get('account.voucher')
60
 
        voucher = obj_voucher.browse(cr, uid, context.get('active_id', []), context=context)
61
 
        total_allocated = 0.0
62
 
        for line in voucher.line_cr_ids:
63
 
            total_allocated += line.amount
64
 
        return total_allocated
65
 
 
66
 
    def _get_ok_to_go(self, cr, uid, context=None):
67
 
        """
68
 
        @param cr: current row of the database
69
 
        @param uid: id of the user currently logged in
70
 
        @param context: context
71
 
        @return: 
72
 
        """
73
 
        if context is None:
74
 
            context = {}
75
 
        obj_voucher = self.pool.get('account.voucher')
76
 
        voucher = obj_voucher.browse(cr, uid, context.get('active_id', []), context=context)
77
 
        total_allocated = 0.0
78
 
        if context.get('invoice_type', '') == 'out_refund':
79
 
            return total_allocated
80
 
        for line in voucher.line_cr_ids:
81
 
            total_allocated += line.amount
82
 
        return total_allocated - voucher.amount
83
 
 
84
 
    _defaults = {
85
 
        'total_paid': _get_total_paid,
86
 
        'total_allocated': _get_total_allocated,
87
 
        'ok_to_go': _get_ok_to_go,
88
 
        }
89
 
    
90
 
    def onchange_ok_to_go(self, cr, uid, ids, ok_to_go, context=None):
91
 
        """
92
 
        @param cr: current row of the database
93
 
        @param uid: id of the user currently logged in
94
 
        @param ids: ids of the selected records
95
 
        @param ok_to_go: 
96
 
        @param context: context
97
 
        @return: 
98
 
        """
99
 
        if ok_to_go > 0.0:
100
 
            return {'warning': {'title': _('Overallocated invoices'), 'message': _('Reduce allocations to match Total Receipt')}}
101
 
        else:
102
 
            return {'value': {}}
103
 
        
104
 
    def launch_wizard(self, cr, uid, ids, context=None):
105
 
        """
106
 
        Don't allow post if total_allocated > total_paid.
107
 
        """
108
 
        if context is None:
109
 
            context = {}
110
 
        obj_voucher = self.pool.get('account.voucher')
111
 
        obj_voucher.action_move_line_create(cr, uid, context.get('active_ids', []), context=context)
112
 
        return {}
113
 
 
114
 
account_post_voucher()
115
 
 
116
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: