From 86f3c3f4830b3322174f143947c486766bb74f26 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 10 Feb 2022 13:53:52 +0100 Subject: [PATCH] fix validate trade form --- ereuse_devicehub/inventory/forms.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index a0ffbde9..f5bbd9ff 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -642,9 +642,18 @@ class TradeForm(NewActionForm): def validate(self, extra_validators=None): is_valid = super().validate(extra_validators) - if not self.confirm and not self.code: + if not self.confirm.data and not self.code.data: self.code.errors = ["If you don't want confirm, you need a code"] is_valid = False - return is_valid + if self.confirm.data and not (self.receiver.data or self.supplier.data): + errors = ["If you want confirm, you need a email"] + if not self.receiver.data: + self.receiver.errors = errors + if not self.supplier.data: + self.supplier.errors = errors + + is_valid = False + + return is_valid