From d016cc84faba86803c3ee9730a58a97162a9c30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 25 Feb 2017 18:36:57 +0100 Subject: [PATCH] Do not use invoices function field for invoice exception This allows to reuse the design for invoices linked differently to the purchase. issue6274 review26161002 --- invoice.py | 6 ++---- purchase.py | 10 ++-------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/invoice.py b/invoice.py index 13f1b13fe1..1a8807069f 100644 --- a/invoice.py +++ b/invoice.py @@ -1,5 +1,6 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from itertools import chain from functools import wraps from sql import Table @@ -86,10 +87,7 @@ class Invoice: @ModelView.button @Workflow.transition('draft') def draft(cls, invoices): - Purchase = Pool().get('purchase.purchase') - purchases = Purchase.search([ - ('invoices', 'in', [i.id for i in invoices]), - ]) + purchases = list(chain(*(i.purchases for i in invoices))) if purchases and any(i.state == 'cancel' for i in invoices): cls.raise_user_error('reset_invoice_purchase') diff --git a/purchase.py b/purchase.py index f90583d974..797e028289 100644 --- a/purchase.py +++ b/purchase.py @@ -1580,19 +1580,13 @@ class HandleInvoiceException(Wizard): def transition_handle(self): Purchase = Pool().get('purchase.purchase') - to_recreate = self.ask.recreate_invoices - domain_invoices = self.ask.domain_invoices purchase = Purchase(Transaction().context['active_id']) - skip = set(purchase.invoices_ignored) - skip.update(purchase.invoices_recreated) invoices_ignored = [] invoices_recreated = [] - for invoice in purchase.invoices: - if invoice not in domain_invoices or invoice in skip: - continue - if invoice in to_recreate: + for invoice in self.ask.domain_invoices: + if invoice in self.ask.recreate_invoices: invoices_recreated.append(invoice.id) else: invoices_ignored.append(invoice.id)