Skip to content

Commit

Permalink
Last adjustments for release
Browse files Browse the repository at this point in the history
  • Loading branch information
LavissaWoW committed Mar 21, 2024
1 parent 79eb855 commit e8de57c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
Expand Down
28 changes: 14 additions & 14 deletions ipn_generator/generator.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,39 +22,41 @@ 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"
TITLE = "IPN Generator"

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,
},
}
Expand Down
29 changes: 28 additions & 1 deletion ipn_generator/tests/test_IPNGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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],
)

0 comments on commit e8de57c

Please sign in to comment.