From 72d565d17a696d378a27e2aee39f96be06cd5589 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 11 Mar 2022 00:20:36 +0100 Subject: [PATCH] move to abstract model --- InvenTree/order/models.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index f7382feb84..c7ca9dd04c 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -151,6 +151,23 @@ class Order(ReferenceIndexingMixin): notes = MarkdownxField(blank=True, verbose_name=_('Notes'), help_text=_('Order notes')) + 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 + class PurchaseOrder(Order): """ A PurchaseOrder represents goods shipped inwards from an external supplier. @@ -601,23 +618,6 @@ 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): """