98
98
'rejected': [('readonly', True)],
99
99
'done': [('readonly', True)]
101
help=("Choose an option for the Payment Order:'Fixed' stands for a "
102
"date specified by you.'Directly' stands for the direct "
101
help=("Choose an option for the Payment Order:'Fixed' stands for "
102
"a date specified by you.'Directly' stands for the direct "
103
103
"execution.'Due date' stands for the scheduled date of "
107
107
'date_sent': fields.date('Send date', readonly=True),
110
110
def _write_payment_lines(self, cr, uid, ids, **kwargs):
112
ORM method for setting attributes of corresponding payment.line objects.
112
ORM method for setting attributes of corresponding payment.line
113
114
Note that while this is ORM compliant, it is also very ineffecient due
114
115
to the absence of filters on writes and hence the requirement to
115
116
filter on the client(=OpenERP server) side.
175
176
uid, 'payment.order', payment_order_id, 'done', cr)
176
177
return reconcile_id
178
def debit_unreconcile_transfer(self, cr, uid, payment_order_id, reconcile_id,
179
amount, currency, context=None):
179
def debit_unreconcile_transfer(
180
self, cr, uid, payment_order_id, reconcile_id, amount, currency,
181
183
Due to a cancelled bank statements import, unreconcile the move on
182
184
the transfer account. Delegate the conditions to the workflow.
213
215
for order in self.browse(cr, uid, ids, context=context):
214
216
for order_line in order.line_ids:
215
217
if order_line.transit_move_line_id.move_id:
216
for line in order_line.transit_move_line_id.move_id.line_id:
219
order_line.transit_move_line_id.move_id.line_id:
217
220
if (line.account_id.type == 'other' and
218
221
line.reconcile_id):
225
def _prepare_transfer_move(
226
self, cr, uid, order, line, labels, context=None):
228
'journal_id': order.mode.transfer_journal_id.id,
229
'name': '%s %s' % (labels[order.payment_order_type],
231
and line.move_line_id.move_id.name
232
or line.communication),
233
'ref': '%s %s' % (order.payment_order_type[:3].upper(),
235
and line.move_line_id.move_id.name
236
or line.communication),
240
def _prepare_move_line_transfer_account(
241
self, cr, uid, order, line, move_id, labels, context=None):
243
'name': _('%s for %s') % (
244
labels[order.payment_order_type],
245
line.move_line_id and (line.move_line_id.invoice
246
and line.move_line_id.invoice.number
247
or line.move_line_id.name)
248
or line.communication),
251
'account_id': order.mode.transfer_account_id.id,
252
'credit': (order.payment_order_type == 'payment'
253
and line.amount or 0.0),
254
'debit': (order.payment_order_type == 'debit'
255
and line.amount or 0.0),
256
'date': fields.date.context_today(
257
self, cr, uid, context=context),
261
def _update_move_line_partner_account(
262
self, cr, uid, order, line, vals, context=None):
264
'partner_id': line.partner_id.id,
265
'account_id': (line.move_line_id
266
and line.move_line_id.account_id.id
268
# if not line.move_line_id, the field 'account_id' must be set by
269
# another module that inherit this function, like for example in
270
# the module purchase_payment_order
271
'credit': (order.payment_order_type == 'debit'
272
and line.amount or 0.0),
273
'debit': (order.payment_order_type == 'payment'
274
and line.amount or 0.0),
278
def action_sent_no_move_line_hook(self, cr, uid, pay_line, context=None):
279
"""This function is designed to be inherited"""
222
282
def action_sent(self, cr, uid, ids, context=None):
224
284
Create the moves that pay off the move lines from
225
285
the debit order. This happens when the debit order file is
233
293
'debit': _('Direct debit order'),
235
295
for order in self.browse(cr, uid, ids, context=context):
236
if not order.mode.transfer_journal_id or not order.mode.transfer_account_id:
296
if not order.mode.transfer_journal_id \
297
or not order.mode.transfer_account_id:
238
299
for line in order.line_ids:
240
if not line.move_line_id:
241
raise orm.except_orm(
243
_('No move line provided for line %s') % line.name)
244
if line.move_line_id.reconcile_id:
245
raise orm.except_orm(
247
_('Move line %s has already been paid/reconciled') %
248
line.move_line_id.name
301
if line.move_line_id and line.move_line_id.reconcile_id:
302
raise orm.except_orm(
304
_('Move line %s has already been paid/reconciled')
305
% line.move_line_id.name)
251
move_id = account_move_obj.create(cr, uid, {
252
'journal_id': order.mode.transfer_journal_id.id,
253
'name': '%s %s' % (labels[order.payment_order_type],
254
line.move_line_id.move_id.name),
255
'ref': '%s%s' % (order.payment_order_type[:3].upper(),
256
line.move_line_id.move_id.name),
307
move_id = account_move_obj.create(
308
cr, uid, self._prepare_transfer_move(
309
cr, uid, order, line, labels, context=context),
259
312
# TODO: take multicurrency into account
261
314
# create the debit move line on the transfer account
263
'name': _('%s for %s') % (
264
labels[order.payment_order_type],
265
line.move_line_id.invoice and
266
line.move_line_id.invoice.number or
267
line.move_line_id.name),
270
'account_id': order.mode.transfer_account_id.id,
271
'credit': (order.payment_order_type == 'payment'
272
and line.amount or 0.0),
273
'debit': (order.payment_order_type == 'debit'
274
and line.amount or 0.0),
275
'date': fields.date.context_today(
276
self, cr, uid, context=context),
278
transfer_move_line_id = account_move_line_obj.create(
279
cr, uid, vals, context=context)
315
ml_vals = self._prepare_move_line_transfer_account(
316
cr, uid, order, line, move_id, labels, context=context)
317
account_move_line_obj.create(cr, uid, ml_vals, context=context)
281
# create the debit move line on the receivable account
283
'partner_id': line.partner_id.id,
284
'account_id': line.move_line_id.account_id.id,
285
'credit': (order.payment_order_type == 'debit'
286
and line.amount or 0.0),
287
'debit': (order.payment_order_type == 'payment'
288
and line.amount or 0.0),
319
# create the debit move line on the partner account
320
self._update_move_line_partner_account(
321
cr, uid, order, line, ml_vals, context=context)
290
322
reconcile_move_line_id = account_move_line_obj.create(
291
cr, uid, vals, context=context)
323
cr, uid, ml_vals, context=context)
293
325
# register the debit move line on the payment line
294
326
# and call reconciliation on it
295
327
payment_line_obj.write(
297
329
{'transit_move_line_id': reconcile_move_line_id},
300
payment_line_obj.debit_reconcile(
301
cr, uid, line.id, context=context)
332
if line.move_line_id:
333
payment_line_obj.debit_reconcile(
334
cr, uid, line.id, context=context)
336
self.action_sent_no_move_line_hook(
337
cr, uid, line, context=context)
302
338
account_move_obj.post(cr, uid, [move_id], context=context)
304
340
# State field is written by act_sent_wait
305
341
self.write(cr, uid, ids, {
306
'date_sent': fields.date.context_today(
307
self, cr, uid, context=context),
342
'date_sent': fields.date.context_today(
343
self, cr, uid, context=context),