2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-05 13:10:57 +00:00

Move Meta class to top of class definition (#4363)

This commit is contained in:
Oliver
2023-02-18 18:51:00 +11:00
committed by GitHub
parent 139274f356
commit cc2e7ee8a5
27 changed files with 1085 additions and 1084 deletions

View File

@ -3045,6 +3045,10 @@ class PartAttachment(InvenTreeAttachment):
class PartSellPriceBreak(common.models.PriceBreak):
"""Represents a price break for selling this part."""
class Meta:
"""Metaclass providing extra model definition"""
unique_together = ('part', 'quantity')
@staticmethod
def get_api_url():
"""Return the list API endpoint URL associated with the PartSellPriceBreak model"""
@ -3057,14 +3061,14 @@ class PartSellPriceBreak(common.models.PriceBreak):
verbose_name=_('Part')
)
class Meta:
"""Metaclass providing extra model definition"""
unique_together = ('part', 'quantity')
class PartInternalPriceBreak(common.models.PriceBreak):
"""Represents a price break for internally selling this part."""
class Meta:
"""Metaclass providing extra model definition"""
unique_together = ('part', 'quantity')
@staticmethod
def get_api_url():
"""Return the list API endpoint URL associated with the PartInternalPriceBreak model"""
@ -3076,10 +3080,6 @@ class PartInternalPriceBreak(common.models.PriceBreak):
verbose_name=_('Part')
)
class Meta:
"""Metaclass providing extra model definition"""
unique_together = ('part', 'quantity')
class PartStar(models.Model):
"""A PartStar object creates a subscription relationship between a User and a Part.
@ -3091,10 +3091,6 @@ class PartStar(models.Model):
user: Link to a User object
"""
part = models.ForeignKey(Part, on_delete=models.CASCADE, verbose_name=_('Part'), related_name='starred_users')
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('User'), related_name='starred_parts')
class Meta:
"""Metaclass providing extra model definition"""
unique_together = [
@ -3102,6 +3098,10 @@ class PartStar(models.Model):
'user'
]
part = models.ForeignKey(Part, on_delete=models.CASCADE, verbose_name=_('Part'), related_name='starred_users')
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('User'), related_name='starred_parts')
class PartCategoryStar(models.Model):
"""A PartCategoryStar creates a subscription relationship between a User and a PartCategory.
@ -3111,10 +3111,6 @@ class PartCategoryStar(models.Model):
user: Link to a User object
"""
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE, verbose_name=_('Category'), related_name='starred_users')
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('User'), related_name='starred_categories')
class Meta:
"""Metaclass providing extra model definition"""
unique_together = [
@ -3122,6 +3118,10 @@ class PartCategoryStar(models.Model):
'user',
]
category = models.ForeignKey(PartCategory, on_delete=models.CASCADE, verbose_name=_('Category'), related_name='starred_users')
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name=_('User'), related_name='starred_categories')
class PartTestTemplate(models.Model):
"""A PartTestTemplate defines a 'template' for a test which is required to be run against a StockItem (an instance of the Part).
@ -3292,6 +3292,11 @@ class PartParameter(models.Model):
data: The data (value) of the Parameter [string]
"""
class Meta:
"""Metaclass providing extra model definition"""
# Prevent multiple instances of a parameter for a single part
unique_together = ('part', 'template')
@staticmethod
def get_api_url():
"""Return the list API endpoint URL associated with the PartParameter model"""
@ -3306,11 +3311,6 @@ class PartParameter(models.Model):
units=str(self.template.units)
)
class Meta:
"""Metaclass providing extra model definition"""
# Prevent multiple instances of a parameter for a single part
unique_together = ('part', 'template')
part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='parameters', verbose_name=_('Part'), help_text=_('Parent Part'))
template = models.ForeignKey(PartParameterTemplate, on_delete=models.CASCADE, related_name='instances', verbose_name=_('Template'), help_text=_('Parameter Template'))
@ -3424,6 +3424,17 @@ class BomItem(DataImportMixin, models.Model):
}
}
class Meta:
"""Metaclass providing extra model definition"""
verbose_name = _("BOM Item")
def __str__(self):
"""Return a string representation of this BomItem instance"""
return "{n} x {child} to make {parent}".format(
parent=self.part.full_name,
child=self.sub_part.full_name,
n=decimal2string(self.quantity))
@staticmethod
def get_api_url():
"""Return the list API endpoint URL associated with the BomItem model"""
@ -3638,17 +3649,6 @@ class BomItem(DataImportMixin, models.Model):
except Part.DoesNotExist:
raise ValidationError({'sub_part': _('Sub part must be specified')})
class Meta:
"""Metaclass providing extra model definition"""
verbose_name = _("BOM Item")
def __str__(self):
"""Return a string representation of this BomItem instance"""
return "{n} x {child} to make {parent}".format(
parent=self.part.full_name,
child=self.sub_part.full_name,
n=decimal2string(self.quantity))
def get_overage_quantity(self, quantity):
"""Calculate overage quantity."""
# Most of the time overage string will be empty