diff --git a/InvenTree/company/apps.py b/InvenTree/company/apps.py index 0afb18f616..5f84ce507f 100644 --- a/InvenTree/company/apps.py +++ b/InvenTree/company/apps.py @@ -38,4 +38,5 @@ class CompanyConfig(AppConfig): company.image = None company.save() except (OperationalError, ProgrammingError): - print("Could not generate Company thumbnails") + # Getting here probably meant the database was in test mode + pass diff --git a/InvenTree/company/migrations/0019_auto_20200413_0642.py b/InvenTree/company/migrations/0019_auto_20200413_0642.py index c81dfd795a..c3c2f58ea0 100644 --- a/InvenTree/company/migrations/0019_auto_20200413_0642.py +++ b/InvenTree/company/migrations/0019_auto_20200413_0642.py @@ -24,7 +24,6 @@ def reverse_association(apps, schema_editor): # Exit if there are no SupplierPart objects # This crucial otherwise the unit test suite fails! if SupplierPart.objects.count() == 0: - print("No SupplierPart objects - skipping") return print("Reversing migration for manufacturer association") @@ -105,7 +104,6 @@ def associate_manufacturers(apps, schema_editor): # Exit if there are no SupplierPart objects # This crucial otherwise the unit test suite fails! if SupplierPart.objects.count() == 0: - print("No SupplierPart objects - skipping") return # Link a 'manufacturer_name' to a 'Company' diff --git a/InvenTree/part/apps.py b/InvenTree/part/apps.py index 2137ec5d89..198e58e337 100644 --- a/InvenTree/part/apps.py +++ b/InvenTree/part/apps.py @@ -37,4 +37,4 @@ class PartConfig(AppConfig): part.image = None part.save() except (OperationalError, ProgrammingError): - print("Could not generate Part thumbnails") + pass diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index fd43e683e0..9395f3e1f2 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -28,9 +28,7 @@ class RuleSet(models.Model): ('part', _('Parts')), ('stock', _('Stock')), ('build', _('Build Orders')), - ('supplier', _('Suppliers')), ('purchase_order', _('Purchase Orders')), - ('customer', _('Customers')), ('sales_order', _('Sales Orders')), ] @@ -73,6 +71,21 @@ class RuleSet(models.Model): 'build.builditem', 'stock.stockitem', 'stock.stocklocation', + ], + 'purchase_order': [ + 'company.company', + 'company.supplierpart', + 'company.supplierpricebreak', + 'order.purchaseorder', + 'order.purchaseorderattachment', + 'order.purchaseorderlineitem', + ], + 'sales_order': [ + 'company.company', + 'order.salesorder', + 'order.salesorderattachment', + 'order.salesorderlineitem', + 'order.salesorderallocation', ] } @@ -119,10 +132,11 @@ class RuleSet(models.Model): super().save(*args, **kwargs) def get_models(self): + """ + Return the database tables / models that this ruleset covers. + """ - models = { - '' - } + return self.RULESET_MODELS.get(self.name, []) def update_group_roles(group): """ @@ -157,4 +171,4 @@ def update_group_roles(group): @receiver(post_save, sender=Group) def create_missing_rule_sets(sender, instance, **kwargs): - update_group_roles(instance) \ No newline at end of file + update_group_roles(instance) diff --git a/InvenTree/users/tests.py b/InvenTree/users/tests.py index 57c7c1fe6b..3687762fba 100644 --- a/InvenTree/users/tests.py +++ b/InvenTree/users/tests.py @@ -1,4 +1,46 @@ # -*- coding: utf-8 -*- -# from __future__ import unicode_literals +from __future__ import unicode_literals + +from django.test import TestCase + +from users.models import RuleSet + + +class RuleSetModelTest(TestCase): + """ + Some simplistic tests to ensure the RuleSet model is setup correctly. + """ + + def test_ruleset_models(self): + + keys = RuleSet.RULESET_MODELS.keys() + + # Check if there are any rulesets which do not have models defined + + missing = [name for name in RuleSet.RULESET_NAMES if name not in keys] + + if len(missing) > 0: + print("The following rulesets do not have models assigned:") + for m in missing: + print("-", m) + + # Check if models have been defined for a ruleset which is incorrect + extra = [name for name in keys if name not in RuleSet.RULESET_NAMES] + + if len(extra) > 0: + print("The following rulesets have been improperly added to RULESET_MODELS:") + for e in extra: + print("-", e) + + # Check that each ruleset has models assigned + empty = [key for key in keys if len(RuleSet.RULESET_MODELS[key]) == 0] + + if len(empty) > 0: + print("The following rulesets have empty entries in RULESET_MODELS:") + for e in empty: + print("-", e) + + self.assertEqual(len(missing), 0) + self.assertEqual(len(extra), 0) + self.assertEqual(len(empty), 0) -# from django.test import TestCase