mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-14 02:55:41 +00:00
add PO wildcard default setting
This commit is contained in:
@ -17,7 +17,7 @@ repos:
|
||||
- id: check-yaml
|
||||
- id: mixed-line-ending
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.7.3
|
||||
rev: v0.7.4
|
||||
hooks:
|
||||
- id: ruff-format
|
||||
args: [--preview]
|
||||
@ -28,7 +28,7 @@ repos:
|
||||
--preview
|
||||
]
|
||||
- repo: https://github.com/astral-sh/uv-pre-commit
|
||||
rev: 0.5.1
|
||||
rev: 0.5.3
|
||||
hooks:
|
||||
- id: pip-compile
|
||||
name: pip-compile requirements-dev.in
|
||||
|
@ -289,6 +289,7 @@ class ReferenceIndexingMixin(models.Model):
|
||||
|
||||
# Name of the global setting which defines the required reference pattern for this model
|
||||
REFERENCE_PATTERN_SETTING = None
|
||||
REFERENCE_PATTERN_WILDCARD_DEFAULT_SETTING = None
|
||||
|
||||
class Meta:
|
||||
"""Metaclass options. Abstract ensures no database table is created."""
|
||||
@ -309,6 +310,28 @@ class ReferenceIndexingMixin(models.Model):
|
||||
cls.REFERENCE_PATTERN_SETTING, create=False
|
||||
).strip()
|
||||
|
||||
@classmethod
|
||||
def get_reference_pattern_wildcard_default(cls):
|
||||
"""Returns the reference pattern associated with this model.
|
||||
|
||||
This is defined by a global setting object, specified by the REFERENCE_PATTERN_WILDCARD_DEFAULT_SETTING attribute
|
||||
"""
|
||||
# By default, we return None to indicate no default exists
|
||||
if cls.REFERENCE_PATTERN_WILDCARD_DEFAULT_SETTING is None:
|
||||
return None
|
||||
|
||||
# import at function level to prevent cyclic imports
|
||||
from common.models import InvenTreeSetting
|
||||
|
||||
setting = InvenTreeSetting.get_setting(
|
||||
cls.REFERENCE_PATTERN_WILDCARD_DEFAULT_SETTING, create=False
|
||||
).strip()
|
||||
|
||||
if setting == '':
|
||||
return None
|
||||
else:
|
||||
return setting
|
||||
|
||||
@classmethod
|
||||
def get_reference_context(cls):
|
||||
"""Generate context data for generating the 'reference' field for this class.
|
||||
@ -365,6 +388,7 @@ class ReferenceIndexingMixin(models.Model):
|
||||
"""Generate the next 'reference' field based on specified pattern."""
|
||||
fmt = cls.get_reference_pattern()
|
||||
ctx = cls.get_reference_context()
|
||||
wildcard_default = cls.get_reference_pattern_wildcard_default()
|
||||
|
||||
reference = None
|
||||
|
||||
@ -394,6 +418,9 @@ class ReferenceIndexingMixin(models.Model):
|
||||
recent = cls.get_most_recent_item()
|
||||
reference = recent.reference if recent else ''
|
||||
|
||||
if wildcard_default is not None:
|
||||
reference = reference.replace('?', wildcard_default)
|
||||
|
||||
return reference
|
||||
|
||||
@classmethod
|
||||
|
@ -1981,6 +1981,15 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
||||
'default': 'PO-{ref:04d}',
|
||||
'validator': order.validators.validate_purchase_order_reference_pattern,
|
||||
},
|
||||
'PURCHASEORDER_REFERENCE_PATTERN_WILDCARD_DEFAULT': {
|
||||
'name': _('Purchase Order Reference Pattern Wildcard Default'),
|
||||
'description': _(
|
||||
'Replace all wildcard ? characters in reference pattern with a default value'
|
||||
),
|
||||
'default': None,
|
||||
# TODO: add validator
|
||||
'validator': lambda x: x,
|
||||
},
|
||||
'PURCHASEORDER_REQUIRE_RESPONSIBLE': {
|
||||
'name': _('Require Responsible Owner'),
|
||||
'description': _('A responsible owner must be assigned to each order'),
|
||||
|
@ -378,6 +378,9 @@ class PurchaseOrder(TotalPriceMixin, Order):
|
||||
"""
|
||||
|
||||
REFERENCE_PATTERN_SETTING = 'PURCHASEORDER_REFERENCE_PATTERN'
|
||||
REFERENCE_PATTERN_WILDCARD_DEFAULT_SETTING = (
|
||||
'PURCHASEORDER_REFERENCE_PATTERN_WILDCARD_DEFAULT'
|
||||
)
|
||||
REQUIRE_RESPONSIBLE_SETTING = 'PURCHASEORDER_REQUIRE_RESPONSIBLE'
|
||||
|
||||
class Meta:
|
||||
|
@ -11,6 +11,7 @@
|
||||
<table class='table table-striped table-condensed'>
|
||||
<tbody>
|
||||
{% include "InvenTree/settings/setting.html" with key="PURCHASEORDER_REFERENCE_PATTERN" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PURCHASEORDER_REFERENCE_PATTERN_WILDCARD_DEFAULT" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PURCHASEORDER_REQUIRE_RESPONSIBLE" %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PURCHASEORDER_EDIT_COMPLETED_ORDERS" icon='fa-edit' %}
|
||||
{% include "InvenTree/settings/setting.html" with key="PURCHASEORDER_AUTO_COMPLETE" icon='fa-check-circle' %}
|
||||
|
Reference in New Issue
Block a user