1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20
##############################################################################
22
from lxml import etree
27
from osv import osv,fields
28
from tools.translate import _
29
import decimal_precision as dp
31
class wizard_cash_payment(osv.osv_memory):
32
_name = 'account.wizard_cash_payment'
33
_description = 'Wizard Cash Payment'
36
'journal_id' : fields.many2one(string='Journal', obj='account.journal', required=True),
37
'name' : fields.char(string='Description', size=100, required=True),
38
'date':fields.date(string='Date', required=True),
41
def fields_view_get(self, cr, uid, view_id=None, view_type=False, context=None, toolbar=False, submenu=False):
42
res = super(wizard_cash_payment, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
44
mod_obj = self.pool.get('ir.model.data')
45
obj_account_voucher_type = self.pool.get('account.voucher_type')
46
if context is None: context = {}
48
voucher_type = context.get('voucher_type')
50
if voucher_type and view_type == 'form':
52
kriteria = [('name','=',voucher_type)]
53
voucher_type_ids = obj_account_voucher_type.search(cr, uid, kriteria)[0]
55
voucher = obj_account_voucher_type.browse(cr, uid, voucher_type_ids, context=context)
57
result = mod_obj.get_object_reference(cr, uid, voucher.modul_origin, voucher.model_view_form)
58
result = result and result[1] or False
61
if voucher.allowed_journal_ids:
62
for journal in voucher.allowed_journal_ids:
64
domain_journal = list(set(x))
66
for field in res['fields']:
67
if field == 'journal_id':
68
res['fields'][field]['domain'] = [('id','in',domain_journal)]
71
def view_init(self, cr, uid, fields_list, context=None):
73
obj_account_invoice = self.pool.get('account.invoice')
78
res = super(wizard_cash_payment, self).view_init(cr, uid, fields_list, context=context)
80
record_id = context and context.get('active_id', False)
84
invoice = obj_account_invoice.browse(cr, uid, record_id, context=context)
86
if invoice.state != 'open' :
87
raise osv.except_osv(_('Warning !'), _("You may only pay invoices that are Open !"))
90
def get_total(self, cr, uid, context=None):
91
obj_account_invoice = self.pool.get('account.invoice')
92
record_id = context.get('active_ids')
95
for data in record_id:
96
invoice_id = obj_account_invoice.browse(cr, uid, data)
97
total = total + invoice_id.residual
101
def cash_payment(self, cr, uid, ids, context=None):
102
obj_account_cash_payment = self.pool.get('account.cash_payment')
103
obj_account_voucher_line = self.pool.get('account.voucher.line')
104
obj_account_move_line = self.pool.get('account.move.line')
105
obj_account_invoice = self.pool.get('account.invoice')
106
obj_account_journal = self.pool.get('account.journal')
107
obj_account_voucher_type = self.pool.get('account.voucher_type')
108
obj_account_period = self.pool.get('account.period')
110
record_id = context.get('active_ids')
112
wizard = self.read(cr, uid, ids[0], context=context)
114
#raise osv.except_osv(_('Error !'), _('%s')%record_id[0])
116
journal = obj_account_journal.browse(cr, uid, wizard['journal_id'][0])
117
voucher_currency_id = journal.currency and journal.currency.id or journal.company_id.currency_id.id
119
voucher_type_ids = obj_account_voucher_type.search(cr, uid, [('name','=','Cash Payment')])[0]
121
voucher_type = obj_account_voucher_type.browse(cr, uid, voucher_type_ids)
123
period_id = obj_account_period.find(cr, uid, wizard['date'], context)
126
'journal_id' : wizard['journal_id'][0],
127
'name' : wizard['name'],
128
'date' : wizard['date'],
129
'account_id' : journal.default_debit_account_id.id,
130
'voucher_type_id' : voucher_type.id,
131
'type' : voucher_type.default_header_type,
132
'amount' : self.get_total(cr, uid, context),
133
'period_id' : period_id[0],
136
new_account_cash_payment_id = obj_account_cash_payment.create(cr, uid, val_header, context)
138
for data in record_id:
140
invoice_id = obj_account_invoice.browse(cr, uid, data)
142
move_line_ids = obj_account_move_line.search(cr, uid, [('move_id','=',invoice_id.move_id.id)])
144
for move_line in obj_account_move_line.browse(cr, uid, move_line_ids):
145
if move_line.account_id.type == 'payable':
146
amount = obj_account_voucher_line.compute_amount(cr, uid, move_line.id, move_line.journal_id.id, voucher_currency_id)['amount']
148
'voucher_id' : new_account_cash_payment_id,
149
'account_id' : move_line.account_id.id,
150
'move_line_id' : move_line.id,
151
'name' : wizard['name'],
154
'partner_id' : move_line.partner_id.id,
156
new_account_cash_payment_detail_id = obj_account_voucher_line.create(cr, uid, val, context)
159
'res_id' : new_account_cash_payment_id,
160
'name' : 'Cash Payment',
161
'view_type' : 'form',
162
'view_mode' : 'form',
163
'res_model' : 'account.cash_payment', #TODO
164
'type' : 'ir.actions.act_window',
168
wizard_cash_payment()
170
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: