FEAT: correccion IVA y Boletas, filtro categorias, vista previa evidencia y proveedor de servicios

This commit is contained in:
Nachou-u
2026-09-09 14:35:10 -03:00
parent acb3a1eaad
commit 522d5337f4
8 changed files with 112 additions and 13 deletions
+12 -5
View File
@@ -137,6 +137,7 @@ class ExpenseForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['project'].queryset = Project.objects.filter(parent__parent__isnull=False)
self.fields['category'].queryset = Category.objects.filter(children__isnull=True)
if self.instance and self.instance.pk:
try:
vlog = self.instance.vehicle_log
@@ -218,10 +219,11 @@ class ExpenseForm(forms.ModelForm):
raise forms.ValidationError("Si desea registrar un nuevo proveedor, debe ingresar tanto el RUT como la Razón Social.")
# Recalculate taxes via SIIService
amount = cleaned_data.get('amount_clp')
amount_clp = cleaned_data.get('amount_clp')
tax_type = cleaned_data.get('tax_type')
if amount and tax_type:
tax_res = SIIService.calculate_taxes(amount, tax_type)
if amount_clp and amount_clp > 0 and tax_type:
tax_res = SIIService.calculate_taxes(amount_clp, tax_type)
cleaned_data['amount_clp'] = tax_res['net_amount']
cleaned_data['tax_amount_clp'] = tax_res['tax_amount']
cleaned_data['total_amount_clp'] = tax_res['total_amount']
@@ -229,7 +231,7 @@ class ExpenseForm(forms.ModelForm):
vendor = cleaned_data.get('vendor')
doc_num = cleaned_data.get('document_number')
date_val = cleaned_data.get('date')
if amount and (vendor or doc_num):
if amount_clp and (vendor or doc_num):
duplicates = SIIService.check_duplicate_expense(
expense_model=Expense,
vendor_id=vendor.id if vendor else None,
@@ -352,6 +354,10 @@ class ProjectForm(forms.ModelForm):
'payment_method': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Ej: 50% Anticipo / 50% Hito Final'}),
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['category'].queryset = Category.objects.filter(children__isnull=True)
class ProjectPhaseForm(forms.ModelForm):
due_date = forms.DateField(widget=forms.DateInput(attrs={'type': 'date', 'class': 'form-control'}), required=False, label="Fecha Pactada")
@@ -381,10 +387,11 @@ class CategoryForm(forms.ModelForm):
class VendorForm(forms.ModelForm):
class Meta:
model = Vendor
fields = ['rut', 'name', 'business_line', 'bank', 'account_type', 'account_number', 'email', 'payment_terms']
fields = ['rut', 'name', 'provider_type', 'business_line', 'bank', 'account_type', 'account_number', 'email', 'payment_terms']
widgets = {
'rut': forms.TextInput(attrs={'class': 'form-control', 'required': 'required', 'pattern': '^[0-9]+-[0-9kK]$', 'title': 'Formato válido: 12345678-9'}),
'name': forms.TextInput(attrs={'class': 'form-control', 'required': 'required'}),
'provider_type': forms.Select(attrs={'class': 'form-control'}),
'email': forms.EmailInput(attrs={'class': 'form-control'}),
}