1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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
##############################################################################
24
from tools.misc import UpdateableStr
28
FORM = UpdateableStr()
31
'entries': {'string':'Entries', 'type':'many2many', 'relation':'account.move.line',},
32
'communication2': {'string':'Communication 2', 'type':'char', 'size': 64, 'help':'The successor message of payment communication.'},
36
'duedate': {'string':'Due Date', 'type':'date','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d'),},
38
arch_duedate='''<?xml version="1.0"?>
39
<form string="Search Payment lines">
40
<field name="duedate" />
44
def search_entries(self, cr, uid, data, context):
45
search_due_date = data['form']['duedate']
47
pool = pooler.get_pool(cr.dbname)
48
order_obj = pool.get('payment.order')
49
line_obj = pool.get('account.move.line')
51
payment = order_obj.browse(cr, uid, data['id'],
55
ctx = '''context="{'journal_id': %d}"''' % payment.mode.journal.id
57
# Search for move line to pay:
58
domain = [('reconcile_id', '=', False),('account_id.type', '=', payment.type),('amount_to_pay', '<>', 0)]
59
domain = domain + ['|',('date_maturity','<',search_due_date),('date_maturity','=',False)]
61
domain = [('payment_type','=',payment.mode.type.name)] + domain
62
line_ids = line_obj.search(cr, uid, domain, context=context)
63
FORM.string = '''<?xml version="1.0"?>
64
<form string="Populate Payment:">
65
<field name="entries" colspan="4" height="300" width="800" nolabel="1"
66
domain="[('id', 'in', [%s])]" %s/>
67
<separator string="Extra message of payment communication" colspan="4"/>
68
<field name="communication2" colspan="4"/>
69
</form>''' % (','.join([str(x) for x in line_ids]), ctx)
73
def create_payment(self, cr, uid, data, context):
74
line_ids= data['form']['entries'][0][2]
75
if not line_ids: return {}
77
pool= pooler.get_pool(cr.dbname)
78
order_obj = pool.get('payment.order')
79
line_obj = pool.get('account.move.line')
81
payment = order_obj.browse(cr, uid, data['id'],
83
t = payment.mode and payment.mode.type.id or None
84
line2bank = pool.get('account.move.line').line2bank(cr, uid,
87
## Finally populate the current payment with new lines:
88
for line in line_obj.browse(cr, uid, line_ids, context=context):
89
if payment.date_prefered == "now":
90
#no payment date => immediate payment
92
elif payment.date_prefered == 'due':
93
date_to_pay = line.date_maturity
94
elif payment.date_prefered == 'fixed':
95
date_to_pay = payment.date_planned
96
pool.get('payment.line').create(cr,uid,{
97
'move_line_id': line.id,
98
'amount_currency': line.amount_to_pay,
99
'bank_id': line2bank.get(line.id),
100
'order_id': payment.id,
101
'partner_id': line.partner_id and line.partner_id.id or False,
102
'communication': (line.ref and line.name!='/' and line.ref+'. '+line.name) or line.ref or line.name or '/',
103
'communication2': data['form']['communication2'],
109
class wizard_payment_order(wizard.interface):
111
Create a payment object with lines corresponding to the account move line
112
to pay according to the date provided by the user and the mode-type payment of the order.
114
- Small number of non-reconcilied move line , payment mode and bank account type,
115
- Big number of partner and bank account.
117
If a type is given, unsuitable account move lines are ignored.
125
'arch': arch_duedate,
126
'fields':field_duedate,
129
('search','_Search', '', True)
135
'actions': [search_entries],
142
('create','_Add to payment order', '', True)
150
'action': create_payment,
155
wizard_payment_order('populate_payment_ext')
157
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: