fixed-asset-plugin 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fixed_asset_plugin/__init__.py +3 -0
- fixed_asset_plugin/core.py +110 -0
- fixed_asset_plugin-0.1.0.dist-info/METADATA +46 -0
- fixed_asset_plugin-0.1.0.dist-info/RECORD +8 -0
- fixed_asset_plugin-0.1.0.dist-info/WHEEL +5 -0
- fixed_asset_plugin-0.1.0.dist-info/entry_points.txt +2 -0
- fixed_asset_plugin-0.1.0.dist-info/licenses/LICENSE +21 -0
- fixed_asset_plugin-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"""Add Fixed Asset Parameter to every new Part created"""
|
|
2
|
+
|
|
3
|
+
from plugin import InvenTreePlugin
|
|
4
|
+
|
|
5
|
+
from plugin.mixins import EventMixin
|
|
6
|
+
|
|
7
|
+
from part.models import Part, PartParameter, PartParameterTemplate
|
|
8
|
+
|
|
9
|
+
from . import PLUGIN_VERSION
|
|
10
|
+
|
|
11
|
+
import logging
|
|
12
|
+
from typing import Optional
|
|
13
|
+
# import os
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class FixedAssetPlugin(EventMixin, InvenTreePlugin):
|
|
19
|
+
|
|
20
|
+
"""FixedAssetPlugin - custom InvenTree plugin."""
|
|
21
|
+
|
|
22
|
+
# Plugin metadata
|
|
23
|
+
TITLE = "Fixed Asset Plugin"
|
|
24
|
+
NAME = "FixedAssetPlugin"
|
|
25
|
+
SLUG = "fixed-asset-plugin"
|
|
26
|
+
DESCRIPTION = "Add Fixed Asset Parameter to every new Part created"
|
|
27
|
+
VERSION = PLUGIN_VERSION
|
|
28
|
+
AUTHOR = "Adrian Piney Gutierrez"
|
|
29
|
+
LICENSE = "MIT"
|
|
30
|
+
|
|
31
|
+
# Variables
|
|
32
|
+
|
|
33
|
+
TEMPLATE_NAME = "Fixed Asset"
|
|
34
|
+
# TEMPLATE_ID = ""
|
|
35
|
+
|
|
36
|
+
# Optionally specify supported InvenTree versions
|
|
37
|
+
# MIN_VERSION = '0.18.0'
|
|
38
|
+
# MAX_VERSION = '2.0.0'
|
|
39
|
+
|
|
40
|
+
def __init__(self):
|
|
41
|
+
super().__init__()
|
|
42
|
+
self.logger = logging.getLogger(f"plugin.{self.SLUG}")
|
|
43
|
+
try:
|
|
44
|
+
self.template = PartParameterTemplate.objects.get(name=self.TEMPLATE_NAME)
|
|
45
|
+
|
|
46
|
+
except PartParameterTemplate.DoesNotExist:
|
|
47
|
+
self.template = None
|
|
48
|
+
logger.error(f"Template {self.TEMPLATE_NAME} not found")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# Configure custom logger to write to file
|
|
52
|
+
# log_dir = '/home/inventree/data/log'
|
|
53
|
+
# os.makedirs(log_dir, exist_ok=True)
|
|
54
|
+
# log_file = os.path.join(log_dir, 'fixed_asset_plugin.log')
|
|
55
|
+
|
|
56
|
+
# self.logger = logging.getLogger(self.NAME)
|
|
57
|
+
# self.logger.setLevel(logging.INFO)
|
|
58
|
+
|
|
59
|
+
# file_handler = logging.FileHandler(log_file)
|
|
60
|
+
# file_handler.setFormatter(logging.Formatter('[%(asctime)s] %(levelname)s: %(message)s'))
|
|
61
|
+
|
|
62
|
+
# # Prevent duplicate handlers on reload
|
|
63
|
+
# if not self.logger.handlers:
|
|
64
|
+
# self.logger.addHandler(file_handler)
|
|
65
|
+
# =============================================
|
|
66
|
+
|
|
67
|
+
def _get_part_from_event(self, *, args, kwargs) -> Optional[Part]:
|
|
68
|
+
if kwargs.get('model') != 'Part':
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
pid = kwargs.get('id')
|
|
72
|
+
if pid is not None:
|
|
73
|
+
return Part.objects.filter(pk=pid).first()
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
# Respond to InvenTree events (from EventMixin)
|
|
78
|
+
# Ref: https://docs.inventree.org/en/stable/extend/plugins/event/
|
|
79
|
+
def wants_process_event(self, event: str) -> bool:
|
|
80
|
+
"""Return True if the plugin wants to process the given event."""
|
|
81
|
+
return event == 'part_part.created'
|
|
82
|
+
|
|
83
|
+
def process_event(self, event: str, *args, **kwargs) -> None:
|
|
84
|
+
|
|
85
|
+
# Check de los args para comprobar datos
|
|
86
|
+
self.logger.debug(f"fixed-asset-plugin args={args}, kwargs={kwargs}")
|
|
87
|
+
|
|
88
|
+
part = self._get_part_from_event(args=args, kwargs=kwargs)
|
|
89
|
+
|
|
90
|
+
if not part:
|
|
91
|
+
self.logger.debug("Ignoring event: not a Part or not ID")
|
|
92
|
+
return
|
|
93
|
+
|
|
94
|
+
if not self.template:
|
|
95
|
+
return
|
|
96
|
+
|
|
97
|
+
if PartParameter.objects.filter(part=part, template=self.template).exists():
|
|
98
|
+
self.logger.debug(f"Part {part.pk} ya tiene '{self.template.name}'")
|
|
99
|
+
return
|
|
100
|
+
|
|
101
|
+
try:
|
|
102
|
+
PartParameter.objects.create(
|
|
103
|
+
part=part,
|
|
104
|
+
template=self.template,
|
|
105
|
+
data=False
|
|
106
|
+
)
|
|
107
|
+
self.logger.info(f"Added '{self.template.name}' parameter to Part {part.pk}")
|
|
108
|
+
|
|
109
|
+
except Exception as e:
|
|
110
|
+
self.logger.error(f"Error adding parameter: {e}")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: fixed_asset_plugin
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Add Fixed Asset Parameter to every new Part created
|
|
5
|
+
Author: Adrian Piney Gutierrez
|
|
6
|
+
Author-email: adrian.piney@unican.es
|
|
7
|
+
License: MIT
|
|
8
|
+
Requires-Python: >=3.9
|
|
9
|
+
Description-Content-Type: text/markdown
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Requires-Dist: inventree>=0.17.0
|
|
12
|
+
Dynamic: author
|
|
13
|
+
Dynamic: author-email
|
|
14
|
+
Dynamic: description
|
|
15
|
+
Dynamic: description-content-type
|
|
16
|
+
Dynamic: license
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
Dynamic: requires-dist
|
|
19
|
+
Dynamic: requires-python
|
|
20
|
+
Dynamic: summary
|
|
21
|
+
|
|
22
|
+
# FixedAssetPlugin
|
|
23
|
+
|
|
24
|
+
Add Fixed Asset Parameter to every new Part created
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
### InvenTree Plugin Manager
|
|
29
|
+
|
|
30
|
+
... todo ...
|
|
31
|
+
|
|
32
|
+
### Command Line
|
|
33
|
+
|
|
34
|
+
To install manually via the command line, run the following command:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install fixed-asset-plugin
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
... todo ...
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
... todo ...
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
fixed_asset_plugin/__init__.py,sha256=AamVBjEe3jzcFGrwK_0mC4sI1NjzOOLvT9k7BvLzj7E,50
|
|
2
|
+
fixed_asset_plugin/core.py,sha256=Brzx9OO6fR27UnieE8vv99zvjzbOE8IJN3kw2A3Zwmo,3504
|
|
3
|
+
fixed_asset_plugin-0.1.0.dist-info/licenses/LICENSE,sha256=GhhUqqR_5Etovl1elW5ovbvsbifigP9648ulhKgjw8Q,1133
|
|
4
|
+
fixed_asset_plugin-0.1.0.dist-info/METADATA,sha256=KMOPF0EBKBNj3BhTa7T5pr9q5UXqhgbj8lcpXuw5huk,888
|
|
5
|
+
fixed_asset_plugin-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
6
|
+
fixed_asset_plugin-0.1.0.dist-info/entry_points.txt,sha256=mAEHNNbhH-BXBppdFXABC-nsZ5zE9h00wGV8IpERtMA,82
|
|
7
|
+
fixed_asset_plugin-0.1.0.dist-info/top_level.txt,sha256=tPbtO_wyTn7m3AwUMQIEk1byIkyCuND-oB1VuW_dZP4,19
|
|
8
|
+
fixed_asset_plugin-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Adrian Piney Gutierrez <adrian.piney@unican.es>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
fixed_asset_plugin
|