21 lines
525 B
Python
21 lines
525 B
Python
from models.invoice import Invoice, InvoiceLine
|
|
from decimal import Decimal
|
|
|
|
def invoice_from_quote(quote):
|
|
inv = Invoice(
|
|
client_id=quote.client_id,
|
|
quote_id=quote.id
|
|
)
|
|
|
|
for item in quote.items:
|
|
inv.lines.append(
|
|
InvoiceLine(
|
|
description=item.description,
|
|
qty=item.qty,
|
|
unit_price=item.unit_price
|
|
)
|
|
)
|
|
|
|
inv.total = sum([Decimal(str(l.qty)) * Decimal(str(l.unit_price)) for l in inv.lines])
|
|
return inv
|