- Added new validations for pedimento regimes and compliance checks in common_validators.py. - Implemented missing date checks for consolidated pedimentos. - Introduced validation for shipped_by_id and manifest_number in invoice compliance. - Refactored create_validators.py by removing the file as it was no longer needed. - Updated update validators for exports and imports to use invoice_data instead of invoice. - Modified schemas.py to set default values for financial fields to avoid None values. - Created calculations.py to handle invoice calculations, including total increments and regime changes. - Improved layout responsiveness in various Svelte components for better user experience.
37 lines
1.6 KiB
Python
37 lines
1.6 KiB
Python
from sqlalchemy.orm import Session
|
|
from api.v1.modules.a76.invoices.models import InvoiceFinancials, InvoiceHeader, InvoiceLogistics
|
|
from core.exceptions import ErrorCollector
|
|
|
|
from .. import schemas
|
|
|
|
|
|
|
|
def apply_calculations(
|
|
invoice: schemas.InvoiceHeaderUpdate,
|
|
):
|
|
if invoice.invoice_type == "CR":
|
|
invoice.compliance_mx.is_regime_change = True
|
|
else:
|
|
invoice.compliance_mx.is_regime_change = False
|
|
|
|
increments_me = (invoice.financials.freight or 0) + (invoice.financials.insurance or 0) + (invoice.financials.packaging or 0) + (invoice.financials.other_increments or 0)
|
|
if invoice.financials.currency == "foreign":
|
|
invoice.financials.total_increments_me = increments_me
|
|
invoice.financials.total_increments_mn = invoice.financials.total_increments_me * invoice.financials.exchange_rate
|
|
invoice.financials.currency_type = "USD"
|
|
elif invoice.financials.currency == "local":
|
|
invoice.financials.total_increments_mn = increments_me
|
|
invoice.financials.total_increments_me = invoice.financials.total_increments_mn / invoice.financials.exchange_rate
|
|
invoice.financials.currency_type = "MXN"
|
|
elif invoice.financials.currency == "manual":
|
|
invoice.financials.total_increments_me = (increments_me)/invoice.financials.exchange_rate
|
|
invoice.financials.total_increments_mn = invoice.financials.total_increments_me * invoice.financials.exchange_rate
|
|
|
|
|
|
invoice.compliance_mx.is_pedimento_pending = False
|
|
if not invoice.compliance_mx.pedimento_id:
|
|
invoice.compliance_mx.is_pedimento_pending = True
|
|
|
|
|
|
|
|
|