From d8494aef0dbca805ccc5d207d91985765e3383d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 25 Jun 2016 14:56:40 +0200 Subject: [PATCH] [FIX+IMP] account_payment_order: 2 things: * IMP: prevent deleting a move-line that is linked to a payment order line * FIX: better filtering of move lines already included in open payment order --- account_payment_order/models/account_payment_line.py | 3 ++- account_payment_order/wizard/account_payment_line_create.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/account_payment_order/models/account_payment_line.py b/account_payment_order/models/account_payment_line.py index 5df4c2644..a938cc7c6 100644 --- a/account_payment_order/models/account_payment_line.py +++ b/account_payment_order/models/account_payment_line.py @@ -27,7 +27,8 @@ class AccountPaymentLine(models.Model): related='order_id.state', string='State', readonly=True, store=True) move_line_id = fields.Many2one( - 'account.move.line', string='Journal Item') + 'account.move.line', string='Journal Item', + ondelete='restrict') ml_maturity_date = fields.Date( related='move_line_id.date_maturity', readonly=True) currency_id = fields.Many2one( diff --git a/account_payment_order/wizard/account_payment_line_create.py b/account_payment_order/wizard/account_payment_line_create.py index f131db886..16fe79cbd 100644 --- a/account_payment_order/wizard/account_payment_line_create.py +++ b/account_payment_order/wizard/account_payment_line_create.py @@ -112,9 +112,11 @@ class AccountPaymentLineCreate(models.TransientModel): ('debit', '>', 0), ('account_id.internal_type', '=', 'receivable'), ] - # Exclude lines that are already in a non-cancelled payment order + # Exclude lines that are already in a non-cancelled + # and non-uploaded payment order; lines that are in a + # uploaded payment order are proposed if they are not reconciled, paylines = self.env['account.payment.line'].search([ - ('state', '!=', 'cancel'), + ('state', 'in', ('draft', 'open', 'generated')), ('move_line_id', '!=', False)]) if paylines: move_lines_ids = [payline.move_line_id.id for payline in paylines]