Overview
The tables module manages restaurant tables, customer orders, order items, and invoice generation.Mesa
Restaurant table model with state management.Primary key for the table. Auto-generated by Django.
Table name or identifier.
max_length: 50
Table description or notes.
blank: True
Current state of the table.
max_length: 20choices: ESTADO_CHOICESdefault: ‘disponible’
Estado Choices
Available table states:
| Value | Display |
|---|---|
disponible | Disponible |
ocupada | Ocupada |
reservada | Reservada |
fuera de servicio | Fuera de servicio |
Related Fields
- pedidos: Reverse relation to Pedido (related_name=‘pedidos’)
Pedido
Customer order model tracking items ordered at a table.Primary key for the order. Auto-generated by Django.
Reference to the table where the order was placed.
to: Mesaon_delete: SET_NULLrelated_name: ‘pedidos’null: Trueblank: True
Users associated with this order.
to: User (Django auth)related_name: ‘pedidos_asociados’blank: True
Timestamp when the order was created.
auto_now_add: True
Timestamp of last update.
auto_now: True
Current state of the order.
max_length: 20choices: ESTADO_CHOICESdefault: ‘en_proceso’
Estado Choices
Available order states:
| Value | Display |
|---|---|
en_proceso | En Proceso |
facturado | Facturado |
cancelado | Cancelado |
Methods
Related Fields
- items: Reverse relation to PedidoItem (related_name=‘items’)
- factura: Reverse OneToOne relation to Factura (related_name=‘factura’)
PedidoItem
Individual item within an order.Primary key for the order item. Auto-generated by Django.
Reference to the parent order.
to: Pedidoon_delete: CASCADErelated_name: ‘items’
Reference to the product being ordered.
to: Producto (from products app)on_delete: PROTECT
Quantity of the product ordered.
default: 1- Must be a positive integer
Unit price at the time of order.
max_digits: 10decimal_places: 2default: 0
Methods
The
precio_unitario stores the price at the time of order, preserving historical pricing even if the product’s current price changes.Factura
Invoice model for completed orders.Primary key for the invoice. Auto-generated by Django.
Reference to the order being invoiced.
to: Pedidoon_delete: PROTECTrelated_name: ‘factura’- Each order can have only one invoice
Invoice number.
max_length: 20unique: True- Auto-generated with 8-digit zero-padded format
Invoice date and time.
default: timezone.now
Total invoice amount.
max_digits: 10decimal_places: 2default: 0- Auto-calculated from order total if not provided
Methods
Invoice numbers are sequential and formatted as 8-digit strings (e.g., “00000001”, “00000002”).
