Facilitated translation for low stock notification subject

moved the message/content of low stock notification to html template
Facilitated translation in low stock notification html template file
This commit is contained in:
rocheparadox 2021-10-30 20:32:10 +05:30
parent e0cd02ee60
commit 6ec2801fce
2 changed files with 9 additions and 8 deletions

View File

@ -12,6 +12,7 @@ from django.utils import timezone
from django.core.exceptions import AppRegistryNotReady
from django.db.utils import OperationalError, ProgrammingError
from django.template.loader import render_to_string
from django.utils.translation import gettext_lazy as _
logger = logging.getLogger("inventree")
@ -321,21 +322,18 @@ def notify_low_stock(stock_item):
if len(starred_users) > 0:
logger.info(f"Notify users regarding low stock of {stock_item.part.name}")
body = f'Hi, {stock_item.part.name} is low on stock. Kindly do the needful.'
context = {
'part_name': stock_item.part.name,
# Part url can be used to open the page of part in application from the email.
# It can be facilitated when the application base url is accessible programmatically.
# 'part_url': f'{application_base_url}/part/{stock_item.part.id}',
'message': body,
# quantity is in decimal field datatype. Since the same datatype is used in models,
# it is not converted to number/integer,
'part_quantity': stock_item.quantity,
'minimum_quantity': stock_item.part.minimum_stock
}
subject = f'Attention! {stock_item.part.name} is low on stock'
subject = _(f'Attention! {stock_item.part.name} is low on stock')
html_message = render_to_string('stock/low_stock_notification.html', context)
recipients = starred_users.values_list('email', flat=True)
send_email(subject, body, recipients, html_message=html_message)
send_email(subject, '', recipients, html_message=html_message)

View File

@ -1,4 +1,6 @@
<p>{{ message }}</p>
{% load i18n %}
<p>{% trans "Hi, " %} {{ part_name }} {% trans "is low on stock. Kindly do the needful." %}</p>
<table style="border-collapse:collapse; width: 80%;margin-left: 10%; font-size: 1rem">
@ -19,8 +21,9 @@
</tr>
<tr style="background-color: aliceblue;height: 4rem;">
<td colspan="3" style="padding-top:1rem; text-align: center">You are receiving this mail because you have starred the part {{ part_name }} in
Inventree application</td>
<td colspan="3" style="padding-top:1rem; text-align: center">{% trans "You are receiving this mail because you have starred the part " %} {{ part_name }}
{% trans "Inventree application" %}
</td>
</tr>
</table>