1
# -*- coding: utf-8 -*-
2
##############################################################################
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>)
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.
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.
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/>
21
##############################################################################
23
from osv import fields, osv
24
from tools.translate import _
26
class account_post_voucher(osv.osv_memory):
27
_name = 'account.post.voucher'
28
_description = 'Account Pay Voucher'
30
'total_paid': fields.float('Total Received'),
31
'total_allocated': fields.float('Total Allocated'),
32
'ok_to_go': fields.float('OK to Go'),
35
def _get_total_paid(self, cr, uid, context=None):
37
@param cr: current row of the database
38
@param uid: id of the user currently logged in
39
@param context: context
44
obj_voucher = self.pool.get('account.voucher')
46
if context.get('active_id'):
47
amount = obj_voucher.browse(cr, uid, context['active_id'], context=context).amount
50
def _get_total_allocated(self, cr, uid, context=None):
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
59
obj_voucher = self.pool.get('account.voucher')
60
voucher = obj_voucher.browse(cr, uid, context.get('active_id', []), context=context)
62
for line in voucher.line_cr_ids:
63
total_allocated += line.amount
64
return total_allocated
66
def _get_ok_to_go(self, cr, uid, context=None):
68
@param cr: current row of the database
69
@param uid: id of the user currently logged in
70
@param context: context
75
obj_voucher = self.pool.get('account.voucher')
76
voucher = obj_voucher.browse(cr, uid, context.get('active_id', []), context=context)
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
85
'total_paid': _get_total_paid,
86
'total_allocated': _get_total_allocated,
87
'ok_to_go': _get_ok_to_go,
90
def onchange_ok_to_go(self, cr, uid, ids, ok_to_go, context=None):
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
96
@param context: context
100
return {'warning': {'title': _('Overallocated invoices'), 'message': _('Reduce allocations to match Total Receipt')}}
104
def launch_wizard(self, cr, uid, ids, context=None):
106
Don't allow post if total_allocated > total_paid.
110
obj_voucher = self.pool.get('account.voucher')
111
obj_voucher.action_move_line_create(cr, uid, context.get('active_ids', []), context=context)
114
account_post_voucher()
116
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: