facho/fe/form(Invoice): ident segun FAJ50,CAJ50,DAJ50.
FossilOrigin-Name: 66a185301ea1f32d9d837bf0811d35d5e8e15539486620b7b88d58b3824190a4
This commit is contained in:
parent
c44a49fccb
commit
8520d9ea29
@ -520,20 +520,36 @@ class Invoice:
|
||||
|
||||
self.invoice_issue = dtime
|
||||
|
||||
def _set_ident_prefix_automatic(self):
|
||||
if not self.invoice_ident_prefix:
|
||||
prefix = ''
|
||||
for idx, val in enumerate(self.invoice_ident):
|
||||
if val.isalpha():
|
||||
prefix += val
|
||||
else:
|
||||
break
|
||||
|
||||
if len(prefix) <= 4:
|
||||
self.invoice_ident_prefix = prefix
|
||||
else:
|
||||
raise ValueError('ident prefix failed to get, expected 0 to 4 chars')
|
||||
|
||||
def set_ident(self, ident: str):
|
||||
"""
|
||||
identificador de factura; prefijo + consecutivo
|
||||
"""
|
||||
self.invoice_ident = ident
|
||||
if not self.invoice_ident_prefix:
|
||||
self.invoice_ident_prefix = ident[0:4]
|
||||
self._set_ident_prefix_automatic()
|
||||
|
||||
def _check_ident_prefix(self, prefix):
|
||||
if len(prefix) != 4:
|
||||
raise ValueError('prefix must be 4 length')
|
||||
|
||||
def set_ident_prefix(self, prefix: str):
|
||||
"""
|
||||
prefijo de facturacion: ejemplo SETP
|
||||
"""
|
||||
if len(prefix) != 4:
|
||||
raise ValueError('prefix must be 4 length')
|
||||
self._check_ident_prefix(prefix)
|
||||
self.invoice_ident_prefix = prefix
|
||||
|
||||
def set_supplier(self, party: Party):
|
||||
@ -624,6 +640,14 @@ class CreditNote(Invoice):
|
||||
def _get_codelist_tipo_operacion(self):
|
||||
return codelist.TipoOperacionNC
|
||||
|
||||
def _check_ident_prefix(self, prefix):
|
||||
if len(prefix) != 6:
|
||||
raise ValueError('prefix must be 6 length')
|
||||
|
||||
def _set_ident_prefix_automatic(self):
|
||||
if not self.invoice_ident_prefix:
|
||||
self.invoice_ident_prefix = self.invoice_ident[0:6]
|
||||
|
||||
|
||||
class DebitNote(Invoice):
|
||||
def __init__(self, invoice_document_reference: BillingReference):
|
||||
@ -635,3 +659,12 @@ class DebitNote(Invoice):
|
||||
|
||||
def _get_codelist_tipo_operacion(self):
|
||||
return codelist.TipoOperacionND
|
||||
|
||||
def _check_ident_prefix(self, prefix):
|
||||
if len(prefix) != 6:
|
||||
raise ValueError('prefix must be 6 length')
|
||||
|
||||
def _set_ident_prefix_automatic(self):
|
||||
if not self.invoice_ident_prefix:
|
||||
self.invoice_ident_prefix = self.invoice_ident[0:6]
|
||||
|
||||
|
@ -174,13 +174,36 @@ def test_invoice_legalmonetary_with_taxes():
|
||||
assert inv.invoice_legal_monetary_total.charge_total_amount == form.Amount(0.0)
|
||||
assert inv.invoice_legal_monetary_total.payable_amount == form.Amount(100.0)
|
||||
|
||||
|
||||
def test_invoice_ident_prefix_automatic_invalid():
|
||||
inv = form.NationalSalesInvoice()
|
||||
with pytest.raises(ValueError):
|
||||
inv.set_ident('SETPQJQJ1234567')
|
||||
|
||||
def test_invoice_ident_prefix_automatic():
|
||||
inv = form.NationalSalesInvoice()
|
||||
inv.set_ident('SETP1234567')
|
||||
assert inv.invoice_ident_prefix == 'SETP'
|
||||
inv = form.NationalSalesInvoice()
|
||||
inv.set_ident('SET1234567')
|
||||
assert inv.invoice_ident_prefix == 'SET'
|
||||
inv = form.NationalSalesInvoice()
|
||||
inv.set_ident('SE1234567')
|
||||
assert inv.invoice_ident_prefix == 'SE'
|
||||
inv = form.NationalSalesInvoice()
|
||||
inv.set_ident('S1234567')
|
||||
assert inv.invoice_ident_prefix == 'S'
|
||||
inv = form.NationalSalesInvoice()
|
||||
inv.set_ident('1234567')
|
||||
assert inv.invoice_ident_prefix == ''
|
||||
|
||||
def test_invoice_ident_prefix_manual():
|
||||
inv = form.NationalSalesInvoice()
|
||||
inv.set_ident('SETP1234567')
|
||||
inv.set_ident_prefix('SETA')
|
||||
assert inv.invoice_ident_prefix == 'SETA'
|
||||
|
||||
def test_invoice_ident_prefix_automatic_debit():
|
||||
inv = form.DebitNote(form.BillingReference('','',''))
|
||||
inv.set_ident('ABCDEF1234567')
|
||||
assert inv.invoice_ident_prefix == 'ABCDEF'
|
||||
|
Loading…
Reference in New Issue
Block a user