213 lines
9.2 KiB
Python
213 lines
9.2 KiB
Python
import datetime
|
|
from decimal import Decimal
|
|
|
|
from trytond.modules.account.tests.test_module import (
|
|
create_chart, get_fiscalyear)
|
|
from trytond.modules.company.tests import create_company, set_company
|
|
from trytond.pool import Pool
|
|
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
|
|
|
|
|
class AccountInvoiceDoTestCase(ModuleTestCase):
|
|
"Test Account Invoice Do module"
|
|
module = 'account_invoice_do'
|
|
|
|
def _prepare_invoice_company(
|
|
self, chart='account_do.do_account_root_en'):
|
|
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_computes_do_fields(self):
|
|
'Post customer invoice and compute Dominican invoice helper fields'
|
|
pool = Pool()
|
|
Invoice = pool.get('account.invoice')
|
|
Journal = pool.get('account.journal')
|
|
|
|
company, term, today = self._prepare_invoice_company()
|
|
receivable = self._account(company, '110201')
|
|
revenue = self._account(company, '4102')
|
|
journal, = Journal.search([('type', '=', 'revenue')], limit=1)
|
|
party = self._party('Cliente local')
|
|
|
|
with set_company(company):
|
|
invoice, = Invoice.create([{
|
|
'type': 'out',
|
|
'company': company.id,
|
|
'party': party.id,
|
|
'invoice_address': party.addresses[0].id,
|
|
'account': receivable.id,
|
|
'currency': company.currency.id,
|
|
'invoice_date': today,
|
|
'accounting_date': today,
|
|
'journal': journal.id,
|
|
'payment_term': term.id,
|
|
'lines': [('create', [{
|
|
'type': 'line',
|
|
'description': 'Servicio local',
|
|
'quantity': 2,
|
|
'unit_price': Decimal('150.00'),
|
|
'account': revenue.id,
|
|
}])],
|
|
}])
|
|
Invoice.post([invoice])
|
|
invoice = Invoice(invoice.id)
|
|
|
|
self.assertEqual(invoice.state, 'posted')
|
|
self.assertEqual(invoice.untaxed_amount, Decimal('300.00'))
|
|
self.assertEqual(invoice.total_amount, Decimal('300.00'))
|
|
line, = invoice.lines
|
|
self.assertEqual(line.product_type, '')
|
|
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% Sales')
|
|
purchase_tax = self._tax(company, 'ITBIS 18% Purchases')
|
|
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_line, = out_invoice.lines
|
|
self.assertEqual(out_line.itbis_invoiced_line, Decimal('180.00'))
|
|
self.assertEqual(out_line.line_total, Decimal('1180.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_line, = in_invoice.lines
|
|
self.assertEqual(in_line.itbis_invoiced_line, Decimal('180.00'))
|
|
self.assertEqual(in_line.line_total, Decimal('1180.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
|