-
Notifications
You must be signed in to change notification settings - Fork 2
/
payment.py
36 lines (31 loc) · 1.32 KB
/
payment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# This file is part account_invoice_posted2draft module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.pool import Pool, PoolMeta
from trytond.i18n import gettext
from trytond.exceptions import UserError
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
@classmethod
def draft(cls, invoices):
pool = Pool()
Payment = pool.get('account.payment')
for invoice in invoices:
moves = []
if invoice.move:
moves.append(invoice.move)
if invoice.additional_moves:
moves.extend(invoice.additional_moves)
if moves:
lines = [l.id for m in moves for l in m.lines]
if lines:
payments = Payment.search([
('line', 'in', lines),
('state', '!=', 'failed'),
])
if payments:
raise UserError(gettext('account_invoice_posted2draft'
'.msg_invoice_in_payment',
invoice=invoice.rec_name,
payments=", ".join([str(p.id) for p in payments])))
return super().draft(invoices)