Overview
The Purchase Service (jea-compra) manages all purchase orders from suppliers, providing robust procurement capabilities with automatic inventory updates and resilient inter-service communication.
Key Features
Supplier Integration
Links purchases to supplier records for complete vendor management
Multi-Service Communication
Uses Feign clients to communicate with 4 different microservices
Circuit Breaker
Resilience4j circuit breakers with fallback methods for fault tolerance
Automatic Calculations
Same tax calculation logic as sales for consistency
Inventory Updates
Automatically increases stock quantities on purchase completion
Document Generation
Auto-generates unique purchase order numbers
Purchase Entity Structure
Purchase orders contain comprehensive information about procurement transactions:Feign Client Integration
The Purchase Service demonstrates advanced inter-service communication using Spring Cloud OpenFeign:Product Service Integration
Circuit breakers prevent cascade failures. If a dependent service is unavailable, the fallback method returns a safe default response, allowing the system to continue operating gracefully.
Connected Services
The Purchase Service communicates with multiple microservices:Catalog Service
Retrieves product information and updates inventory quantities after purchase completion
Circuit Breaker Pattern
The service implements Resilience4j circuit breakers for fault tolerance:Benefits
- Prevents Cascade Failures - Stops failure propagation across services
- Graceful Degradation - Returns fallback responses when services are unavailable
- System Stability - Maintains operation even when dependencies fail
- Fast Failure - Quickly returns errors instead of waiting for timeouts
Configuration
Circuit breakers are configured per Feign client with:- Failure rate thresholds
- Timeout settings
- Fallback methods
- Recovery time windows
Purchase Order Process
Create Purchase Order
Client submits purchase order with supplier ID, payment method, and line items
Available Endpoints
The Purchase Service provides comprehensive purchase order management:| Method | Endpoint | Description |
|---|---|---|
| POST | /compra | Create new purchase order |
| GET | /compra | List all purchase orders |
| GET | /compra/{id} | Get purchase order by ID |
| PUT | /compra/{id} | Update purchase order |
| DELETE | /compra/{id} | Delete purchase order |
| GET | /compra/proveedor/{id} | Get purchases by supplier |
| GET | /compra/fecha | Search by date range |
Automatic Inventory Updates
When a purchase order is completed, the system automatically updates inventory:Tax Calculations
Purchase orders use the same IGV (18% VAT) calculation logic as sales:Supplier Management Integration
Purchase orders are tightly integrated with supplier records:- Supplier Validation - Verifies supplier exists before creating purchase order
- Supplier History - Track all purchases from each supplier
- Payment Terms - Associate purchase orders with supplier payment terms
- Performance Tracking - Monitor supplier performance metrics
Payment Processing
Purchase orders support various payment methods:- Cash (Efectivo)
- Credit Card (Tarjeta de crédito)
- Bank Transfer (Transferencia bancaria)
- Check (Cheque)
- Mobile Payments (Yape, Plin, BIM)
Best Practices
Supplier Validation
Supplier Validation
Always validate supplier existence and status before creating purchase orders. Inactive suppliers should not be used for new orders.
Product Verification
Product Verification
Verify that all products in the purchase order exist in the catalog and are active before submission.
Quantity Accuracy
Quantity Accuracy
Double-check quantities before submitting purchase orders. Once completed, inventory updates are automatic and should match received goods.
Cost Tracking
Cost Tracking
Keep purchase costs updated in the product catalog to ensure accurate profit margin calculations.
Circuit Breaker Monitoring
Circuit Breaker Monitoring
Monitor circuit breaker status to identify dependent service issues early. Implement alerts for circuit breaker trips.
Error Handling
The Purchase Service implements comprehensive error handling:- Service Unavailability - Circuit breakers provide fallback responses
- Invalid Suppliers - Validation errors are returned with clear messages
- Insufficient Product Data - Missing product information triggers appropriate errors
- Transaction Failures - Rollback mechanisms ensure data consistency
Next Steps
API Reference
Detailed purchase API documentation
Supplier Management
Manage supplier relationships
Inventory Control
Monitor inventory levels
Payment Processing
Configure payment methods