crudbasico/models/invoice_item.py

22 lines
914 B
Python

from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class InvoiceItem(db.Model):
id = db.Column(db.Integer, primary_key=True)
invoice_id = db.Column(db.Integer, db.ForeignKey('invoice.id'), nullable=False)
description = db.Column(db.String(255), nullable=False) # Descrição do item
quantity = db.Column(db.Integer, nullable=False) # Quantidade
unit_price = db.Column(db.Numeric(10, 2), nullable=False) # Preço unitário
total_price = db.Column(db.Numeric(10, 2), nullable=False) # Preço total
def __init__(self, description, quantity, unit_price, invoice_id):
self.description = description
self.quantity = quantity
self.unit_price = unit_price
self.total_price = quantity * unit_price
self.invoice_id = invoice_id
def __repr__(self):
return f"<InvoiceItem {self.description} - {self.quantity} x {self.unit_price}>"