code
stringlengths
66
870k
docstring
stringlengths
19
26.7k
func_name
stringlengths
1
138
language
stringclasses
1 value
repo
stringlengths
7
68
path
stringlengths
5
324
url
stringlengths
46
389
license
stringclasses
7 values
def validate_model_instance( self, instance: Model, deltas: Optional[dict] = None ) -> None: """Run custom validation on a database model instance. This method is called when a model instance is being validated. It allows the plugin to raise a ValidationError on any field in the mod...
Run custom validation on a database model instance. This method is called when a model instance is being validated. It allows the plugin to raise a ValidationError on any field in the model. Arguments: instance: The model instance to validate deltas: A dictionary of fie...
validate_model_instance
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
MIT
def validate_batch_code( self, batch_code: str, item: stock.models.StockItem ) -> None: """Validate the supplied batch code. Arguments: batch_code: The proposed batch code (string) item: The StockItem instance we are validating against Returns: N...
Validate the supplied batch code. Arguments: batch_code: The proposed batch code (string) item: The StockItem instance we are validating against Returns: None or True (refer to class docstring) Raises: ValidationError: If the proposed batch code...
validate_batch_code
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
MIT
def validate_serial_number( self, serial: str, part: part.models.Part, stock_item: stock.models.StockItem = None, ) -> None: """Validate the supplied serial number. Arguments: serial: The proposed serial number (string) part: The Part instance...
Validate the supplied serial number. Arguments: serial: The proposed serial number (string) part: The Part instance for which this serial number is being validated stock_item: The StockItem instance for which this serial number is being validated (if applicable) Ret...
validate_serial_number
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
MIT
def increment_serial_number( self, serial: str, part: part.models.Part = None, **kwargs ) -> str: """Return the next sequential serial based on the provided value. A plugin which implements this method can either return: - A string which represents the "next" serial number in the s...
Return the next sequential serial based on the provided value. A plugin which implements this method can either return: - A string which represents the "next" serial number in the sequence - None (null value) if the next value could not be determined Arguments: serial: Cur...
increment_serial_number
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
MIT
def validate_part_parameter( self, parameter: part.models.PartParameter, data: str ) -> None: """Validate a parameter value. Arguments: parameter: The parameter we are validating data: The proposed parameter value Returns: None or True (refer to ...
Validate a parameter value. Arguments: parameter: The parameter we are validating data: The proposed parameter value Returns: None or True (refer to class docstring) Raises: ValidationError: If the proposed parameter value is objectionable ...
validate_part_parameter
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/integration/ValidationMixin.py
MIT
def print_label(plugin_slug: str, **kwargs): """Print label with the provided plugin. This task is nominally handled by the background worker. If the printing fails (throws an exception) then the user is notified. Arguments: plugin_slug (str): The unique slug (key) of the plugin. kwargs: ...
Print label with the provided plugin. This task is nominally handled by the background worker. If the printing fails (throws an exception) then the user is notified. Arguments: plugin_slug (str): The unique slug (key) of the plugin. kwargs: passed through to the plugin.print_label() m...
print_label
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/label.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/label.py
MIT
def render_to_pdf(self, label: LabelTemplate, instance, request, **kwargs): """Render this label to PDF format. Arguments: label: The LabelTemplate object to render against instance: The model instance to render request: The HTTP request object which triggered this p...
Render this label to PDF format. Arguments: label: The LabelTemplate object to render against instance: The model instance to render request: The HTTP request object which triggered this print job
render_to_pdf
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/mixins.py
MIT
def render_to_html(self, label: LabelTemplate, instance, request, **kwargs): """Render this label to HTML format. Arguments: label: The LabelTemplate object to render against instance: The model instance to render request: The HTTP request object which triggered this...
Render this label to HTML format. Arguments: label: The LabelTemplate object to render against instance: The model instance to render request: The HTTP request object which triggered this print job
render_to_html
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/mixins.py
MIT
def render_to_png(self, label: LabelTemplate, instance, request=None, **kwargs): """Render this label to PNG format. Arguments: label: The LabelTemplate object to render against instance: The model instance to render request: The HTTP request object which triggered t...
Render this label to PNG format. Arguments: label: The LabelTemplate object to render against instance: The model instance to render request: The HTTP request object which triggered this print job Keyword Arguments: pdf_data: The raw PDF data of the rende...
render_to_png
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/mixins.py
MIT
def print_labels( self, label: LabelTemplate, output: DataOutput, items: list, request: Request, **kwargs, ) -> None: """Print one or more labels with the provided template and items. Arguments: label: The LabelTemplate object to use for p...
Print one or more labels with the provided template and items. Arguments: label: The LabelTemplate object to use for printing output: The DataOutput object used to store the results items: The list of database items to print (e.g. StockItem instances) request: Th...
print_labels
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/mixins.py
MIT
def print_label(self, **kwargs): """Print a single label (blocking). kwargs: pdf_data: Raw PDF data of the rendered label filename: The filename of this PDF label label_instance: The instance of the label model which triggered the print_label() method ite...
Print a single label (blocking). kwargs: pdf_data: Raw PDF data of the rendered label filename: The filename of this PDF label label_instance: The instance of the label model which triggered the print_label() method item_instance: The instance of the database mod...
print_label
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/mixins.py
MIT
def get_printing_options_serializer( self, request: Request, *args, **kwargs ) -> Union[serializers.Serializer, None]: """Return a serializer class instance with dynamic printing options. Arguments: request: The request made to print a label or interfering the available serializ...
Return a serializer class instance with dynamic printing options. Arguments: request: The request made to print a label or interfering the available serializer fields via an OPTIONS request *args, **kwargs: need to be passed to the serializer instance Returns: A cla...
get_printing_options_serializer
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/mixins.py
MIT
def test_wrong_implementation(self): """Test that a wrong implementation raises an error.""" class WrongPlugin(LabelPrintingMixin, InvenTreePlugin): pass with self.assertRaises(MixinNotImplementedError): plugin = WrongPlugin() plugin.print_label(filename='te...
Test that a wrong implementation raises an error.
test_wrong_implementation
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/test_label_mixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/test_label_mixin.py
MIT
def test_installed(self): """Test that the sample printing plugin is installed.""" # Get all label plugins plugins = registry.with_mixin(PluginMixinEnum.LABELS, active=None) self.assertEqual(len(plugins), 4) # But, it is not 'active' plugins = registry.with_mixin(PluginM...
Test that the sample printing plugin is installed.
test_installed
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/test_label_mixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/test_label_mixin.py
MIT
def test_api(self): """Test that we can filter the API endpoint by mixin.""" url = reverse('api-plugin-list') # Try POST (disallowed) response = self.client.post(url, {}) self.assertEqual(response.status_code, 405) response = self.client.get(url, {'mixin': 'labels', 'ac...
Test that we can filter the API endpoint by mixin.
test_api
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/test_label_mixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/test_label_mixin.py
MIT
def test_printing_process(self): """Test that a label can be printed.""" # Ensure the labels were created apps.get_app_config('report').create_default_labels() apps.get_app_config('report').create_default_reports() test_path = BASE_DIR / '_testfolder' / 'label' parts = ...
Test that a label can be printed.
test_printing_process
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/test_label_mixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/test_label_mixin.py
MIT
def test_printing_endpoints(self): """Cover the endpoints not covered by `test_printing_process`.""" # Activate the label components apps.get_app_config('report').create_default_labels() self.do_activate_plugin() # Test StockItemLabel self.run_print_test(StockItem, 'stoc...
Cover the endpoints not covered by `test_printing_process`.
test_printing_endpoints
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/label/test_label_mixin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/label/test_label_mixin.py
MIT
def post(self, request, *args, **kwargs): """Identify or 'locate' a stock item or location with a plugin.""" # Check inputs and offload the task to the plugin # Which plugin to we wish to use? plugin = request.data.get('plugin', None) if not plugin: raise ParseError(...
Identify or 'locate' a stock item or location with a plugin.
post
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/locate/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/locate/api.py
MIT
def locate_stock_item(self, item_pk): """Attempt to locate a particular StockItem. Arguments: item_pk: The PK (primary key) of the StockItem to be located The default implementation for locating a StockItem attempts to locate the StockLocation where the item is located. ...
Attempt to locate a particular StockItem. Arguments: item_pk: The PK (primary key) of the StockItem to be located The default implementation for locating a StockItem attempts to locate the StockLocation where the item is located. An attempt is only made if the StockItem is...
locate_stock_item
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/locate/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/locate/mixins.py
MIT
def test_installed(self): """Test that a locate plugin is actually installed.""" plugins = registry.with_mixin(PluginMixinEnum.LOCATE) self.assertGreater(len(plugins), 0) self.assertIn('samplelocate', [p.slug for p in plugins])
Test that a locate plugin is actually installed.
test_installed
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/locate/test_locate.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/locate/test_locate.py
MIT
def test_locate_item(self): """Test that the plugin correctly 'locates' a StockItem. As the background worker is not running during unit testing, the sample 'locate' function will be called 'inline' """ url = reverse('api-locate-plugin') item = StockItem.objects.get(pk=...
Test that the plugin correctly 'locates' a StockItem. As the background worker is not running during unit testing, the sample 'locate' function will be called 'inline'
test_locate_item
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/locate/test_locate.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/locate/test_locate.py
MIT
def test_locate_location(self): """Test that the plugin correctly 'locates' a StockLocation.""" url = reverse('api-locate-plugin') for location in StockLocation.objects.all(): location.set_metadata('located', False) response = self.post( url, ...
Test that the plugin correctly 'locates' a StockLocation.
test_locate_location
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/locate/test_locate.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/locate/test_locate.py
MIT
def get_ui_features( self, feature_type: FeatureType, context: dict, request: Request, **kwargs ) -> list[UIFeature]: """Return a list of custom features to be injected into the UI. Arguments: feature_type: The type of feature being requested context: Additional cont...
Return a list of custom features to be injected into the UI. Arguments: feature_type: The type of feature being requested context: Additional context data provided by the UI (query parameters) request: HTTPRequest object (including user information) Returns: ...
get_ui_features
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/mixins.py
MIT
def get_ui_panels( self, request: Request, context: dict, **kwargs ) -> list[UIFeature]: """Return a list of custom panels to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data provided by the UI (...
Return a list of custom panels to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data provided by the UI (query parameters) Returns: list: A list of custom panels to be injected into the UI ...
get_ui_panels
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/mixins.py
MIT
def get_ui_dashboard_items( self, request: Request, context: dict, **kwargs ) -> list[UIFeature]: """Return a list of custom dashboard items to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data pr...
Return a list of custom dashboard items to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data provided by the UI (query parameters) Returns: list: A list of custom dashboard items to be injected i...
get_ui_dashboard_items
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/mixins.py
MIT
def get_ui_template_editors( self, request: Request, context: dict, **kwargs ) -> list[UIFeature]: """Return a list of custom template editors to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data ...
Return a list of custom template editors to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data provided by the UI (query parameters) Returns: list: A list of custom template editors to be injected...
get_ui_template_editors
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/mixins.py
MIT
def get_ui_template_previews( self, request: Request, context: dict, **kwargs ) -> list[UIFeature]: """Return a list of custom template previews to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context dat...
Return a list of custom template previews to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data provided by the UI (query parameters) Returns: list: A list of custom template previews to be inject...
get_ui_template_previews
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/mixins.py
MIT
def get_ui_navigation_items( self, request: Request, context: dict, **kwargs ) -> list[UIFeature]: """Return a list of custom navigation items to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data ...
Return a list of custom navigation items to be injected into the UI. Args: request: HTTPRequest object (including user information) context: Additional context data provided by the UI (query parameters) Returns: list: A list of custom navigation items to be injected...
get_ui_navigation_items
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/mixins.py
MIT
def test_installed(self): """Test that the sample UI plugin is installed and active.""" plugin = registry.get_plugin('sampleui') self.assertTrue(plugin.is_active()) plugins = registry.with_mixin(PluginMixinEnum.USER_INTERFACE) self.assertGreater(len(plugins), 0)
Test that the sample UI plugin is installed and active.
test_installed
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/tests.py
MIT
def test_ui_dashboard_items(self): """Test that the sample UI plugin provides custom dashboard items.""" # Ensure the user has superuser status self.user.is_superuser = True self.user.save() url = reverse('api-plugin-ui-feature-list', kwargs={'feature': 'dashboard'}) re...
Test that the sample UI plugin provides custom dashboard items.
test_ui_dashboard_items
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/tests.py
MIT
def test_ui_panels(self): """Test that the sample UI plugin provides custom panels.""" from part.models import Part plugin = registry.get_plugin('sampleui') _part = Part.objects.first() # Ensure that the part is active _part.active = True _part.save() ...
Test that the sample UI plugin provides custom panels.
test_ui_panels
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/tests.py
MIT
def test_ui_template_editors(self): """Test that the sample UI plugin provides template editor features.""" template_editor_url = reverse( 'api-plugin-ui-feature-list', kwargs={'feature': 'template_editor'} ) template_preview_url = reverse( 'api-plugin-ui-feature-...
Test that the sample UI plugin provides template editor features.
test_ui_template_editors
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/tests.py
MIT
def test_ui_navigation_items(self): """Test that the sample UI plugin provides custom navigation items.""" response = self.get( reverse('api-plugin-ui-feature-list', kwargs={'feature': 'navigation'}) ) self.assertEqual(1, len(response.data)) self.assertEqual(response....
Test that the sample UI plugin provides custom navigation items.
test_ui_navigation_items
python
inventree/InvenTree
src/backend/InvenTree/plugin/base/ui/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/base/ui/tests.py
MIT
def __init__(self): """Raise a KeyError to provoke a range of unit tests and safety mechanisms in the plugin loading mechanism.""" super().__init__() raise KeyError('This is a dummy error')
Raise a KeyError to provoke a range of unit tests and safety mechanisms in the plugin loading mechanism.
__init__
python
inventree/InvenTree
src/backend/InvenTree/plugin/broken/broken_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/broken/broken_sample.py
MIT
def scan(self, barcode_data): """Scan a barcode against this plugin. Here we are looking for a dict object which contains a reference to a particular InvenTree database object """ # Internal Barcodes - Short Format # Attempt to match the barcode data against the short barcode fo...
Scan a barcode against this plugin. Here we are looking for a dict object which contains a reference to a particular InvenTree database object
scan
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/inventree_barcode.py
MIT
def test_assign_errors(self): """Test error cases for assignment action.""" def test_assert_error(barcode_data): response = self.post( reverse('api-barcode-link'), data={'barcode': barcode_data, 'stockitem': 521}, expected_code=400, ...
Test error cases for assignment action.
test_assign_errors
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def set_plugin_setting(self, key: str, value: str): """Set the internal barcode format for the plugin.""" from plugin import registry plugin = registry.get_plugin('inventreebarcode') plugin.set_setting(key, value)
Set the internal barcode format for the plugin.
set_plugin_setting
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def test_unassign_errors(self): """Test various error conditions for the barcode unassign endpoint.""" # Fail without any fields provided response = self.unassign({}, expected_code=400) self.assertIn('Missing data: Provide one of', str(response.data['error'])) # Fail with too m...
Test various error conditions for the barcode unassign endpoint.
test_unassign_errors
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def test_assign_to_stock_item(self): """Test that we can assign a unique barcode to a StockItem object.""" # Test without providing any fields response = self.assign({'barcode': 'abcde'}, expected_code=400) self.assertIn('Missing data:', str(response.data)) # Permission error c...
Test that we can assign a unique barcode to a StockItem object.
test_assign_to_stock_item
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def test_assign_to_part(self): """Test that we can assign a unique barcode to a Part instance.""" barcode = 'xyz-123' self.assignRole('part.change') # Test that an initial scan yields no results response = self.scan({'barcode': barcode}, expected_code=400) self.assignR...
Test that we can assign a unique barcode to a Part instance.
test_assign_to_part
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def test_assign_to_location(self): """Test that we can assign a unique barcode to a StockLocation instance.""" barcode = '555555555555555555555555' # Assign random barcode data to a StockLocation instance response = self.assign( data={'barcode': barcode, 'stocklocation': 1},...
Test that we can assign a unique barcode to a StockLocation instance.
test_assign_to_location
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def test_scan_third_party(self): """Test scanning of third-party barcodes.""" # First scanned barcode is for a 'third-party' barcode (which does not exist) response = self.scan({'barcode': 'blbla=10008'}, expected_code=400) self.assertEqual(response.data['error'], 'No match found for bar...
Test scanning of third-party barcodes.
test_scan_third_party
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def test_scan_inventree_json(self): """Test scanning of first-party json barcodes.""" # Scan a StockItem object (which does not exist) response = self.scan({'barcode': '{"stockitem": 5}'}, expected_code=400) self.assertIn('No match found for barcode data', str(response.data)) #...
Test scanning of first-party json barcodes.
test_scan_inventree_json
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def test_scan_inventree_short(self): """Test scanning of first-party short barcodes.""" # Scan a StockItem object (which does not exist) response = self.scan({'barcode': 'INV-SI5'}, expected_code=400) self.assertIn('No match found for barcode data', str(response.data)) # Scan a...
Test scanning of first-party short barcodes.
test_scan_inventree_short
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/barcodes/test_inventree_barcode.py
MIT
def auto_issue_orders(self): """Automatically issue orders on the assigned target date.""" if self.get_setting('AUTO_ISSUE_BUILD_ORDERS', backup_value=True): self.auto_issue_build_orders() if self.get_setting('AUTO_ISSUE_PURCHASE_ORDERS', backup_value=True): self.auto_is...
Automatically issue orders on the assigned target date.
auto_issue_orders
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
MIT
def issue_func(self, model, status: int, func_name: str = 'issue_order'): """Helper function to issue orders of a given model and status.""" orders = model.objects.filter(status=status) orders = orders.filter(target_date__isnull=False) if self.get_setting('ISSUE_BACKDATED_ORDERS', backu...
Helper function to issue orders of a given model and status.
issue_func
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
MIT
def auto_issue_build_orders(self): """Automatically issue build orders on the assigned target date.""" from build.models import Build from build.status_codes import BuildStatus self.issue_func(Build, BuildStatus.PENDING, func_name='issue_build')
Automatically issue build orders on the assigned target date.
auto_issue_build_orders
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
MIT
def auto_issue_purchase_orders(self): """Automatically issue purchase orders on the assigned target date.""" from order.models import PurchaseOrder from order.status_codes import PurchaseOrderStatus self.issue_func(PurchaseOrder, PurchaseOrderStatus.PENDING)
Automatically issue purchase orders on the assigned target date.
auto_issue_purchase_orders
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
MIT
def auto_issue_sales_orders(self): """Automatically issue sales orders on the assigned target date.""" from order.models import SalesOrder from order.status_codes import SalesOrderStatus self.issue_func(SalesOrder, SalesOrderStatus.PENDING)
Automatically issue sales orders on the assigned target date.
auto_issue_sales_orders
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
MIT
def auto_issue_return_orders(self): """Automatically issue return orders on the assigned target date.""" from order.models import ReturnOrder from order.status_codes import ReturnOrderStatus self.issue_func(ReturnOrder, ReturnOrderStatus.PENDING)
Automatically issue return orders on the assigned target date.
auto_issue_return_orders
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/events/auto_issue_orders.py
MIT
def update_headers(self, headers, context, **kwargs): """Update headers for the BOM export.""" if not self.export_stock_data: # Remove stock data from the headers for field in [ 'available_stock', 'available_substitute_stock', 'avai...
Update headers for the BOM export.
update_headers
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py
MIT
def prefetch_queryset(self, queryset): """Perform pre-fetch on the provided queryset.""" queryset = queryset.prefetch_related('sub_part') if self.export_substitute_data: queryset = queryset.prefetch_related('substitutes') if self.export_supplier_data: queryset =...
Perform pre-fetch on the provided queryset.
prefetch_queryset
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py
MIT
def export_data( self, queryset, serializer_class, headers, context, output, **kwargs ): """Export BOM data from the queryset.""" self.serializer_class = serializer_class # Track how many extra columns we need self.n_substitute_cols = 0 self.n_supplier_cols = 0 ...
Export BOM data from the queryset.
export_data
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/exporter/bom_exporter.py
MIT
def supports_export( self, model_class: type, user=None, serializer_class=None, view_class=None, *args, **kwargs, ) -> bool: """Supported if the base model is Part.""" return model_class == Part and serializer_class == PartSerializer
Supported if the base model is Part.
supports_export
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/exporter/part_parameter_exporter.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/exporter/part_parameter_exporter.py
MIT
def get_settings_content(self, request): """Custom settings content for the plugin.""" return """ <p>Setup for Slack:</p> <ol> <li>Create a new Slack app on <a href="https://api.slack.com/apps/new" target="_blank">this page</a></li> <li>Enable <i>Incoming Webhooks...
Custom settings content for the plugin.
get_settings_content
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
MIT
def get_targets(self): """Return a list of target email addresses, only for users which allow email notifications.""" allowed_users = [] for user in self.targets: if not user.is_active: # Ignore any users who have been deactivated ...
Return a list of target email addresses, only for users which allow email notifications.
get_targets
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
MIT
def send_bulk(self): """Send the notifications out via email.""" html_message = render_to_string( self.context['template']['html'], self.context ) targets = self.targets.values_list('email', flat=True) # Prefix the 'instance title' to the emai...
Send the notifications out via email.
send_bulk
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
MIT
def send_bulk(self): """Send the notifications out via slack.""" instance = registry.get_plugin(self.get_plugin().NAME.lower()) url = instance.get_setting('NOTIFICATION_SLACK_URL') if not url: return False ret = requests.post( ...
Send the notifications out via slack.
send_bulk
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/integration/core_notifications.py
MIT
def update_exchange_rates(self, base_currency: str, symbols: list[str]) -> dict: """Request exchange rate data from external API.""" response = self.api_call( 'latest', url_args={'from': [base_currency], 'to': symbols}, simple_response=False, ) if res...
Request exchange rate data from external API.
update_exchange_rates
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/integration/currency_exchange.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/integration/currency_exchange.py
MIT
def test_email(self): """Ensure that the email notifications run.""" # No email should be send self.assertEqual(len(mail.outbox), 0) # enable plugin and set mail setting to true plugin = registry.get_plugin('inventreecorenotificationsplugin') plugin.set_setting('ENABLE_N...
Ensure that the email notifications run.
test_email
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/integration/test_core_notifications.py
MIT
def get_generated_file(self, **kwargs): """Return the generated file, by stitching together the individual label outputs.""" if len(self.outputs) == 0: return None if str2bool(self.get_setting('DEBUG')): # Simple HTML output data = '\n'.join(self.outputs) ...
Return the generated file, by stitching together the individual label outputs.
get_generated_file
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/inventree_label.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/inventree_label.py
MIT
def get_machine_and_driver(machine_pk: str): """Get the driver by machine pk and ensure that it is a label printing driver.""" machine = registry.get_machine(machine_pk) # machine should be valid due to the machine select field validator if machine is None: # pragma: no cover return None, None...
Get the driver by machine pk and ensure that it is a label printing driver.
get_machine_and_driver
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
MIT
def get_last_used_printers(user): """Get the last used printers for a specific user.""" return [ printer for printer in cast( str, InvenTreeUserSetting.get_setting( 'LAST_USED_PRINTING_MACHINES', '', user=user ), ).split(',') if...
Get the last used printers for a specific user.
get_last_used_printers
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
MIT
def print_labels(self, label: LabelTemplate, output, items, request, **kwargs): """Print labels implementation that calls the correct machine driver print_labels method.""" machine, driver = get_machine_and_driver( kwargs['printing_options'].get('machine', '') ) # the driver...
Print labels implementation that calls the correct machine driver print_labels method.
print_labels
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
MIT
def __init__(self, *args, **kwargs): """Custom __init__ method to dynamically override the machine choices based on the request.""" super().__init__(*args, **kwargs) # TODO @matmair Re-enable this when the need is clear # view = kwargs['context']['view'] temp...
Custom __init__ method to dynamically override the machine choices based on the request.
__init__
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/inventree_machine.py
MIT
def print_labels( self, label: LabelTemplate, output: DataOutput, items: list, request, **kwargs ): """Handle printing of the provided labels. Note that we override the entire print_labels method for this plugin. """ printing_options = kwargs['printing_options'] # E...
Handle printing of the provided labels. Note that we override the entire print_labels method for this plugin.
print_labels
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/label_sheet.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/label_sheet.py
MIT
def print_page(self, label: LabelTemplate, items: list, request, **kwargs): """Generate a single page of labels. For a single page, generate a simple table grid of labels. Styling of the table is handled by the higher level label template Arguments: label: The LabelTemplate...
Generate a single page of labels. For a single page, generate a simple table grid of labels. Styling of the table is handled by the higher level label template Arguments: label: The LabelTemplate object to use for printing items: The list of database items to print (e.g...
print_page
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/label_sheet.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/label_sheet.py
MIT
def wrap_pages(self, pages, **kwargs): """Wrap the generated pages into a single document.""" border = kwargs['border'] page_width = kwargs['page_width'] page_height = kwargs['page_height'] label_width = kwargs['label_width'] label_height = kwargs['label_height'] ...
Wrap the generated pages into a single document.
wrap_pages
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/labels/label_sheet.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/labels/label_sheet.py
MIT
def extract_barcode_fields(self, barcode_data: str) -> dict[str, str]: """Get supplier_part and barcode_fields from LCSC QR-Code. Example LCSC QR-Code: {pbn:PICK2009291337,on:SO2009291337,pc:C312270} """ if not self.LCSC_BARCODE_REGEX.fullmatch(barcode_data): return {} ...
Get supplier_part and barcode_fields from LCSC QR-Code. Example LCSC QR-Code: {pbn:PICK2009291337,on:SO2009291337,pc:C312270}
extract_barcode_fields
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/lcsc.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/lcsc.py
MIT
def extract_barcode_fields(self, barcode_data: str) -> dict[str, str]: """Get supplier_part and barcode_fields from Mouser DataMatrix-Code.""" barcode_fields = self.parse_ecia_barcode2d(barcode_data) # Mouser uses the custom order number ('K') field of the 2D barcode for both, # the ord...
Get supplier_part and barcode_fields from Mouser DataMatrix-Code.
extract_barcode_fields
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/mouser.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/mouser.py
MIT
def test_digikey_2_barcode(self): """Test digikey barcode which uses 30P instead of P.""" result = self.post( self.SCAN_URL, data={'barcode': DIGIKEY_BARCODE_2}, expected_code=200 ) self.assertEqual(result.data['plugin'], 'DigiKeyPlugin') supplier_part_data = result...
Test digikey barcode which uses 30P instead of P.
test_digikey_2_barcode
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_mouser_barcode(self): """Test mouser barcode with custom order number.""" result = self.post( self.SCAN_URL, data={'barcode': MOUSER_BARCODE}, expected_code=200 ) supplier_part_data = result.data.get('supplierpart') self.assertIn('pk', supplier_part_data) ...
Test mouser barcode with custom order number.
test_mouser_barcode
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_old_mouser_barcode(self): """Test old mouser barcode with messed up header.""" result = self.post( self.SCAN_URL, data={'barcode': MOUSER_BARCODE_OLD}, expected_code=200 ) supplier_part_data = result.data.get('supplierpart') self.assertIn('pk', supplier_part...
Test old mouser barcode with messed up header.
test_old_mouser_barcode
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_receive(self): """Test receiving an item from a barcode.""" url = reverse('api-barcode-po-receive') # First attempt - PO is not yet "placed" result1 = self.post(url, data={'barcode': DIGIKEY_BARCODE}, expected_code=400) self.assertIn('received against an order marked a...
Test receiving an item from a barcode.
test_receive
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_receive_custom_order_number(self): """Test receiving an item from a barcode with a custom order number.""" url = reverse('api-barcode-po-receive') result1 = self.post(url, data={'barcode': MOUSER_BARCODE}, expected_code=200) self.assertIn('success', result1.data) # Scan...
Test receiving an item from a barcode with a custom order number.
test_receive_custom_order_number
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_receive_stock_location(self): """Test receiving an item when the location is provided.""" stock_location = StockLocation.objects.create(name='Test Location') url = reverse('api-barcode-po-receive') result1 = self.post( url, data={'barcode': MOUSER_BARCO...
Test receiving an item when the location is provided.
test_receive_stock_location
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_receive_default_line_item_location(self): """Test receiving an item into the default line_item location.""" StockLocation.objects.create(name='Test Location 1') stock_location2 = StockLocation.objects.create(name='Test Location 2') line_item = PurchaseOrderLineItem.objects.filt...
Test receiving an item into the default line_item location.
test_receive_default_line_item_location
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_receive_default_part_location(self): """Test receiving an item into the default part location.""" StockLocation.objects.create(name='Test Location 1') stock_location2 = StockLocation.objects.create(name='Test Location 2') # Ensure no other fallback locations are set # T...
Test receiving an item into the default part location.
test_receive_default_part_location
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_receive_specific_order_and_location(self): """Test receiving an item from a specific order into a specific location.""" StockLocation.objects.create(name='Test Location 1') stock_location2 = StockLocation.objects.create(name='Test Location 2') url = reverse('api-barcode-po-rece...
Test receiving an item from a specific order into a specific location.
test_receive_specific_order_and_location
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def test_receive_missing_quantity(self): """Test receiving an with missing quantity information.""" url = reverse('api-barcode-po-receive') barcode = MOUSER_BARCODE.replace('\x1dQ3', '') response = self.post(url, data={'barcode': barcode}, expected_code=200) self.assertIn('actio...
Test receiving an with missing quantity information.
test_receive_missing_quantity
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/test_supplier_barcodes.py
MIT
def extract_barcode_fields(self, barcode_data: str) -> dict[str, str]: """Get supplier_part and barcode_fields from TME QR-Code or DataMatrix-Code.""" barcode_fields = {} if self.TME_IS_QRCODE_REGEX.fullmatch(barcode_data): # Custom QR Code format e.g. "QTY: 1 PN:12345" ...
Get supplier_part and barcode_fields from TME QR-Code or DataMatrix-Code.
extract_barcode_fields
python
inventree/InvenTree
src/backend/InvenTree/plugin/builtin/suppliers/tme.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/builtin/suppliers/tme.py
MIT
def test_run_event(self): """Check if the event is issued.""" # Activate plugin config = registry.get_plugin('sampleevent').plugin_config() config.active = True config.save() InvenTreeSetting.set_setting('ENABLE_PLUGINS_EVENTS', True, change_user=None) # Enable ...
Check if the event is issued.
test_run_event
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/event/test_event_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/event/test_event_sample.py
MIT
def print_label(self, **kwargs): """Sample printing step. Normally here the connection to the printer and transfer of the label would take place. """ # Test that the expected kwargs are present print(f'Printing Label: {kwargs["filename"]} (User: {kwargs["user"]})') pdf_...
Sample printing step. Normally here the connection to the printer and transfer of the label would take place.
print_label
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/label_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/label_sample.py
MIT
def add_report_context(self, report_instance, model_instance, request, context): """Add example content to the report instance.""" # We can add any extra context data we want to the report # Generate a random string of data context['random_text'] = ''.join( random.choices('ab...
Add example content to the report instance.
add_report_context
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/report_plugin_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/report_plugin_sample.py
MIT
def setup_urls(self): """Urls that are exposed by this plugin.""" he_urls = [ path('he/', self.view_test, name='he'), path('ha/', self.view_test, name='ha'), ] return [ path('hi/', self.view_test, name='hi'), path('ho/', include(he_urls), ...
Urls that are exposed by this plugin.
setup_urls
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/sample.py
MIT
def update_exchange_rates(self, base_currency: str, symbols: list[str]) -> dict: """Return dummy data for some currencies.""" rates = {base_currency: 1.00} for symbol in symbols: rates[symbol] = random.randrange(5, 15) * 0.1 return rates
Return dummy data for some currencies.
update_exchange_rates
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/sample_currency_exchange.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/sample_currency_exchange.py
MIT
def member_func(self, *args, **kwargs): """A simple member function to demonstrate functionality.""" t_or_f = self.get_setting('T_OR_F') print(f'Called member_func - value is {t_or_f}') return t_or_f
A simple member function to demonstrate functionality.
member_func
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/scheduled_task.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/scheduled_task.py
MIT
def test_return(self): """Check if the external api call works.""" # The plugin should be defined self.assertIn('sample-api-caller', registry.plugins) plg = registry.plugins['sample-api-caller'] self.assertTrue(plg) # do an api call result = plg.get_external_url(...
Check if the external api call works.
test_return
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/test_api_caller.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/test_api_caller.py
MIT
def test_view(self): """Check the function of the custom sample plugin.""" from common.models import InvenTreeSetting url = '/plugin/sample/ho/he/' # First, check with custom URLs disabled InvenTreeSetting.set_setting('ENABLE_PLUGINS_URL', False, None) # Requires a fu...
Check the function of the custom sample plugin.
test_view
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/test_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/test_sample.py
MIT
def test_calling(self): """Test calling of plugin functions by name.""" # Check with right parameters self.assertEqual(call_plugin_function('schedule', 'member_func'), False) # Check with wrong key with self.assertRaises(AttributeError): call_plugin_function('does_no...
Test calling of plugin functions by name.
test_calling
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/test_scheduled_task.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/test_scheduled_task.py
MIT
def set_plugin_state(self, state: bool): """Set the enabled state of the SimpleActionPlugin.""" cfg = registry.get_plugin_config('simpleaction') cfg.active = state cfg.save()
Set the enabled state of the SimpleActionPlugin.
set_plugin_state
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/test_simpleactionplugin.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/test_simpleactionplugin.py
MIT
def test_api_batch(self): """Test the batch code validation API.""" self.enable_plugin(True) url = reverse('api-generate-batch-code') response = self.post(url) self.assertIn('batch_code', response.data) self.assertTrue(response.data['batch_code'].startswith('SAMPLE-BATCH...
Test the batch code validation API.
test_api_batch
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/test_validation_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/test_validation_sample.py
MIT
def transition(current_state, target_state, instance, default_action, **kwargs): # noqa: N805 """Example override function for state transition.""" # Only act on ReturnOrders that should be completed if ( not isinstance(instance, ReturnOrder) or targe...
Example override function for state transition.
transition
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/transition.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/transition.py
MIT
def get_ui_panels(self, request, context, **kwargs): """Return a list of custom panels to be injected into the UI.""" panels = [] context = context or {} # First, add a custom panel which will appear on every type of page # This panel will contain a simple message targe...
Return a list of custom panels to be injected into the UI.
get_ui_panels
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
MIT
def get_ui_dashboard_items(self, request, context, **kwargs): """Return a list of custom dashboard items.""" items = [ { 'key': 'broken-dashboard-item', 'title': _('Broken Dashboard Item'), 'description': _( 'This is a broke...
Return a list of custom dashboard items.
get_ui_dashboard_items
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
MIT
def get_ui_template_editors(self, request, context, **kwargs): """Return a list of custom template editors.""" # If the context is a label template, return a custom template editor if context.get('template_type') == 'labeltemplate': return [ { 'key...
Return a list of custom template editors.
get_ui_template_editors
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
MIT
def get_ui_template_previews(self, request, context, **kwargs): """Return a list of custom template previews.""" return [ { 'key': 'sample-template-preview', 'title': 'Sample Template Preview', 'icon': 'ti:category:outline', 'so...
Return a list of custom template previews.
get_ui_template_previews
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
MIT
def get_ui_navigation_items(self, request, context, **kwargs): """Return a list of custom navigation items.""" return [ { 'key': 'sample-nav-item', 'title': 'Sample Nav Item', 'icon': 'ti:menu', 'options': {'url': '/sample/page/...
Return a list of custom navigation items.
get_ui_navigation_items
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/user_interface_sample.py
MIT
def validate_part_name(self, name: str, part): """Custom validation for Part name field. Rules: - Name must be shorter than the description field - Name cannot contain illegal characters These examples are silly, but serve to demonstrate how the feature could be used. "...
Custom validation for Part name field. Rules: - Name must be shorter than the description field - Name cannot contain illegal characters These examples are silly, but serve to demonstrate how the feature could be used.
validate_part_name
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/validation_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/validation_sample.py
MIT
def validate_part_ipn(self, ipn: str, part): """Validate part IPN. These examples are silly, but serve to demonstrate how the feature could be used """ if self.get_setting('IPN_MUST_CONTAIN_Q') and 'Q' not in ipn: self.raise_error("IPN must contain 'Q'")
Validate part IPN. These examples are silly, but serve to demonstrate how the feature could be used
validate_part_ipn
python
inventree/InvenTree
src/backend/InvenTree/plugin/samples/integration/validation_sample.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/plugin/samples/integration/validation_sample.py
MIT