Validate Dominican tax posting with real invoices
Add transactional invoice tests that create a Dominican chart, post customer and supplier invoices with ITBIS 18%, and verify the generated tax move lines use the expected Dominican tax accounts and debit/credit signs.
This commit is contained in:
@@ -15,6 +15,73 @@ class AccountInvoiceDoTestCase(ModuleTestCase):
|
||||
"Test Account Invoice Do module"
|
||||
module = 'account_invoice_do'
|
||||
|
||||
def _prepare_invoice_company(self, chart='account_do.do_account_root'):
|
||||
pool = Pool()
|
||||
FiscalYear = pool.get('account.fiscalyear')
|
||||
InvoiceSequence = pool.get('account.fiscalyear.invoice_sequence')
|
||||
PaymentTerm = pool.get('account.invoice.payment_term')
|
||||
Sequence = pool.get('ir.sequence.strict')
|
||||
SequenceType = pool.get('ir.sequence.type')
|
||||
|
||||
today = datetime.date.today()
|
||||
company = create_company()
|
||||
create_chart(company, chart=chart)
|
||||
fiscalyear = get_fiscalyear(company, today=today)
|
||||
sequence_type, = SequenceType.search([
|
||||
('name', '=', 'Invoice'),
|
||||
], limit=1)
|
||||
invoice_sequence, = Sequence.create([{
|
||||
'name': fiscalyear.name,
|
||||
'sequence_type': sequence_type.id,
|
||||
'company': company.id,
|
||||
}])
|
||||
fiscalyear.invoice_sequences = [InvoiceSequence(
|
||||
company=company,
|
||||
in_invoice_sequence=invoice_sequence,
|
||||
in_credit_note_sequence=invoice_sequence,
|
||||
out_invoice_sequence=invoice_sequence,
|
||||
out_credit_note_sequence=invoice_sequence)]
|
||||
fiscalyear.save()
|
||||
FiscalYear.create_period([fiscalyear])
|
||||
term, = PaymentTerm.create([{
|
||||
'name': 'Contado',
|
||||
'lines': [('create', [{'type': 'remainder'}])],
|
||||
}])
|
||||
return company, term, today
|
||||
|
||||
def _account(self, company, code):
|
||||
Account = Pool().get('account.account')
|
||||
account, = Account.search([
|
||||
('company', '=', company.id),
|
||||
('code', '=', code),
|
||||
('closed', '!=', True),
|
||||
], limit=1)
|
||||
return account
|
||||
|
||||
def _tax(self, company, description):
|
||||
Tax = Pool().get('account.tax')
|
||||
tax, = Tax.search([
|
||||
('company', '=', company.id),
|
||||
('description', '=', description),
|
||||
], limit=1)
|
||||
return tax
|
||||
|
||||
def _party(self, name):
|
||||
Party = Pool().get('party.party')
|
||||
party, = Party.create([{
|
||||
'name': name,
|
||||
'addresses': [('create', [{}])],
|
||||
}])
|
||||
return party
|
||||
|
||||
def _invoice_tax_line(self, invoice, account_code):
|
||||
lines = [
|
||||
line for line in invoice.move.lines
|
||||
if line.account.code == account_code
|
||||
]
|
||||
self.assertEqual(len(lines), 1)
|
||||
return lines[0]
|
||||
|
||||
@with_transaction()
|
||||
def test_customer_invoice_without_product_posts_and_computes_do_fields(self):
|
||||
'Post customer invoice and compute Dominican invoice helper fields'
|
||||
@@ -101,6 +168,84 @@ class AccountInvoiceDoTestCase(ModuleTestCase):
|
||||
self.assertEqual(line.itbis_invoiced_line, Decimal('0.00'))
|
||||
self.assertEqual(line.line_total, Decimal('300.00'))
|
||||
|
||||
@with_transaction()
|
||||
def test_dominican_real_invoices_post_taxes_to_expected_accounts(self):
|
||||
'Post Dominican invoices and verify tax accounts and amounts'
|
||||
pool = Pool()
|
||||
Invoice = pool.get('account.invoice')
|
||||
Journal = pool.get('account.journal')
|
||||
|
||||
company, term, today = self._prepare_invoice_company()
|
||||
customer = self._party('Cliente fiscal dominicano')
|
||||
supplier = self._party('Proveedor fiscal dominicano')
|
||||
receivable = self._account(company, '110201')
|
||||
payable = self._account(company, '210101')
|
||||
revenue = self._account(company, '4102')
|
||||
expense = self._account(company, '6103')
|
||||
sale_tax = self._tax(company, 'ITBIS 18% Ventas')
|
||||
purchase_tax = self._tax(company, 'ITBIS 18% Compras')
|
||||
revenue_journal, = Journal.search([('type', '=', 'revenue')], limit=1)
|
||||
expense_journal, = Journal.search([('type', '=', 'expense')], limit=1)
|
||||
|
||||
with set_company(company):
|
||||
out_invoice, = Invoice.create([{
|
||||
'type': 'out',
|
||||
'company': company.id,
|
||||
'party': customer.id,
|
||||
'invoice_address': customer.addresses[0].id,
|
||||
'account': receivable.id,
|
||||
'currency': company.currency.id,
|
||||
'invoice_date': today,
|
||||
'accounting_date': today,
|
||||
'journal': revenue_journal.id,
|
||||
'payment_term': term.id,
|
||||
'lines': [('create', [{
|
||||
'type': 'line',
|
||||
'description': 'Servicio gravado RD',
|
||||
'quantity': 1,
|
||||
'unit_price': Decimal('1000.00'),
|
||||
'account': revenue.id,
|
||||
'taxes': [('add', [sale_tax.id])],
|
||||
}])],
|
||||
}])
|
||||
Invoice.update_taxes([out_invoice])
|
||||
Invoice.post([out_invoice])
|
||||
out_invoice = Invoice(out_invoice.id)
|
||||
|
||||
in_invoice, = Invoice.create([{
|
||||
'type': 'in',
|
||||
'company': company.id,
|
||||
'party': supplier.id,
|
||||
'invoice_address': supplier.addresses[0].id,
|
||||
'account': payable.id,
|
||||
'currency': company.currency.id,
|
||||
'invoice_date': today,
|
||||
'accounting_date': today,
|
||||
'journal': expense_journal.id,
|
||||
'payment_term': term.id,
|
||||
'lines': [('create', [{
|
||||
'type': 'line',
|
||||
'description': 'Compra gravada RD',
|
||||
'quantity': 1,
|
||||
'unit_price': Decimal('1000.00'),
|
||||
'account': expense.id,
|
||||
'taxes': [('add', [purchase_tax.id])],
|
||||
}])],
|
||||
}])
|
||||
Invoice.update_taxes([in_invoice])
|
||||
Invoice.post([in_invoice])
|
||||
in_invoice = Invoice(in_invoice.id)
|
||||
|
||||
self.assertEqual(out_invoice.tax_amount, Decimal('180.00'))
|
||||
out_tax_line = self._invoice_tax_line(out_invoice, '21020101')
|
||||
self.assertEqual(out_tax_line.debit, Decimal('0.00'))
|
||||
self.assertEqual(out_tax_line.credit, Decimal('180.00'))
|
||||
|
||||
self.assertEqual(in_invoice.tax_amount, Decimal('180.00'))
|
||||
in_tax_line = self._invoice_tax_line(in_invoice, '11040101')
|
||||
self.assertEqual(in_tax_line.debit, Decimal('180.00'))
|
||||
self.assertEqual(in_tax_line.credit, Decimal('0.00'))
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
|
||||
|
||||
Reference in New Issue
Block a user