2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

add total price woth js reload

This commit is contained in:
Matthias
2022-03-06 23:21:33 +01:00
parent 56142b9303
commit f0b19e69b8
5 changed files with 54 additions and 0 deletions

View File

@ -23,6 +23,7 @@ from markdownx.models import MarkdownxField
from mptt.models import TreeForeignKey
from djmoney.contrib.exchange.models import convert_money
from djmoney.money import Money
from common.settings import currency_code_default
from users import models as UserModels
@ -600,6 +601,23 @@ class SalesOrder(Order):
verbose_name=_('shipped by')
)
def get_total_price(self):
"""
Calculates the total price of all order lines
"""
target_currency = currency_code_default()
total = Money(0, target_currency)
# order items
total += sum([a.quantity * convert_money(a.sale_price, target_currency) for a in self.lines.all() if a.sale_price])
# additional lines
total += sum([a.quantity * convert_money(a.sale_price, target_currency) for a in self.additional_lines.all() if a.sale_price])
# set decimal-places
total.decimal_places = 4
return total
@property
def is_overdue(self):
"""

View File

@ -515,6 +515,8 @@ class SalesOrderSerializer(ReferenceIndexingSerializerMixin, InvenTreeModelSeria
reference = serializers.CharField(required=True)
total_price_string = serializers.CharField(source='get_total_price', read_only=True)
class Meta:
model = order.models.SalesOrder
@ -535,6 +537,7 @@ class SalesOrderSerializer(ReferenceIndexingSerializerMixin, InvenTreeModelSeria
'status_text',
'shipment_date',
'target_date',
'total_price_string',
]
read_only_fields = [

View File

@ -183,6 +183,12 @@ src="{% static 'img/blank_image.png' %}"
<td>{{ order.responsible }}</td>
</tr>
{% endif %}
<tr>
<td><span class='fas fa-dollar-sign'></span></td>
<td>{% trans "Total cost" %}</td>
<td id="soTotalPrice">{{ order.get_total_price }}</td>
</tr>
</table>
{% endblock %}

View File

@ -292,6 +292,13 @@
}
);
loadOrderTotal(
'#soTotalPrice',
{
url: '{% url "api-so-detail" order.pk %}',
}
);
enableSidebar('salesorder');
{% endblock %}