Adds 'status_text' functions to models (#3752)

- Convert status codes into text representation (translated)
- Useful for template rendering
This commit is contained in:
Oliver 2022-10-07 00:18:11 +11:00 committed by GitHub
parent cfff5ea264
commit d194aef79e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -236,6 +236,11 @@ class Build(MPTTModel, ReferenceIndexingMixin):
help_text=_('Build status code')
)
@property
def status_text(self):
"""Return the text representation of the status field"""
return BuildStatus.text(self.status)
batch = models.CharField(
verbose_name=_('Batch Code'),
max_length=100,

View File

@ -248,6 +248,11 @@ class PurchaseOrder(Order):
status = models.PositiveIntegerField(default=PurchaseOrderStatus.PENDING, choices=PurchaseOrderStatus.items(),
help_text=_('Purchase order status'))
@property
def status_text(self):
"""Return the text representation of the status field"""
return PurchaseOrderStatus.text(self.status)
supplier = models.ForeignKey(
Company, on_delete=models.SET_NULL,
null=True,
@ -645,6 +650,11 @@ class SalesOrder(Order):
status = models.PositiveIntegerField(default=SalesOrderStatus.PENDING, choices=SalesOrderStatus.items(),
verbose_name=_('Status'), help_text=_('Purchase order status'))
@property
def status_text(self):
"""Return the text representation of the status field"""
return SalesOrderStatus.text(self.status)
customer_reference = models.CharField(max_length=64, blank=True, verbose_name=_('Customer Reference '), help_text=_("Customer order reference code"))
target_date = models.DateField(

View File

@ -670,6 +670,11 @@ class StockItem(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel):
choices=StockStatus.items(),
validators=[MinValueValidator(0)])
@property
def status_text(self):
"""Return the text representation of the status field"""
return StockStatus.text(self.status)
notes = InvenTreeNotesField(help_text=_('Stock Item Notes'))
purchase_price = InvenTreeModelMoneyField(