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 currency_code(self): """Return the currency code associated with this company. - If the currency code is invalid, use the default currency - If the currency code is not specified, use the default currency """ code = self.currency if code not in CURRENCIES: ...
Return the currency code associated with this company. - If the currency code is invalid, use the default currency - If the currency code is not specified, use the default currency
currency_code
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def get_image_url(self): """Return the URL of the image for this company.""" if self.image: return InvenTree.helpers.getMediaUrl(self.image.url) return InvenTree.helpers.getBlankImage()
Return the URL of the image for this company.
get_image_url
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def get_thumbnail_url(self): """Return the URL for the thumbnail image for this Company.""" if self.image: return InvenTree.helpers.getMediaUrl(self.image.thumbnail.url) return InvenTree.helpers.getBlankThumbnail()
Return the URL for the thumbnail image for this Company.
get_thumbnail_url
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def parts(self): """Return SupplierPart objects which are supplied or manufactured by this company.""" return SupplierPart.objects.filter( Q(supplier=self.id) | Q(manufacturer_part__manufacturer=self.id) ).distinct()
Return SupplierPart objects which are supplied or manufactured by this company.
parts
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def stock_items(self): """Return a list of all stock items supplied or manufactured by this company.""" stock = apps.get_model('stock', 'StockItem') return stock.objects.filter( Q(supplier_part__supplier=self.id) | Q(supplier_part__manufacturer_part__manufacturer=self.id)...
Return a list of all stock items supplied or manufactured by this company.
stock_items
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def __str__(self): """Defines string representation of address to supple a one-line to API calls.""" available_lines = [ self.line1, self.line2, self.postal_code, self.postal_city, self.province, self.country, ] pop...
Defines string representation of address to supple a one-line to API calls.
__str__
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def save(self, *args, **kwargs): """Run checks when saving an address. Rules: - If this address is marked as "primary", ensure that all other addresses for this company are marked as non-primary """ others = list( Address.objects.filter(company=self.company).exclude(...
Run checks when saving an address. Rules: - If this address is marked as "primary", ensure that all other addresses for this company are marked as non-primary
save
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def create(cls, part, manufacturer, mpn, description, link=None): """Check if ManufacturerPart instance does not already exist then create it.""" manufacturer_part = None try: manufacturer_part = ManufacturerPart.objects.get( part=part, manufacturer=manufacturer, MPN...
Check if ManufacturerPart instance does not already exist then create it.
create
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def get_queryset(self): """Prefetch related fields when querying against the SupplierPart model.""" # Always prefetch related models return ( super() .get_queryset() .prefetch_related('part', 'supplier', 'manufacturer_part__manufacturer') )
Prefetch related fields when querying against the SupplierPart model.
get_queryset
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def clean(self): """Custom clean action for the SupplierPart model. Rules: - Ensure that manufacturer_part.part and part are the same! """ super().clean() self.pack_quantity = self.pack_quantity.strip() # An empty 'pack_quantity' value is equivalent to '1' ...
Custom clean action for the SupplierPart model. Rules: - Ensure that manufacturer_part.part and part are the same!
clean
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def save(self, *args, **kwargs): """Overriding save method to connect an existing ManufacturerPart.""" manufacturer_part = None if all(key in kwargs for key in ('manufacturer', 'MPN')): manufacturer_name = kwargs.pop('manufacturer') MPN = kwargs.pop('MPN') #...
Overriding save method to connect an existing ManufacturerPart.
save
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def base_quantity(self, quantity=1) -> Decimal: """Calculate the base unit quantiy for a given quantity.""" q = Decimal(quantity) * Decimal(self.pack_quantity_native) q = round(q, 10).normalize() return q
Calculate the base unit quantiy for a given quantity.
base_quantity
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def update_available_quantity(self, quantity): """Update the available quantity for this SupplierPart.""" self.available = quantity self.availability_updated = InvenTree.helpers.current_time() self.save()
Update the available quantity for this SupplierPart.
update_available_quantity
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def manufacturer_string(self): """Format a MPN string for this SupplierPart. Concatenates manufacture name and part number. """ items = [] if self.manufacturer_part: if self.manufacturer_part.manufacturer: items.append(self.manufacturer_part.manufact...
Format a MPN string for this SupplierPart. Concatenates manufacture name and part number.
manufacturer_string
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def add_price_break(self, quantity, price) -> None: """Create a new price break for this part. Args: quantity: Numerical quantity price: Must be a Money object """ # Check if a price break at that quantity already exists... if self.price_breaks.filter(qua...
Create a new price break for this part. Args: quantity: Numerical quantity price: Must be a Money object
add_price_break
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def on_order(self): """Return the total quantity of items currently on order. Subtract partially received stock as appropriate """ totals = self.open_orders().aggregate(Sum('quantity'), Sum('received')) # Quantity on order q = totals.get('quantity__sum', 0) # Q...
Return the total quantity of items currently on order. Subtract partially received stock as appropriate
on_order
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def purchase_orders(self): """Returns a list of purchase orders relating to this supplier part.""" return [ line.order for line in self.purchase_order_line_items.all().prefetch_related('order') ]
Returns a list of purchase orders relating to this supplier part.
purchase_orders
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def after_save_supplier_price(sender, instance, created, **kwargs): """Callback function when a SupplierPriceBreak is created or updated.""" if ( ( InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING) and not InvenTree.ready.isImportingData() ) ...
Callback function when a SupplierPriceBreak is created or updated.
after_save_supplier_price
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def after_delete_supplier_price(sender, instance, **kwargs): """Callback function when a SupplierPriceBreak is deleted.""" if ( ( InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING) and not InvenTree.ready.isImportingData() ) and instance.par...
Callback function when a SupplierPriceBreak is deleted.
after_delete_supplier_price
python
inventree/InvenTree
src/backend/InvenTree/company/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/models.py
MIT
def annotate_queryset(queryset): """Annotate the supplied queryset with aggregated information.""" # Add count of parts manufactured queryset = queryset.annotate( parts_manufactured=SubqueryCount('manufactured_parts') ) queryset = queryset.annotate(parts_supplied=Sub...
Annotate the supplied queryset with aggregated information.
annotate_queryset
python
inventree/InvenTree
src/backend/InvenTree/company/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/serializers.py
MIT
def __init__(self, *args, **kwargs): """Initialize this serializer with extra detail fields as required.""" part_detail = kwargs.pop('part_detail', True) manufacturer_detail = kwargs.pop('manufacturer_detail', True) prettify = kwargs.pop('pretty', False) super().__init__(*args, ...
Initialize this serializer with extra detail fields as required.
__init__
python
inventree/InvenTree
src/backend/InvenTree/company/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/serializers.py
MIT
def annotate_queryset(queryset): """Annotate the SupplierPart queryset with extra fields. Fields: in_stock: Current stock quantity for each SupplierPart """ queryset = queryset.annotate(in_stock=part.filters.annotate_total_stock()) queryset = queryset.annotate( ...
Annotate the SupplierPart queryset with extra fields. Fields: in_stock: Current stock quantity for each SupplierPart
annotate_queryset
python
inventree/InvenTree
src/backend/InvenTree/company/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/serializers.py
MIT
def update(self, supplier_part, data): """Custom update functionality for the serializer.""" available = data.pop('available', None) response = super().update(supplier_part, data) if available is not None and self.has_available_quantity: supplier_part.update_available_quant...
Custom update functionality for the serializer.
update
python
inventree/InvenTree
src/backend/InvenTree/company/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/serializers.py
MIT
def create(self, validated_data): """Extract manufacturer data and process ManufacturerPart.""" # Extract 'available' quantity from the serializer available = validated_data.pop('available', None) # Create SupplierPart supplier_part = super().create(validated_data) if a...
Extract manufacturer data and process ManufacturerPart.
create
python
inventree/InvenTree
src/backend/InvenTree/company/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/serializers.py
MIT
def __init__(self, *args, **kwargs): """Initialize this serializer with extra fields as required.""" supplier_detail = kwargs.pop('supplier_detail', False) part_detail = kwargs.pop('part_detail', False) super().__init__(*args, **kwargs) if isGeneratingSchema(): retu...
Initialize this serializer with extra fields as required.
__init__
python
inventree/InvenTree
src/backend/InvenTree/company/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/serializers.py
MIT
def setUpTestData(cls): """Perform initialization for the tests in this class.""" super().setUpTestData() Company.objects.create( name='ABC Co.', description='Seller of ABC products', website='www.abc-sales.com', is_customer=False, is_...
Perform initialization for the tests in this class.
setUpTestData
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def test_company_model(self): """Tests for the company model data.""" c = Company.objects.get(name='ABC Co.') self.assertEqual(c.name, 'ABC Co.') self.assertEqual(str(c), 'ABC Co. - Seller of ABC products')
Tests for the company model data.
test_company_model
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def test_image_renamer(self): """Test the company image upload functionality.""" c = Company.objects.get(pk=1) rn = rename_company_image(c, 'test.png') self.assertEqual(rn, 'company_images' + os.path.sep + 'company_1_img.png') rn = rename_company_image(c, 'test2') self.a...
Test the company image upload functionality.
test_image_renamer
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def test_part_pricing(self): """Unit tests for supplier part pricing.""" m2x4 = Part.objects.get(name='M2x4 LPHS') self.assertEqual(m2x4.get_price_info(5.5), '38.5 - 41.25') self.assertEqual(m2x4.get_price_info(10), '70 - 75') self.assertEqual(m2x4.get_price_info(100), '125 - 35...
Unit tests for supplier part pricing.
test_part_pricing
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def setUp(self): """Initialization for the tests in this class.""" # Create a simple company self.c = Company.objects.create( name='Test Corp.', description='We make stuff good' ) # Add some contacts Contact.objects.create(name='Joe Smith', company=self.c) ...
Initialization for the tests in this class.
setUp
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def test_primary_constraint(self): """Test that there can only be one company-'primary=true' pair.""" Address.objects.create(company=self.c, primary=True) Address.objects.create(company=self.c, primary=False) self.assertEqual(Address.objects.count(), 2) self.assertTrue(Address....
Test that there can only be one company-'primary=true' pair.
test_primary_constraint
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def setUp(self): """Initialization for the unit tests in this class.""" # Create a manufacturer part self.part = Part.objects.get(pk=1) manufacturer = Company.objects.get(pk=1) self.mp = ManufacturerPart.create( part=self.part, manufacturer=manufacturer, ...
Initialization for the unit tests in this class.
setUp
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def test_exists(self): """That that a ManufacturerPart has been created.""" self.assertEqual(ManufacturerPart.objects.count(), 4) # Check that manufacturer part was created from supplier part creation manufacturer_parts = ManufacturerPart.objects.filter(manufacturer=1) self.asse...
That that a ManufacturerPart has been created.
test_exists
python
inventree/InvenTree
src/backend/InvenTree/company/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/tests.py
MIT
def setUpTestData(cls): """Perform initialization for the unit test class.""" super().setUpTestData() # Create some company objects to work with cls.acme = Company.objects.create( name='ACME', description='Supplier', is_customer=False, is_supplier=True ) Comp...
Perform initialization for the unit test class.
setUpTestData
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_company_list(self): """Test the list API endpoint for the Company model.""" url = reverse('api-company-list') # There should be three companies response = self.get(url) self.assertEqual(len(response.data), 3) data = {'is_customer': True} # There should...
Test the list API endpoint for the Company model.
test_company_list
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_company_detail(self): """Tests for the Company detail endpoint.""" url = reverse('api-company-detail', kwargs={'pk': self.acme.pk}) response = self.get(url, expected_code=200) self.assertIn('name', response.data.keys()) self.assertEqual(response.data['name'], 'ACME') ...
Tests for the Company detail endpoint.
test_company_detail
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_company_search(self): """Test search functionality in company list.""" url = reverse('api-company-list') data = {'search': 'cup'} response = self.get(url, data) self.assertEqual(len(response.data), 2)
Test search functionality in company list.
test_company_search
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_company_create(self): """Test that we can create a company via the API!""" url = reverse('api-company-list') # Name is required response = self.post(url, {'description': 'A description!'}, expected_code=400) # Minimal example, checking default values response =...
Test that we can create a company via the API!
test_company_create
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_company_active(self): """Test that the 'active' value and filter works.""" Company.objects.filter(active=False).update(active=True) n = Company.objects.count() url = reverse('api-company-list') self.assertEqual( len(self.get(url, data={'active': True}, expe...
Test that the 'active' value and filter works.
test_company_active
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_company_notes(self): """Test the markdown 'notes' field for the Company model.""" pk = Company.objects.first().pk url = reverse('api-company-detail', kwargs={'pk': pk}) # Attempt to inject malicious markdown into the "notes" field xss = [ '[Click me](javascr...
Test the markdown 'notes' field for the Company model.
test_company_notes
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def setUpTestData(cls): """Perform init for this test class.""" super().setUpTestData() # Create some companies companies = [ Company(name=f'Company {idx}', description='Some company') for idx in range(3) ] Company.objects.bulk_create(companies) ...
Perform init for this test class.
setUpTestData
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_create(self): """Test that we can create a new Contact object via the API.""" n = Contact.objects.count() company = Company.objects.first() # Without required permissions, creation should fail self.post( self.url, {'company': company.pk, 'name': 'Joe Bloggs...
Test that we can create a new Contact object via the API.
test_create
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_edit(self): """Test that we can edit a Contact via the API.""" # Get the first contact contact = Contact.objects.first() # Use this contact in the tests url = reverse('api-contact-detail', kwargs={'pk': contact.pk}) # Retrieve detail view data = self.get...
Test that we can edit a Contact via the API.
test_edit
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_delete(self): """Tests that we can delete a Contact via the API.""" # Get the last contact contact = Contact.objects.first() url = reverse('api-contact-detail', kwargs={'pk': contact.pk}) # Delete (without required permissions) self.delete(url, expected_code=403...
Tests that we can delete a Contact via the API.
test_delete
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def setUpTestData(cls): """Perform initialization for this test class.""" super().setUpTestData() cls.num_companies = 3 cls.num_addr = 3 # Create some companies companies = [ Company(name=f'Company {idx}', description='Some company') for idx in ran...
Perform initialization for this test class.
setUpTestData
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_list(self): """Test listing all addresses without filtering.""" response = self.get(self.url, expected_code=200) self.assertEqual(len(response.data), self.num_companies * self.num_addr)
Test listing all addresses without filtering.
test_list
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_filter_list(self): """Test listing addresses filtered on company.""" company = Company.objects.first() response = self.get(self.url, {'company': company.pk}, expected_code=200) self.assertEqual(len(response.data), self.num_addr)
Test listing addresses filtered on company.
test_filter_list
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_get(self): """Test that objects are properly returned from a get.""" addr = Address.objects.first() url = reverse('api-address-detail', kwargs={'pk': addr.pk}) response = self.get(url, expected_code=200) self.assertEqual(response.data['pk'], addr.pk) for key i...
Test that objects are properly returned from a get.
test_get
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_manufacturer_part_list(self): """Test the ManufacturerPart API list functionality.""" url = reverse('api-manufacturer-part-list') # There should be three manufacturer parts response = self.get(url) self.assertEqual(len(response.data), 3) # Create manufacturer p...
Test the ManufacturerPart API list functionality.
test_manufacturer_part_list
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_manufacturer_part_detail(self): """Tests for the ManufacturerPart detail endpoint.""" url = reverse('api-manufacturer-part-detail', kwargs={'pk': 1}) response = self.get(url) self.assertEqual(response.data['MPN'], 'MPN123') # Change the MPN data = {'MPN': 'MPN-...
Tests for the ManufacturerPart detail endpoint.
test_manufacturer_part_detail
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_manufacturer_part_search(self): """Test search functionality in manufacturer list.""" url = reverse('api-manufacturer-part-list') data = {'search': 'MPN'} response = self.get(url, data) self.assertEqual(len(response.data), 3)
Test search functionality in manufacturer list.
test_manufacturer_part_search
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_supplier_part_create(self): """Test a SupplierPart can be created via the API.""" url = reverse('api-supplier-part-list') # Create a manufacturer part response = self.post( reverse('api-manufacturer-part-list'), { 'part': 1, ...
Test a SupplierPart can be created via the API.
test_supplier_part_create
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_supplier_part_list(self): """Test the SupplierPart API list functionality.""" url = reverse('api-supplier-part-list') # Return *all* SupplierParts response = self.get(url, {}, expected_code=200) self.assertEqual(len(response.data), SupplierPart.objects.count()) ...
Test the SupplierPart API list functionality.
test_supplier_part_list
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_available(self): """Tests for updating the 'available' field.""" url = reverse('api-supplier-part-list') # Should fail when sending an invalid 'available' field response = self.post( url, {'part': 1, 'supplier': 2, 'SKU': 'QQ', 'available': 'not a number...
Tests for updating the 'available' field.
test_available
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def test_active(self): """Test that 'active' status filtering works correctly.""" url = reverse('api-supplier-part-list') # Create a new company, which is inactive company = Company.objects.create( name='Inactive Company', is_supplier=True, active=False ) pa...
Test that 'active' status filtering works correctly.
test_active
python
inventree/InvenTree
src/backend/InvenTree/company/test_api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_api.py
MIT
def prepare(self): """Create some simple Company data, and ensure that it migrates OK.""" Company = self.old_state.apps.get_model('company', 'company') Company.objects.create( name='MSPC', description='Michael Scotts Paper Company', is_supplier=True )
Create some simple Company data, and ensure that it migrates OK.
prepare
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def prepare(self): """Prepare the database by adding some test data 'before' the change. Changes: - Part object - Company object (supplier) - SupplierPart object """ Part = self.old_state.apps.get_model('part', 'part') Company = self.old_state.apps.get_mo...
Prepare the database by adding some test data 'before' the change. Changes: - Part object - Company object (supplier) - SupplierPart object
prepare
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def test_company_objects(self): """Test that the new companies have been created successfully.""" # Two additional company objects should have been created Company = self.new_state.apps.get_model('company', 'company') self.assertEqual(Company.objects.count(), 3) # The new compan...
Test that the new companies have been created successfully.
test_company_objects
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def prepare(self): """Prepare some data. Changes: - A part to buy - A supplier to buy from - A supplier part - Multiple currency objects - Multiple supplier price breaks """ Part = self.old_state.apps.get_model('part', 'part') part = Part...
Prepare some data. Changes: - A part to buy - A supplier to buy from - A supplier part - Multiple currency objects - Multiple supplier price breaks
prepare
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def test_currency_migration(self): """Test database state after applying migrations.""" PB = self.new_state.apps.get_model('company', 'supplierpricebreak') for pb in PB.objects.all(): # Test that a price has been assigned self.assertIsNotNone(pb.price)
Test database state after applying migrations.
test_currency_migration
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def prepare(self): """Set up some companies with addresses.""" Company = self.old_state.apps.get_model('company', 'company') Company.objects.create(name='Company 1', address=self.short_l1) Company.objects.create(name='Company 2', address=self.long_l1 + self.l2)
Set up some companies with addresses.
prepare
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def test_address_migration(self): """Test database state after applying the migration.""" Address = self.new_state.apps.get_model('company', 'address') Company = self.new_state.apps.get_model('company', 'company') c1 = Company.objects.filter(name='Company 1').first() c2 = Compan...
Test database state after applying the migration.
test_address_migration
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def test_supplier_part_quantity(self): """Test that the supplier part quantity is correctly migrated.""" SupplierPart = self.new_state.apps.get_model('company', 'supplierpart') for i, sp in enumerate(SupplierPart.objects.all()): self.assertEqual(sp.pack_quantity, str(i + 1)) ...
Test that the supplier part quantity is correctly migrated.
test_supplier_part_quantity
python
inventree/InvenTree
src/backend/InvenTree/company/test_migrations.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_migrations.py
MIT
def test_pack_quantity_dimensionless(self): """Test valid values for the 'pack_quantity' field.""" # Create a part without units (dimensionless) part = Part.objects.create( name='Test Part', description='Test part description', component=True ) # Create a supplier (c...
Test valid values for the 'pack_quantity' field.
test_pack_quantity_dimensionless
python
inventree/InvenTree
src/backend/InvenTree/company/test_supplier_parts.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_supplier_parts.py
MIT
def test_pack_quantity(self): """Test pack_quantity for a part with a specified dimension.""" # Create a part with units 'm' part = Part.objects.create( name='Test Part', description='Test part description', component=True, units='m', ) ...
Test pack_quantity for a part with a specified dimension.
test_pack_quantity
python
inventree/InvenTree
src/backend/InvenTree/company/test_supplier_parts.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/test_supplier_parts.py
MIT
def reverse_association(apps, schema_editor): # pragma: no cover """ This is the 'reverse' operation of the manufacturer reversal. This operation is easier: For each SupplierPart object, copy the name of the 'manufacturer' field into the 'manufacturer_name' field. """ cursor = connection....
This is the 'reverse' operation of the manufacturer reversal. This operation is easier: For each SupplierPart object, copy the name of the 'manufacturer' field into the 'manufacturer_name' field.
reverse_association
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
MIT
def associate_manufacturers(apps, schema_editor): """ This migration is the "middle step" in migration of the "manufacturer" field for the SupplierPart model. Previously the "manufacturer" field was a simple text field with the manufacturer name. This is quite insufficient. The new "manufacturer" f...
This migration is the "middle step" in migration of the "manufacturer" field for the SupplierPart model. Previously the "manufacturer" field was a simple text field with the manufacturer name. This is quite insufficient. The new "manufacturer" field is a link to Company object which has the "is_manufa...
associate_manufacturers
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
MIT
def get_manufacturer_name(part_id): """ THIS IS CRITICAL! Once the pythonic representation of the model has removed the 'manufacturer_name' field, it is NOT ACCESSIBLE by calling SupplierPart.manufacturer_name. However, as long as the migrations are applied in order, then the t...
THIS IS CRITICAL! Once the pythonic representation of the model has removed the 'manufacturer_name' field, it is NOT ACCESSIBLE by calling SupplierPart.manufacturer_name. However, as long as the migrations are applied in order, then the table DOES have a field called 'manufacturer_nam...
get_manufacturer_name
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
MIT
def link_part(part_id, name): """ Attempt to link Part to an existing Company """ # Matches a company name directly if name in companies.keys(): # pragma: no cover print(" - Part[{pk}]: '{n}' maps to existing manufacturer".format(pk=part_id, n=name)) manufacturer_id = ...
Attempt to link Part to an existing Company
link_part
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
MIT
def find_matches(text, threshold=65): """ Attempt to match a 'name' to an existing Company. A list of potential matches will be returned. """ matches = [] for name in companies.keys(): # Case-insensitive matching ratio = fuzz.partial_ratio(name.l...
Attempt to match a 'name' to an existing Company. A list of potential matches will be returned.
find_matches
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0019_auto_20200413_0642.py
MIT
def migrate_currencies(apps, schema_editor): """ Migrate from the 'old' method of handling currencies, to the new method which uses the django-money library. Previously, we created a custom Currency model, which was very simplistic. Here we will attempt to map each existing "currency" referenc...
Migrate from the 'old' method of handling currencies, to the new method which uses the django-money library. Previously, we created a custom Currency model, which was very simplistic. Here we will attempt to map each existing "currency" reference for the SupplierPriceBreak model, to a new dja...
migrate_currencies
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0026_auto_20201110_1011.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0026_auto_20201110_1011.py
MIT
def reverse_currencies(apps, schema_editor): # pragma: no cover """ Reverse the "update" process. Here we may be in the situation that the legacy "Currency" table is empty, and so we have to re-populate it based on the new price_currency codes. """ print("Reversing currency migration...") ...
Reverse the "update" process. Here we may be in the situation that the legacy "Currency" table is empty, and so we have to re-populate it based on the new price_currency codes.
reverse_currencies
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0026_auto_20201110_1011.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0026_auto_20201110_1011.py
MIT
def update_supplier_part_units(apps, schema_editor): """Migrate existing supplier part units to new field""" SupplierPart = apps.get_model('company', 'SupplierPart') supplier_parts = SupplierPart.objects.all() for sp in supplier_parts: pack_size = normalize(sp.pack_size) sp.pack_quant...
Migrate existing supplier part units to new field
update_supplier_part_units
python
inventree/InvenTree
src/backend/InvenTree/company/migrations/0060_auto_20230519_0344.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/company/migrations/0060_auto_20230519_0344.py
MIT
def __init__(self, *args, **kwargs): """Initialise the DataExportSerializerMixin. Determine if the serializer is being used for data export, and if so, adjust the serializer fields accordingly. """ exporting = kwargs.pop('exporting', False) super().__init__(*args, **kwa...
Initialise the DataExportSerializerMixin. Determine if the serializer is being used for data export, and if so, adjust the serializer fields accordingly.
__init__
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def get_exportable_fields(self) -> dict: """Return a dict of fields which can be exported against this serializer instance. Note: Any fields which should be excluded from export have already been removed Returns: dict: A dictionary of field names and field objects """ ...
Return a dict of fields which can be exported against this serializer instance. Note: Any fields which should be excluded from export have already been removed Returns: dict: A dictionary of field names and field objects
get_exportable_fields
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def get_child_fields(self, field_name: str, field) -> dict: """Return a dictionary of child fields for a given field. Only child fields which match the 'export_child_fields' list will be returned. """ child_fields = {} if sub_fields := getattr(field, 'fields', None): ...
Return a dictionary of child fields for a given field. Only child fields which match the 'export_child_fields' list will be returned.
get_child_fields
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def get_nested_value(self, row: dict, key: str) -> any: """Get a nested value from a dictionary. This method allows for dot notation to access nested fields. Arguments: row: The dictionary to extract the value from key: The key to extract Returns: a...
Get a nested value from a dictionary. This method allows for dot notation to access nested fields. Arguments: row: The dictionary to extract the value from key: The key to extract Returns: any: The extracted value
get_nested_value
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def generate_headers(self) -> OrderedDict: """Generate a list of default headers for the exported data. Returns an ordered dict of field names and their corresponding human-readable labels. e.g. { 'id': 'ID', 'name': 'Name', ... } "...
Generate a list of default headers for the exported data. Returns an ordered dict of field names and their corresponding human-readable labels. e.g. { 'id': 'ID', 'name': 'Name', ... }
generate_headers
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def export_to_file(self, data, headers: OrderedDict, file_format): """Export the queryset to a file in the specified format. Arguments: queryset: The queryset to export data: The serialized dataset to export headers: The headers to use for the exported data {field: l...
Export the queryset to a file in the specified format. Arguments: queryset: The queryset to export data: The serialized dataset to export headers: The headers to use for the exported data {field: label} file_format: The file format to export to Returns: ...
export_to_file
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def is_exporting(self) -> bool: """Determine if the view is currently exporting data.""" if request := getattr(self, 'request', None): return str2bool( request.data.get('export') or request.query_params.get('export') ) return False
Determine if the view is currently exporting data.
is_exporting
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def get_plugin(self, plugin_slug=None): """Return the plugin instance associated with the export request. Arguments: plugin_slug: The slug of the plugin to use for exporting the data (optional) """ PLUGIN_KEY = 'export_plugin' if not plugin_slug: if requ...
Return the plugin instance associated with the export request. Arguments: plugin_slug: The slug of the plugin to use for exporting the data (optional)
get_plugin
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def get_serializer(self, *args, **kwargs): """Return the serializer instance for the view. - Only applies for OPTIONS or GET requests - OPTIONS requests to determine plugin serializer options - GET request to perform the data export - If the view is exporting data, return the Da...
Return the serializer instance for the view. - Only applies for OPTIONS or GET requests - OPTIONS requests to determine plugin serializer options - GET request to perform the data export - If the view is exporting data, return the DataExportOptionsSerializer. - Otherwise, return...
get_serializer
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def export_data( self, export_plugin, export_format: str, export_context: dict, output: DataOutput, ): """Export the data in the specified format. Arguments: export_plugin: The plugin instance to use for exporting the data export_forma...
Export the data in the specified format. Arguments: export_plugin: The plugin instance to use for exporting the data export_format: The file format to export the data in export_context: Additional context data to pass to the plugin output: The DataOutput object t...
export_data
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def get(self, request, *args, **kwargs): """Override the GET method to determine export options.""" from common.serializers import DataOutputSerializer # If we are not exporting data, return the default response if self.is_exporting(): # Determine if the export options are v...
Override the GET method to determine export options.
get
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/mixins.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/mixins.py
MIT
def __init__(self, *args, **kwargs): """Construct the DataExportOptionsSerializer. - The exact nature of the available fields depends on which plugin is selected. - The selected plugin may 'extend' the fields available in the serializer. """ # Reset fields to a known state ...
Construct the DataExportOptionsSerializer. - The exact nature of the available fields depends on which plugin is selected. - The selected plugin may 'extend' the fields available in the serializer.
__init__
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/serializers.py
MIT
def export_data( view_class, user_id: int, query_params: dict, plugin_key: str, export_format: str, export_context: dict, output_id: int, ): """Perform the data export task using the provided parameters. Arguments: view_class: The class of the view to export data from ...
Perform the data export task using the provided parameters. Arguments: view_class: The class of the view to export data from user_id: The ID of the user who requested the export query_params: Query parameters for the export plugin_key: The key for the export plugin export_fo...
export_data
python
inventree/InvenTree
src/backend/InvenTree/data_exporter/tasks.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/data_exporter/tasks.py
MIT
def get_status_model(self, *args, **kwargs): """Return the StatusCode model based on extra parameters passed to the view.""" status_model = self.kwargs.get(self.MODEL_REF, None) if status_model is None: raise serializers.ValidationError( f"StatusView view called with...
Return the StatusCode model based on extra parameters passed to the view.
get_status_model
python
inventree/InvenTree
src/backend/InvenTree/generic/states/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/api.py
MIT
def get(self, request, *args, **kwargs): """Perform a GET request to learn information about status codes.""" status_class = self.get_status_model() if not inspect.isclass(status_class): raise NotImplementedError('`status_class` not a class') if not issubclass(status_class,...
Perform a GET request to learn information about status codes.
get
python
inventree/InvenTree
src/backend/InvenTree/generic/states/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/api.py
MIT
def state_reference_mappings(): """Return a list of custom user state references.""" classes = inheritors(StatusCode) return [(a.__name__, a.__name__) for a in sorted(classes, key=lambda x: x.__name__)]
Return a list of custom user state references.
state_reference_mappings
python
inventree/InvenTree
src/backend/InvenTree/generic/states/custom.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/custom.py
MIT
def get_logical_value(value, model: str): """Return the state model for the selected value.""" from common.models import InvenTreeCustomUserStateModel return InvenTreeCustomUserStateModel.objects.get(key=value, model__model=model)
Return the state model for the selected value.
get_logical_value
python
inventree/InvenTree
src/backend/InvenTree/generic/states/custom.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/custom.py
MIT
def to_internal_value(self, data): """Map the choice (that might be a custom one) back to the logical value.""" try: return super().to_internal_value(data) except serializers.ValidationError: try: logical = get_logical_value(data, self.choice_mdl._meta.mod...
Map the choice (that might be a custom one) back to the logical value.
to_internal_value
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def get_field_info(self, field, field_info): """Return the field information for the given item.""" from common.models import InvenTreeCustomUserStateModel # Static choices choices = [ { 'value': choice_value, 'display_name': force_str(choice_...
Return the field information for the given item.
get_field_info
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def contribute_to_class(self, cls, name): """Add the _custom_key field to the model.""" cls._meta.supports_custom_status = True if not hasattr(self, '_custom_key_field') and not hasattr( cls, f'{name}_custom_key' ): self.add_field(cls, name) super().cont...
Add the _custom_key field to the model.
contribute_to_class
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def clean(self, value: Any, model_instance: Any) -> Any: """Ensure that the value is not an empty string.""" if value == '': value = None return super().clean(value, model_instance)
Ensure that the value is not an empty string.
clean
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def add_field(self, cls, name): """Adds custom_key_field to the model class to save additional status information.""" from generic.states.validators import CustomStatusCodeValidator validators = [] if self.status_class: validators.append(CustomStatusCodeValidator(status_cla...
Adds custom_key_field to the model class to save additional status information.
add_field
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def update(self, instance, validated_data): """Ensure the custom field is updated if the leader was changed.""" self.gather_custom_fields() # Mirror values from leader to follower for field in self._custom_fields_leader: follower_field_name = f'{field}_custom_key' ...
Ensure the custom field is updated if the leader was changed.
update
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def to_representation(self, instance): """Ensure custom state fields are not served empty.""" data = super().to_representation(instance) for field in self.gather_custom_fields(): if data[field] is None: data[field] = data[ field.replace('_custom_ke...
Ensure custom state fields are not served empty.
to_representation
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def gather_custom_fields(self): """Gather all custom fields on the serializer.""" if self._custom_fields_follower: self._is_gathering = False return self._custom_fields_follower if self._is_gathering: self._custom_fields = {} else: self._i...
Gather all custom fields on the serializer.
gather_custom_fields
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def build_standard_field(self, field_name, model_field): """Use custom field for custom status model. This is required because of DRF overwriting all fields with choice sets. """ field_cls, field_kwargs = super().build_standard_field(field_name, model_field) if issubclass(field_...
Use custom field for custom status model. This is required because of DRF overwriting all fields with choice sets.
build_standard_field
python
inventree/InvenTree
src/backend/InvenTree/generic/states/fields.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/fields.py
MIT
def __eq__(self, obj): """Override equality operator to allow comparison with int.""" if type(obj) is int: return self.value == obj if isinstance(obj, BaseEnum): return self.value == obj.value if hasattr(obj, 'value'): return self.value == obj.value ...
Override equality operator to allow comparison with int.
__eq__
python
inventree/InvenTree
src/backend/InvenTree/generic/states/states.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/generic/states/states.py
MIT