diff --git a/README.md b/README.md index 4713866..7f7f714 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ This is a plugin for [InvenTree](https://github.com/inventree/InvenTree/). Installing this plugin enables the automatic generation if Internal Part Numbers (IPN) for parts. ## Installation -NOT YET PUBLISHED! - To automatically install the plugin when running `invoke install`: Add `inventree-ipn-generator` to your plugins.txt file. @@ -16,6 +14,9 @@ Or, install the plugin manually: pip install inventree-ipn-generator ``` +For the plugin to be listed as available, you need to enable "Event Integration" in your plugin settings. +This setting is located with the Plugin Settings on the settings page. + ## Settings - Active - Enables toggling of plugin without having to disable it diff --git a/ipn_generator/generator.py b/ipn_generator/generator.py index 431f956..d50d1dc 100644 --- a/ipn_generator/generator.py +++ b/ipn_generator/generator.py @@ -1,5 +1,3 @@ -"""Does this need to be here maybe?""" - from plugin import InvenTreePlugin from plugin.mixins import EventMixin, SettingsMixin from part.models import Part @@ -24,11 +22,13 @@ def validate_pattern(pattern): class AutoGenIPNPlugin(EventMixin, SettingsMixin, InvenTreePlugin): """Plugin to generate IPN automatically""" - AUTHOR = "Nichlas Walsøe" + AUTHOR = "Nichlas W." DESCRIPTION = ( - "Plugin for automatically assigning IPN to parts created with empty IPN fields." + "Plugin for automatically assigning IPN to parts created with empty IPN fields.\ + IPN pattern syntax can be found on the website linked here." ) VERSION = "0.1" + WEBSITE = "https://github.com/LavissaWoW/inventree-ipn-generator" NAME = "IPNGenerator" SLUG = "ipngen" @@ -36,27 +36,27 @@ class AutoGenIPNPlugin(EventMixin, SettingsMixin, InvenTreePlugin): SETTINGS = { "ACTIVE": { - "name": ("Active"), - "description": ("IPN generator is active"), + "name": "Active", + "description": "IPN generator is active", "validator": bool, "default": True, }, "ON_CREATE": { - "name": ("On Create"), - "description": ("Active when creating new parts"), + "name": "On Create", + "description": "Active when creating new parts", "validator": bool, "default": True, }, "ON_CHANGE": { - "name": ("On Edit"), - "description": ("Active when editing existing parts"), + "name": "On Edit", + "description": "Active when editing existing parts", "validator": bool, - "default": True, + "default": False, }, "PATTERN": { - "name": ("IPN pattern"), - "description": ("Pattern for IPN generation"), - "default": "(12)[a-z][a-d]", + "name": "IPN pattern", + "description": "Pattern for IPN generation (See website for guide)", + "default": "(IPN-){4}", "validator": validate_pattern, }, } diff --git a/ipn_generator/tests/test_IPNGenerator.py b/ipn_generator/tests/test_IPNGenerator.py index f57d7ed..5e811c7 100644 --- a/ipn_generator/tests/test_IPNGenerator.py +++ b/ipn_generator/tests/test_IPNGenerator.py @@ -3,7 +3,8 @@ import logging from django.conf import settings -from part.models import Part, PartCategory +from part.models import PartCategory, SupplierPart, Part +from company.models import Company from common.models import InvenTreeSetting from plugin import registry @@ -379,3 +380,29 @@ def test_only_last_incrementable_is_changed(self): part = Part.objects.get(pk=p.pk) self.assertEqual(part.IPN, "a26") + + +class IPNGeneratorModelTests(TestCase): + """Verify model behaviours""" + + def setUp(self): + """Set up test environment""" + setup_func(self) + + def tearDown(self): + """Teardown test environment""" + teardown_func() + + def test_supplier_part_does_not_trigger_plugin(self): + """Supplier parts events should not trigger the plugin""" + + cat = PartCategory.objects.all().first() + part = Part.objects.create(category=cat, name="PartName") + supplier = Company.objects.create(name="Suppliercompany", currency="USD") + + with self.assertLogs(logger=logger, level="DEBUG") as cm: + SupplierPart.objects.create(part=part, SKU="abc", supplier=supplier) + self.assertNotIn( + "DEBUG:inventree:Plugin 'ipngen' is processing triggered event 'part_part.created'", + cm[1], + )