facho/fe/form: InvoiceLine fix taxable amount
FossilOrigin-Name: 26cc98a74588647ec409716c1954d37baa1951b41605a4f9ffc624a1bf090269
This commit is contained in:
parent
516525be2b
commit
38a0a72e2b
@ -110,7 +110,7 @@ class Amount:
|
||||
return formatter % self.float()
|
||||
|
||||
def float(self):
|
||||
return round(self.amount, DECIMAL_PRECISION)
|
||||
return float(round(self.amount, DECIMAL_PRECISION))
|
||||
|
||||
|
||||
class Quantity:
|
||||
@ -279,11 +279,9 @@ class TaxSubTotal:
|
||||
tax_scheme_name: str = 'IVA'
|
||||
|
||||
tax_amount: Amount = Amount(0.0)
|
||||
taxable_amount: Amount = Amount(0.0)
|
||||
|
||||
def calculate(self, invline):
|
||||
self.tax_amount = invline.total_amount * Amount(self.percent / 100)
|
||||
self.taxable_amount = invline.total_amount
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -293,10 +291,11 @@ class TaxTotal:
|
||||
taxable_amount: Amount = Amount(0.0)
|
||||
|
||||
def calculate(self, invline):
|
||||
self.taxable_amount = invline.total_amount
|
||||
|
||||
for subtax in self.subtotals:
|
||||
subtax.calculate(invline)
|
||||
self.tax_amount += subtax.tax_amount
|
||||
self.taxable_amount += subtax.taxable_amount
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -409,6 +408,14 @@ class LegalMonetaryTotal:
|
||||
payable_amount: Amount = Amount(0.0)
|
||||
prepaid_amount: Amount = Amount(0.0)
|
||||
|
||||
def calculate(self):
|
||||
#DIAN 1.7.-2020: FAU14
|
||||
self.payable_amount = \
|
||||
self.tax_inclusive_amount \
|
||||
+ self.allowance_total_amount \
|
||||
+ self.charge_total_amount \
|
||||
- self.prepaid_amount
|
||||
|
||||
|
||||
@dataclass
|
||||
class AllowanceChargeReason:
|
||||
@ -556,12 +563,7 @@ class Invoice:
|
||||
.sum()
|
||||
|
||||
#DIAN 1.7.-2020: FAU14
|
||||
self.invoice_legal_monetary_total.payable_amount = \
|
||||
self.invoice_legal_monetary_total.tax_inclusive_amount \
|
||||
+ self.invoice_legal_monetary_total.allowance_total_amount \
|
||||
+ self.invoice_legal_monetary_total.charge_total_amount \
|
||||
- self.invoice_legal_monetary_total.prepaid_amount
|
||||
|
||||
self.invoice_legal_monetary_total.calculate()
|
||||
|
||||
def calculate(self):
|
||||
for invline in self.invoice_lines:
|
||||
|
@ -435,9 +435,10 @@ class DIANInvoiceXML(fe.FeXML):
|
||||
total_tax_amount = Amount(0.0)
|
||||
|
||||
for invoice_line in invoice.invoice_lines:
|
||||
|
||||
for subtotal in invoice_line.tax.subtotals:
|
||||
tax_amount_for[subtotal.tax_scheme_ident]['tax_amount'] += subtotal.tax_amount
|
||||
tax_amount_for[subtotal.tax_scheme_ident]['taxable_amount'] += subtotal.taxable_amount
|
||||
tax_amount_for[subtotal.tax_scheme_ident]['taxable_amount'] = invoice_line.taxable_amount
|
||||
total_tax_amount += subtotal.tax_amount
|
||||
# MACHETE ojo InvoiceLine.tax pasar a Invoice
|
||||
percent_for[subtotal.tax_scheme_ident] = subtotal.percent
|
||||
@ -505,10 +506,12 @@ class DIANInvoiceXML(fe.FeXML):
|
||||
'./cac:TaxTotal/cbc:TaxAmount',
|
||||
invoice_line.tax_amount)
|
||||
|
||||
#DIAN 1.7.-2020: FAX05
|
||||
fexml.set_element_amount_for(line,
|
||||
'./cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount',
|
||||
invoice_line.taxable_amount)
|
||||
for subtotal in invoice_line.tax.subtotals:
|
||||
fexml.set_element_amount_for(line,
|
||||
'./cac:TaxTotal/cac:TaxSubtotal/cbc:TaxableAmount',
|
||||
subtotal.taxable_amount)
|
||||
|
||||
line.set_element('./cac:TaxTotal/cac:TaxSubtotal/cbc:TaxAmount', subtotal.tax_amount, currencyID='COP')
|
||||
line.set_element('./cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cbc:Percent', subtotal.percent)
|
||||
line.set_element('./cac:TaxTotal/cac:TaxSubtotal/cac:TaxCategory/cac:TaxScheme/cbc:ID', subtotal.tax_scheme_ident)
|
||||
|
@ -132,3 +132,45 @@ def test_valid_tipo_operacion_nota_credito():
|
||||
)
|
||||
inv = form.CreditNote(reference)
|
||||
inv.set_operation_type('20')
|
||||
|
||||
|
||||
def test_quantity():
|
||||
quantity1 = form.Quantity(10, '94')
|
||||
assert quantity1 * form.Amount(3) == form.Amount(30)
|
||||
|
||||
def test_invoice_line_quantity_without_taxes():
|
||||
line = form.InvoiceLine(
|
||||
quantity = form.Quantity(10, '94'),
|
||||
description = '',
|
||||
item = form.StandardItem('test', 9999),
|
||||
price = form.Price(
|
||||
amount = form.Amount(30.00),
|
||||
type_code = '01',
|
||||
type = 'x'
|
||||
),
|
||||
tax = form.TaxTotal(subtotals=[]))
|
||||
line.calculate()
|
||||
assert line.total_amount == form.Amount(300)
|
||||
assert line.tax_amount == form.Amount(0)
|
||||
|
||||
def test_invoice_legalmonetary_with_taxes():
|
||||
inv = form.NationalSalesInvoice()
|
||||
inv.add_invoice_line(form.InvoiceLine(
|
||||
quantity = form.Quantity(1, '94'),
|
||||
description = 'producto facho',
|
||||
item = form.StandardItem(9999),
|
||||
price = form.Price(
|
||||
amount = form.Amount(100.0),
|
||||
type_code = '01',
|
||||
type = 'x'
|
||||
),
|
||||
tax = form.TaxTotal(subtotals=[])
|
||||
))
|
||||
inv.calculate()
|
||||
|
||||
assert inv.invoice_legal_monetary_total.line_extension_amount == form.Amount(100.0)
|
||||
assert inv.invoice_legal_monetary_total.tax_exclusive_amount == form.Amount(100.0)
|
||||
assert inv.invoice_legal_monetary_total.tax_inclusive_amount == form.Amount(100.0)
|
||||
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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user