From 1caa341f8e588759f4375ded9e244da96ccbc95e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 30 Oct 2020 21:34:56 +1100 Subject: [PATCH] Fixes for unit tests --- InvenTree/order/forms.py | 10 +++++----- InvenTree/order/test_views.py | 4 +--- InvenTree/order/views.py | 3 ++- InvenTree/part/models.py | 2 +- InvenTree/part/views.py | 2 +- InvenTree/stock/models.py | 4 +++- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 1f412271e0..770dd392bf 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -21,7 +21,7 @@ from .models import SalesOrderAllocation class IssuePurchaseOrderForm(HelperForm): - confirm = forms.BooleanField(required=False, help_text=_('Place order')) + confirm = forms.BooleanField(required=True, initial=False, help_text=_('Place order')) class Meta: model = PurchaseOrder @@ -32,7 +32,7 @@ class IssuePurchaseOrderForm(HelperForm): class CompletePurchaseOrderForm(HelperForm): - confirm = forms.BooleanField(required=False, help_text=_("Mark order as complete")) + confirm = forms.BooleanField(required=True, help_text=_("Mark order as complete")) class Meta: model = PurchaseOrder @@ -43,7 +43,7 @@ class CompletePurchaseOrderForm(HelperForm): class CancelPurchaseOrderForm(HelperForm): - confirm = forms.BooleanField(required=False, help_text=_('Cancel order')) + confirm = forms.BooleanField(required=True, help_text=_('Cancel order')) class Meta: model = PurchaseOrder @@ -54,7 +54,7 @@ class CancelPurchaseOrderForm(HelperForm): class CancelSalesOrderForm(HelperForm): - confirm = forms.BooleanField(required=False, help_text=_('Cancel order')) + confirm = forms.BooleanField(required=True, help_text=_('Cancel order')) class Meta: model = SalesOrder @@ -65,7 +65,7 @@ class CancelSalesOrderForm(HelperForm): class ShipSalesOrderForm(HelperForm): - confirm = forms.BooleanField(required=False, help_text=_('Ship order')) + confirm = forms.BooleanField(required=True, help_text=_('Ship order')) class Meta: model = SalesOrder diff --git a/InvenTree/order/test_views.py b/InvenTree/order/test_views.py index 246cc2dd48..5c4e2dd405 100644 --- a/InvenTree/order/test_views.py +++ b/InvenTree/order/test_views.py @@ -113,6 +113,7 @@ class POTests(OrderViewTestCase): self.assertEqual(response.status_code, 200) data = json.loads(response.content) + self.assertFalse(data['form_valid']) # Test WITH confirmation @@ -151,7 +152,6 @@ class POTests(OrderViewTestCase): response = self.client.post(url, post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') data = json.loads(response.content) self.assertFalse(data['form_valid']) - self.assertIn('Invalid Purchase Order', str(data['html_form'])) # POST with a part that does not match the purchase order post_data['order'] = 1 @@ -159,14 +159,12 @@ class POTests(OrderViewTestCase): response = self.client.post(url, post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') data = json.loads(response.content) self.assertFalse(data['form_valid']) - self.assertIn('must match for Part and Order', str(data['html_form'])) # POST with an invalid part post_data['part'] = 12345 response = self.client.post(url, post_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest') data = json.loads(response.content) self.assertFalse(data['form_valid']) - self.assertIn('Invalid SupplierPart selection', str(data['html_form'])) # POST the form with valid data post_data['part'] = 100 diff --git a/InvenTree/order/views.py b/InvenTree/order/views.py index 333509952b..e411afbdad 100644 --- a/InvenTree/order/views.py +++ b/InvenTree/order/views.py @@ -454,7 +454,7 @@ class PurchaseOrderIssue(AjaxUpdateView): def validate(self, order, form, **kwargs): - confirm = str2bool(form.cleaned_data.get('confirm', False)) + confirm = str2bool(self.request.POST.get('confirm', False)) if not confirm: form.add_error('confirm', _('Confirm order placement')) @@ -504,6 +504,7 @@ class PurchaseOrderComplete(AjaxUpdateView): 'success': _('Purchase order completed') } + class SalesOrderShip(AjaxUpdateView): """ View for 'shipping' a SalesOrder """ form_class = order_forms.ShipSalesOrderForm diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 34beb4b68e..715d1423eb 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1141,7 +1141,7 @@ class Part(MPTTModel): if clear: self.get_parameters().delete() - for parameter in other.get_parameters.all(): + for parameter in other.get_parameters(): # If this part already has a parameter pointing to the same template, # delete that parameter from this part first! diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index 2dd3a47c3f..0b96addc84 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -372,7 +372,7 @@ class MakePartVariant(AjaxCreateView): initials['is_template'] = False initials['variant_of'] = part_template initials['bom_copy'] = InvenTreeSetting.get_setting('PART_COPY_BOM') - initials['parameters_copy'] = InvenTreeSetting.get_seting('PART_COPY_PARAMETERS') + initials['parameters_copy'] = InvenTreeSetting.get_setting('PART_COPY_PARAMETERS') return initials diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 1a58592f26..11ec0bd087 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1130,6 +1130,9 @@ class StockItem(MPTTModel): def clear_test_results(self, **kwargs): """ Remove all test results + + kwargs: + TODO """ # All test results @@ -1139,7 +1142,6 @@ class StockItem(MPTTModel): results.delete() - def getTestResults(self, test=None, result=None, user=None): """ Return all test results associated with this StockItem.