diff --git a/facho/fe/data/dian/codelist/__init__.py b/facho/fe/data/dian/codelist/__init__.py index c9a5f38..4c04c7f 100644 --- a/facho/fe/data/dian/codelist/__init__.py +++ b/facho/fe/data/dian/codelist/__init__.py @@ -89,6 +89,8 @@ TipoImpuesto = CodeList(path_for_codelist('TipoImpuesto-2.1.gc'), 'code', 'name' CodigoPrecioReferencia = CodeList(path_for_codelist('CodigoPrecioReferencia-2.1.gc'), 'code', 'name') MediosPago = CodeList(path_for_codelist('MediosPago-2.1.gc'), 'code', 'name') RegimenFiscal = CodeList(path_for_codelist('RegimenFiscal-2.1.custom.gc'), 'code', 'name') +TipoOperacionNC = CodeList(path_for_codelist('TipoOperacionNC-2.1.gc'), 'code', 'name') +TipoOperacionND = CodeList(path_for_codelist('TipoOperacionND-2.1 - copia.gc'), 'code', 'name') TipoOperacionF = CodeList(path_for_codelist('TipoOperacionF-2.1.gc'), 'code', 'name')\ .update(CodeList(path_for_codelist('TipoOperacionF-2.1.custom.gc'), 'code', 'name')) Municipio = CodeList(path_for_codelist('Municipio-2.1.gc'), 'code', 'name') diff --git a/facho/fe/form.py b/facho/fe/form.py index 05ed2ef..b1dec46 100644 --- a/facho/fe/form.py +++ b/facho/fe/form.py @@ -436,8 +436,11 @@ class Invoice: def set_payment_mean(self, payment_mean: PaymentMean): self.invoice_payment_mean = payment_mean + def _get_codelist_tipo_operacion(self): + return codelist.TipoOperacionF + def set_operation_type(self, operation): - if operation not in codelist.TipoOperacionF: + if operation not in self._get_codelist_tipo_operacion(): raise ValueError("operation not found") self.invoice_operation_type = operation @@ -514,6 +517,9 @@ class CreditNote(Invoice): raise TypeError('invoice_document_reference invalid type') self.invoice_billing_reference = invoice_document_reference + def _get_codelist_tipo_operacion(self): + return codelist.TipoOperacionNC + class DebitNote(Invoice): def __init__(self, invoice_document_reference: BillingReference): @@ -522,3 +528,6 @@ class DebitNote(Invoice): if not isinstance(invoice_document_reference, BillingReference): raise TypeError('invoice_document_reference invalid type') self.invoice_billing_reference = invoice_document_reference + + def _get_codelist_tipo_operacion(self): + return codelist.TipoOperacionND diff --git a/tests/test_fe_form.py b/tests/test_fe_form.py index 179a740..5bd730a 100644 --- a/tests/test_fe_form.py +++ b/tests/test_fe_form.py @@ -20,7 +20,7 @@ def simple_debit_note_without_lines(): inv.set_period(datetime.now(), datetime.now()) inv.set_issue(datetime.now()) inv.set_ident('ABC123') - inv.set_operation_type('10') + inv.set_operation_type('30') inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234')) inv.set_supplier(form.Party( name = 'facho-supplier', @@ -52,7 +52,7 @@ def simple_credit_note_without_lines(): inv.set_period(datetime.now(), datetime.now()) inv.set_issue(datetime.now()) inv.set_ident('ABC123') - inv.set_operation_type('10') + inv.set_operation_type('20') inv.set_payment_mean(form.PaymentMean(form.PaymentMean.DEBIT, '41', datetime.now(), '1234')) inv.set_supplier(form.Party( name = 'facho-supplier', diff --git a/tests/test_form.py b/tests/test_form.py index 51a9c21..08b5aed 100644 --- a/tests/test_form.py +++ b/tests/test_form.py @@ -93,3 +93,42 @@ def test_FAU14(): wants = form.Amount(119.0 + 19.0 - 50.0) assert inv.invoice_legal_monetary_total.payable_amount == wants, "got %s want %s" % (inv.invoice_legal_monetary_total.payable_amount, wants) + + +def test_invalid_tipo_operacion_nota_debito(): + reference = form.InvoiceDocumentReference( + ident = '11111', + uuid = '21312312', + date = '2020-05-05' + ) + inv = form.DebitNote(reference) + with pytest.raises(ValueError): + inv.set_operation_type(22) + +def test_valid_tipo_operacion_nota_debito(): + reference = form.InvoiceDocumentReference( + ident = '11111', + uuid = '21312312', + date = '2020-05-05' + ) + inv = form.DebitNote(reference) + inv.set_operation_type('30') + +def test_invalid_tipo_operacion_nota_credito(): + reference = form.InvoiceDocumentReference( + ident = '11111', + uuid = '21312312', + date = '2020-05-05' + ) + inv = form.DebitNote(reference) + with pytest.raises(ValueError): + inv.set_operation_type('990') + +def test_valid_tipo_operacion_nota_credito(): + reference = form.InvoiceDocumentReference( + ident = '11111', + uuid = '21312312', + date = '2020-05-05' + ) + inv = form.CreditNote(reference) + inv.set_operation_type('20')