Skip to content
Snippets Groups Projects
Commit 9400a2f5e868 authored by Houzefa Abbasbhay's avatar Houzefa Abbasbhay :slight_smile:
Browse files

Tests: Check invoice date propagation to acc docs

parent 291273d1524f
No related branches found
No related tags found
No related merge requests found
# flake8: noqa
from . import test_account_period
##############################################################################
#
# Accounting periods, for Odoo
# Copyright (C) 2018 XCG Consulting <http://odoo.consulting>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import odoo
from .util.odoo_tests import TestBase
from .util.singleton import Singleton
from .util.uuidgen import genUuid
class TestMemory(object):
"""Keep records in memory across tests."""
__metaclass__ = Singleton
@odoo.tests.common.at_install(False)
@odoo.tests.common.post_install(True)
class Test(TestBase):
"""Test fiscal years & accounting periods.
These tests assume an Odoo database with demo data.
"""
def setUp(self):
super(Test, self).setUp()
self.memory = TestMemory()
def test_0000_create_accounting_account(self):
"""Create accounting accounts for use in further tests.
"""
acctype, = self.createAndTest('account.account.type', [{
'name': genUuid(), 'type': 'other',
}])
self.memory.account, = self.createAndTest(
'account.account',
[{
'code': genUuid(max_chars=4),
'internal_type': 'other',
'name': genUuid(max_chars=8),
'reconcile': True,
'user_type_id': acctype.id,
}],
)
def test_0001_create_partners(self):
"""Create simple partners, that will be used in other tests.
"""
self.memory.partner, = self.createAndTest(
'res.partner',
[{
'customer': True,
'name': genUuid(),
}],
)
def test_0002_create_products(self):
"""Create products for use in further tests.
"""
def createProduct(values):
"""Create a product template and return its product variant."""
ptemplate, = self.createAndTest('product.template', [values])
product = ptemplate.product_variant_ids
self.assertEqual(len(product), 1)
return product
self.memory.product = createProduct({
'name': genUuid(),
'property_account_expense_id': self.memory.account.id,
'property_account_income_id': self.memory.account.id,
'type': 'service',
})
def test_0100_invoice_dates(self):
"""Check invoice date propagation to accounting documents.
"""
# Find the period around today. We should have one in demo data.
today = odoo.fields.Date.today()
period_today = self.env['account.period'].search([
('date_start', '<=', today),
('date_stop', '>=', today),
])
self.assertEqual(len(period_today), 1)
# Control: Default dates & period around today.
invoice = self._makeInvoice()
self._validateInvoice(invoice)
accdoc = invoice.move_id
self.assertEqual(accdoc.date, today)
self.assertEqual(accdoc.transaction_date, today)
self.assertEqual(accdoc.period_id.id, period_today.id)
# Force a date on the invoice; check its propagation.
invoice = self._makeInvoice()
invoice.date_invoice = '2017-01-15'
self._validateInvoice(invoice)
accdoc = invoice.move_id
self.assertEqual(accdoc.date, today)
self.assertEqual(accdoc.transaction_date, '2017-01-15')
self.assertEqual(accdoc.period_id.id, period_today.id)
def _makeInvoice(self):
"""Create an invoice and return it.
:return: The invoice.
:rtype: Odoo "account.invoice" record set.
"""
# Create the invoice first and add lines afterwards.
invoice, = self.createAndTest(
'account.invoice',
[{
'partner_id': self.memory.partner.id,
'type': 'out_invoice',
}],
)
self.createAndTest(
'account.invoice.line',
[
{
'account_id': self.memory.account.id,
'invoice_id': invoice.id,
'name': genUuid(),
'price_unit': 42.0,
'product_id': self.memory.product.id,
},
],
)
return invoice
def _validateInvoice(self, invoice):
"""Validate the specified invoice.
:type invoice: Odoo "account.invoice" record set.
"""
self.assertEqual(invoice.state, 'draft')
invoice.action_invoice_open()
self.assertEqual(invoice.state, 'open')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment