move to abstract model

This commit is contained in:
Matthias 2022-03-11 00:20:36 +01:00
parent 2036164ef1
commit 72d565d17a
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -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):
"""