summaryrefslogtreecommitdiff
path: root/addons/account/tests
diff options
context:
space:
mode:
authorOdoo's Mergebot <xmo+roboto@odoo.com>2019-11-07 08:37:12 +0100
committerGitHub <noreply@github.com>2019-11-07 08:37:12 +0100
commitcfc65bd1b72b6fb7833f67fa580fa9fdac28b1f5 (patch)
treec1aa353aa7e29d0ed918911dbdce456ed957b72e /addons/account/tests
parenta3f5afdd53f5f0d8d76427fe14dce6f02e064a75 (diff)
parentbc8fe668495a1d080ff883d5e61e961a128669de (diff)
[MERGE] various: Make the test suite demo data independant
Purpose ======= This is the first huge step to improve the test suite in several ways: - Make them demo data independent, allowing to modify the demo data without having to adapt the tests depending on it. It also allows to have a beautiful + convenient demo dataset to make a demonstration, and to configure complex data in the tests to manage the corner cases. - Improve the test performances by converting them into SavepointCase. Each test will be rollbacked to it's initial state, after the setUpClass call. That way the different data are not re-created at each test for nothing. - Introduce several test classes in base/tests/common.py to launch a TransactionCase, HttpCase or SavepointCase test with an available demo user, portal user or a large set of partners. - This is the first step to tend to a rolling release process, allowing to execute the tests (or a subset of the tests) on a migrated base, for example. closes odoo/odoo#39868 Taskid: 2075739 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/account/tests')
-rw-r--r--addons/account/tests/__init__.py1
-rw-r--r--addons/account/tests/account_minimal_test.py294
-rw-r--r--addons/account/tests/account_test_classes.py17
-rw-r--r--addons/account/tests/account_test_no_chart.py4
-rw-r--r--addons/account/tests/account_test_savepoint.py5
-rw-r--r--addons/account/tests/account_test_users.py35
-rw-r--r--addons/account/tests/test_account_journal_dashboard.py19
-rw-r--r--addons/account/tests/test_account_move_partner_count.py22
-rw-r--r--addons/account/tests/test_account_move_rounding.py33
-rw-r--r--addons/account/tests/test_account_onboarding.py28
-rw-r--r--addons/account/tests/test_bank_statement_reconciliation.py15
-rw-r--r--addons/account/tests/test_fiscal_position.py43
-rw-r--r--addons/account/tests/test_invoice_taxes.py24
-rw-r--r--addons/account/tests/test_payment.py47
-rw-r--r--addons/account/tests/test_portal_attachment.py7
-rw-r--r--addons/account/tests/test_reconciliation.py221
-rw-r--r--addons/account/tests/test_reconciliation_matching_rules.py155
-rw-r--r--addons/account/tests/test_tax.py45
18 files changed, 716 insertions, 299 deletions
diff --git a/addons/account/tests/__init__.py b/addons/account/tests/__init__.py
index 004d914db65..7bf7eabf151 100644
--- a/addons/account/tests/__init__.py
+++ b/addons/account/tests/__init__.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
+from . import account_minimal_test
from . import test_account_move_out_invoice
from . import test_account_move_out_refund
from . import test_account_move_in_invoice
diff --git a/addons/account/tests/account_minimal_test.py b/addons/account/tests/account_minimal_test.py
new file mode 100644
index 00000000000..daaaaa35652
--- /dev/null
+++ b/addons/account/tests/account_minimal_test.py
@@ -0,0 +1,294 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.tests.common import SavepointCase
+
+
+class AccountMinimalTest(SavepointCase):
+ """ This should be loaded for non python tests in other modules that require
+ accounting test data but that don't depend on any localization"""
+
+ @classmethod
+ def setUpClass(cls):
+ super(AccountMinimalTest, cls).setUpClass()
+ cls.create_accounting_minimal_data()
+
+ @classmethod
+ def create_accounting_minimal_data(cls):
+ cls.company = cls.env.company
+ cls.company.bank_account_code_prefix = 'X1100'
+
+ # Chart of Accounts
+
+ # Account Tags
+ cls.demo_capital_account = cls.env['account.account.tag'].create({'name': 'Demo Capital Account'})
+ cls.demo_stock_account = cls.env['account.account.tag'].create({'name': 'Demo Stock Account'})
+ cls.demo_sale_of_land_account = cls.env['account.account.tag'].create({'name': 'Demo Sale of Land Account'})
+ cls.demo_ceo_wages_account = cls.env['account.account.tag'].create({'name': 'Demo CEO Wages Account'})
+ cls.demo_office_furniture_account = cls.env['account.account.tag'].create({'name': 'Office Furniture'})
+
+ # Balance Sheet
+ cls.xfa = cls.env['account.account'].create({
+ 'code': 'X1000',
+ 'name': 'Fixed Assets - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_fixed_assets').id,
+ })
+ cls.cas = cls.env['account.account'].create({
+ 'code': 'X1010',
+ 'name': 'Current Assets - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
+ })
+ cls.stk = cls.env['account.account'].create({
+ 'code': 'X1011',
+ 'name': 'Purchased Stocks - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
+ 'tag_ids': [(6, 0, [cls.demo_stock_account.id])]
+ })
+ cls.a_recv = cls.env['account.account'].create({
+ 'code': 'X1012',
+ 'name': 'Debtors - (test)',
+ 'reconcile': True,
+ 'user_type_id': cls.env.ref('account.data_account_type_receivable').id,
+ })
+ cls.ova = cls.env['account.account'].create({
+ 'code': 'X1013',
+ 'name': 'VAT Paid- (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
+ })
+ cls.bnk = cls.env['account.account'].create({
+ 'code': 'X1014',
+ 'name': 'Bank Current Account - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_liquidity').id,
+ })
+ cls.cash = cls.env['account.account'].create({
+ 'code': 'X1015',
+ 'name': 'Cash - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_liquidity').id,
+ })
+ cls.o_income = cls.env['account.account'].create({
+ 'code': 'X1016',
+ 'name': 'Opening Income - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_other_income').id,
+ })
+ cls.usd_bnk = cls.env['account.account'].create({
+ 'code': 'X1017',
+ 'name': 'USD Bank Account - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_liquidity').id,
+ 'currency_id': cls.env.ref('base.USD').id,
+ })
+ cls.transfer_account = cls.env['account.account'].create({
+ 'code': 'X1019',
+ 'name': 'Internal Transfert Account - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
+ 'reconcile': True,
+ })
+ cls.ncas = cls.env['account.account'].create({
+ 'code': 'X1020',
+ 'name': 'Non-current Assets - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_non_current_assets').id,
+ })
+ cls.prepayements = cls.env['account.account'].create({
+ 'code': 'X1030',
+ 'name': 'Prepayments - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_prepayments').id,
+ })
+ cls.current_liabilities = cls.env['account.account'].create({
+ 'code': 'X1110',
+ 'name': 'Current Liabilities - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_current_liabilities').id,
+ })
+ cls.a_pay = cls.env['account.account'].create({
+ 'code': 'X1111',
+ 'name': 'Creditors - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_payable').id,
+ 'reconcile': True,
+ })
+ cls.iva = cls.env['account.account'].create({
+ 'code': 'X1112',
+ 'name': 'VAT Received - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_current_liabilities').id,
+ })
+ cls.rsa = cls.env['account.account'].create({
+ 'code': 'X1113',
+ 'name': 'Reserve and Profit/Loss - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_current_liabilities').id,
+ })
+ cls.cas = cls.env['account.account'].create({
+ 'code': 'X1120',
+ 'name': 'Non-current Liabilities - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_non_current_liabilities').id,
+ })
+ cls.o_expense = cls.env['account.account'].create({
+ 'code': 'X1114',
+ 'name': 'Opening Expense - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_expenses').id,
+ })
+
+ # Profit and Loss
+ cls.income_fx_income = cls.env['account.account'].create({
+ 'code': 'X2010',
+ 'name': 'Foreign Exchange Gain - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_revenue').id,
+ 'reconcile': False,
+ })
+ cls.a_sale = cls.env['account.account'].create({
+ 'code': 'X2020',
+ 'name': 'Product Sales - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_revenue').id,
+ 'tag_ids': [(6, 0, [cls.env.ref('account.account_tag_operating').id])],
+ })
+ cls.a_sale_invest = cls.env['account.account'].create({
+ 'code': 'X2021',
+ 'name': 'Sale of Lands - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_revenue').id,
+ 'tag_ids': [(6, 0, [cls.env.ref('account.account_tag_investing').id])],
+ })
+ cls.a_sale_finance = cls.env['account.account'].create({
+ 'code': 'X2022',
+ 'name': 'Bank Accounts Interests - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_revenue').id,
+ 'tag_ids': [(6, 0, [cls.env.ref('account.account_tag_financing').id])],
+ })
+ cls.a_sale_finance = cls.env['account.account'].create({
+ 'code': 'X2030',
+ 'name': 'Cost of Goods Sold - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_direct_costs').id,
+ })
+ cls.income_fx_expense = cls.env['account.account'].create({
+ 'code': 'X2110',
+ 'name': 'Foreign Exchange Loss - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_expenses').id,
+ 'reconcile': False,
+ })
+ cls.a_expense = cls.env['account.account'].create({
+ 'code': 'X2120',
+ 'name': 'Expenses - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_expenses').id,
+ 'tag_ids': [(6, 0, [cls.env.ref('account.account_tag_operating').id])],
+ })
+ cls.a_salary_expense = cls.env['account.account'].create({
+ 'code': 'X2121',
+ 'name': 'Salary Expenses - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_expenses').id,
+ 'tag_ids': [(6, 0, [cls.env.ref('account.account_tag_operating').id])],
+ })
+ cls.a_expense_invest = cls.env['account.account'].create({
+ 'code': 'X2122',
+ 'name': 'Purchase of Equipments - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_fixed_assets').id,
+ 'tag_ids': [(6, 0, [cls.env.ref('account.account_tag_investing').id])],
+ })
+ cls.a_expense_finance = cls.env['account.account'].create({
+ 'code': 'X2123',
+ 'name': 'Bank Fees - (test)',
+ 'user_type_id': cls.env.ref('account.data_account_type_expenses').id,
+ 'tag_ids': [(6, 0, [cls.env.ref('account.account_tag_financing').id])],
+ })
+ cls.a_capital = cls.env['account.account'].create({
+ 'code': 'X3001',
+ 'name': 'Capital',
+ 'user_type_id': cls.env.ref('account.data_account_type_equity').id,
+ })
+ cls.a_dividends = cls.env['account.account'].create({
+ 'code': 'X3002',
+ 'name': 'Dividends',
+ 'user_type_id': cls.env.ref('account.data_account_type_equity').id,
+ })
+
+ # Properties: Product income and expense accounts, default parameters
+ cls.env['ir.property'].create([{
+ 'name': 'property_account_receivable_id',
+ 'fields_id': cls.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_receivable_id')], limit=1).id,
+ 'value': 'account.account,%s' % (cls.a_recv.id),
+ 'company_id': cls.company.id,
+ }, {
+ 'name': 'property_account_payable_id',
+ 'fields_id': cls.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_payable_id')], limit=1).id,
+ 'value': 'account.account,%s' % (cls.a_pay.id),
+ 'company_id': cls.company.id,
+ }, {
+ 'name': 'property_account_position_id',
+ 'fields_id': cls.env['ir.model.fields'].search([('model', '=', 'res.partner'), ('name', '=', 'property_account_position_id')], limit=1).id,
+ 'value': False,
+ 'company_id': cls.company.id,
+ }, {
+ 'name': 'property_account_expense_categ_id',
+ 'fields_id': cls.env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', '=', 'property_account_expense_categ_id')], limit=1).id,
+ 'value': 'account.account,%s' % (cls.a_expense.id),
+ 'company_id': cls.company.id,
+ }, {
+ 'name': 'property_account_income_categ_id',
+ 'fields_id': cls.env['ir.model.fields'].search([('model', '=', 'product.category'), ('name', '=', 'property_account_income_categ_id')], limit=1).id,
+ 'value': 'account.account,%s' % (cls.a_sale.id),
+ 'company_id': cls.company.id,
+ }])
+
+ # Bank Accounts
+ cls.bank_account = cls.env['res.partner.bank'].create({
+ 'acc_number': '987654321',
+ 'bank_name': 'Bank',
+ 'partner_id': cls.company.partner_id.id,
+ })
+ cls.bank_account_usd = cls.env['res.partner.bank'].create({
+ 'acc_number': '123456789',
+ 'bank_name': 'Bank US',
+ 'partner_id': cls.company.partner_id.id,
+ })
+
+ # Account Journal
+ cls.sales_journal = cls.env['account.journal'].create({
+ 'name': 'Customer Invoices - Test',
+ 'code': 'TINV',
+ 'type': 'sale',
+ 'default_credit_account_id': cls.a_sale.id,
+ 'default_debit_account_id': cls.a_sale.id,
+ 'refund_sequence': True,
+ })
+ cls.expenses_journal = cls.env['account.journal'].create({
+ 'name': 'Vendor Bills - Test',
+ 'code': 'TEXJ',
+ 'type': 'purchase',
+ 'default_credit_account_id': cls.a_expense.id,
+ 'default_debit_account_id': cls.a_expense.id,
+ 'refund_sequence': True,
+ })
+ cls.bank_journal = cls.env['account.journal'].create({
+ 'name': 'Bank - Test',
+ 'code': 'TBNK',
+ 'type': 'bank',
+ 'default_credit_account_id': cls.bnk.id,
+ 'default_debit_account_id': cls.bnk.id,
+ })
+ cls.cash_journal = cls.env['account.journal'].create({
+ 'name': 'Cash - Test',
+ 'code': 'TCSH',
+ 'type': 'cash',
+ 'profit_account_id': cls.rsa.id,
+ 'loss_account_id': cls.rsa.id,
+ 'default_credit_account_id': cls.cash.id,
+ 'default_debit_account_id': cls.cash.id,
+ })
+ cls.miscellaneous_journal = cls.env['account.journal'].create({
+ 'name': 'Miscellaneous - Test',
+ 'code': 'TMIS',
+ 'type': 'general',
+ 'show_on_dashboard': False,
+ })
+ cls.currency_diff_journal = cls.env['account.journal'].create({
+ 'name': 'Currency Difference - Test',
+ 'code': 'CUR',
+ 'type': 'general',
+ 'default_credit_account_id': cls.income_fx_expense.id,
+ 'default_debit_account_id': cls.income_fx_income.id,
+ 'show_on_dashboard': False,
+ })
+ cls.bank_journal_usd = cls.env['account.journal'].create({
+ 'name': 'USD Bank - Test',
+ 'code': 'TUBK',
+ 'type': 'bank',
+ 'default_credit_account_id': cls.usd_bnk.id,
+ 'default_debit_account_id': cls.usd_bnk.id,
+ 'bank_account_id': cls.bank_account_usd.id,
+ })
+
+ cls.company.currency_exchange_journal_id = cls.currency_diff_journal.id
diff --git a/addons/account/tests/account_test_classes.py b/addons/account/tests/account_test_classes.py
index 00267faddd6..8db3804321f 100644
--- a/addons/account/tests/account_test_classes.py
+++ b/addons/account/tests/account_test_classes.py
@@ -4,21 +4,22 @@ import logging
_logger = logging.getLogger(__name__)
from odoo.tests.common import HttpCase, tagged
+from odoo.addons.account.tests.account_minimal_test import AccountMinimalTest
-
-class AccountingTestCase(HttpCase):
- """ This class extends the base TransactionCase, in order to test the
+class AccountingTestCase(AccountMinimalTest):
+ """ This class extends the base SavePoint Case, in order to test the
accounting with localization setups. It is configured to run the tests after
the installation of all modules, and will SKIP TESTS if it cannot find an already
configured accounting (which means no localization module has been installed).
"""
- def setUp(self):
- super(AccountingTestCase, self).setUp()
- domain = [('company_id', '=', self.env.ref('base.main_company').id)]
- if not self.env['account.account'].search_count(domain):
+ @classmethod
+ def setUpClass(cls):
+ super(AccountingTestCase, cls).setUpClass()
+ domain = [('company_id', '=', cls.env.company.id)]
+ if not cls.env['account.account'].search_count(domain):
_logger.warning('Test skipped because there is no chart of account defined ...')
- self.skipTest("No Chart of account found")
+ cls.skipTest(cls, "No Chart of account found")
def ensure_account_property(self, property_name):
'''Ensure the ir.property targeting an account.account passed as parameter exists.
diff --git a/addons/account/tests/account_test_no_chart.py b/addons/account/tests/account_test_no_chart.py
index 61cbe3e47a6..a42bc2755db 100644
--- a/addons/account/tests/account_test_no_chart.py
+++ b/addons/account/tests/account_test_no_chart.py
@@ -2,9 +2,9 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.tests.common import SavepointCase, HttpCase, tagged
+from odoo.addons.base.tests.common import SavepointCaseWithUserDemo
-
-class TestAccountNoChartCommon(SavepointCase):
+class TestAccountNoChartCommon(SavepointCaseWithUserDemo):
""" Some tests required to be executed at module installation, and not 'post install', like moslty
of accounting tests, since a chart of account is required
This test setup class provides data for test suite to make business flow working without a chart
diff --git a/addons/account/tests/account_test_savepoint.py b/addons/account/tests/account_test_savepoint.py
index a5e0b2f2082..180b7a868c4 100644
--- a/addons/account/tests/account_test_savepoint.py
+++ b/addons/account/tests/account_test_savepoint.py
@@ -1,4 +1,7 @@
# -*- coding: utf-8 -*-
+
+import unittest
+
from odoo import fields
from odoo.tests.common import Form, SavepointCase
from odoo.tests import tagged
@@ -19,7 +22,7 @@ class AccountingSavepointCase(SavepointCase):
if not chart_template:
chart_template = cls.env.ref('l10n_generic_coa.configurable_chart_template', raise_if_not_found=False)
if not chart_template:
- cls.skipTest("Accounting Tests skipped because the user's company has no chart of accounts.")
+ cls.skipTest(cls, "Accounting Tests skipped because the user's company has no chart of accounts.")
# Create user.
user = cls.env['res.users'].create({
diff --git a/addons/account/tests/account_test_users.py b/addons/account/tests/account_test_users.py
index caa17a9a821..a9b7b30545d 100644
--- a/addons/account/tests/account_test_users.py
+++ b/addons/account/tests/account_test_users.py
@@ -5,30 +5,31 @@ class AccountTestUsers(AccountingTestCase):
"""Tests for diffrent type of user 'Accountant/Adviser' and added groups"""
- def setUp(self):
- super(AccountTestUsers, self).setUp()
- self.res_user_model = self.env['res.users']
- self.main_company = self.env.ref('base.main_company')
- self.main_partner = self.env.ref('base.main_partner')
- self.main_bank = self.env.ref('base.res_bank_1')
- res_users_account_user = self.env.ref('account.group_account_invoice')
- res_users_account_manager = self.env.ref('account.group_account_manager')
- partner_manager = self.env.ref('base.group_partner_manager')
- self.tax_model = self.env['account.tax']
- self.account_model = self.env['account.account']
- self.account_type_model = self.env['account.account.type']
- self.currency_euro = self.env.ref('base.EUR')
+ @classmethod
+ def setUpClass(cls):
+ super(AccountTestUsers, cls).setUpClass()
+ cls.res_user_model = cls.env['res.users']
+ cls.main_company = cls.env.ref('base.main_company')
+ cls.main_partner = cls.env.ref('base.main_partner')
+ cls.main_bank = cls.env.ref('base.res_bank_1')
+ res_users_account_user = cls.env.ref('account.group_account_invoice')
+ res_users_account_manager = cls.env.ref('account.group_account_manager')
+ partner_manager = cls.env.ref('base.group_partner_manager')
+ cls.tax_model = cls.env['account.tax']
+ cls.account_model = cls.env['account.account']
+ cls.account_type_model = cls.env['account.account.type']
+ cls.currency_euro = cls.env.ref('base.EUR')
- self.account_user = self.res_user_model.with_context({'no_reset_password': True}).create(dict(
+ cls.account_user = cls.res_user_model.with_context({'no_reset_password': True}).create(dict(
name="Accountant",
- company_id=self.main_company.id,
+ company_id=cls.main_company.id,
login="acc",
email="accountuser@yourcompany.com",
groups_id=[(6, 0, [res_users_account_user.id, partner_manager.id])]
))
- self.account_manager = self.res_user_model.with_context({'no_reset_password': True}).create(dict(
+ cls.account_manager = cls.res_user_model.with_context({'no_reset_password': True}).create(dict(
name="Adviser",
- company_id=self.main_company.id,
+ company_id=cls.main_company.id,
login="fm",
email="accountmanager@yourcompany.com",
groups_id=[(6, 0, [res_users_account_manager.id, partner_manager.id])]
diff --git a/addons/account/tests/test_account_journal_dashboard.py b/addons/account/tests/test_account_journal_dashboard.py
index 0d6e88e30bc..19a7bbdab59 100644
--- a/addons/account/tests/test_account_journal_dashboard.py
+++ b/addons/account/tests/test_account_journal_dashboard.py
@@ -18,14 +18,25 @@ class TestAccountJournalDashboard(AccountTestUsers):
'type': 'sale',
})
+ res_partner_3 = self.env['res.partner'].create({
+ 'name': 'Gemini Furniture',
+ })
+
+ product_product_1 = self.env['product.product'].create({
+ 'name': 'Virtual Interior Design',
+ 'standard_price': 20.5,
+ 'list_price': 30.75,
+ 'type': 'service',
+ })
+
invoice = self.env['account.move'].create({
'type': 'out_invoice',
'journal_id': journal.id,
- 'partner_id': self.env.ref('base.res_partner_3').id,
+ 'partner_id': res_partner_3.id,
'invoice_date': date_invoice,
'date': date_invoice,
'invoice_line_ids': [(0, 0, {
- 'product_id': self.env.ref('product.product_product_1').id,
+ 'product_id': product_product_1.id,
'quantity': 40.0,
'name': 'product test 1',
'discount': 10.00,
@@ -35,11 +46,11 @@ class TestAccountJournalDashboard(AccountTestUsers):
refund = self.env['account.move'].create({
'type': 'out_refund',
'journal_id': journal.id,
- 'partner_id': self.env.ref('base.res_partner_3').id,
+ 'partner_id': res_partner_3.id,
'invoice_date': '2019-01-21',
'date': date_invoice,
'invoice_line_ids': [(0, 0, {
- 'product_id': self.env.ref('product.product_product_1').id,
+ 'product_id': product_product_1.id,
'quantity': 1.0,
'name': 'product test 1',
'price_unit': 13.3,
diff --git a/addons/account/tests/test_account_move_partner_count.py b/addons/account/tests/test_account_move_partner_count.py
index 203c4dc0493..de3d8ae7fa7 100644
--- a/addons/account/tests/test_account_move_partner_count.py
+++ b/addons/account/tests/test_account_move_partner_count.py
@@ -51,25 +51,3 @@ class TestAccountMovePartnerCount(TransactionCase):
self.journal.with_env(env).unlink()
self.account_income.with_env(env).unlink()
self.partner.with_env(env).unlink()
-
- def test_account_move_count(self):
- # T2 create and post account move
- with self.registry.cursor() as cr:
- env = self.env(cr=cr)
- self.move.with_env(env).post()
- partner = self.partner.with_env(env)
- self.assertEqual(partner.supplier_rank, 0)
- self.assertEqual(partner.customer_rank, 1)
-
- def test_account_move_count_concurrent(self):
- # T2 Lock the partner row
- with self.registry.cursor() as cr:
- cr.execute("""SELECT id FROM res_partner WHERE id = %s FOR UPDATE""" % self.partner.id)
-
- # T3 concurrently posts account move and tries to update partner
- with self.registry.cursor() as cr:
- env = self.env(cr=cr)
- self.move.with_env(env).state = 'posted'
-
- self.assertEqual(self.partner.with_env(env).customer_rank,
- 0, "It should not wait the concurrent transaction for the update")
diff --git a/addons/account/tests/test_account_move_rounding.py b/addons/account/tests/test_account_move_rounding.py
index 63a3bebc2be..9ea27cb74bb 100644
--- a/addons/account/tests/test_account_move_rounding.py
+++ b/addons/account/tests/test_account_move_rounding.py
@@ -7,33 +7,34 @@ from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestAccountMoveRounding(AccountingTestCase):
- def setUp(self):
- super(TestAccountMoveRounding, self).setUp()
- self.currency = self.env['res.currency'].create({
+ @classmethod
+ def setUpClass(cls):
+ super(TestAccountMoveRounding, cls).setUpClass()
+ cls.currency = cls.env['res.currency'].create({
'name': "RAM",
'symbol': "🐏",
'rounding': 0.01,
})
- self.company = self.env['res.company'].create({
+ cls.company = cls.env['res.company'].create({
'name': "SHEEP",
- 'currency_id': self.currency.id,
+ 'currency_id': cls.currency.id,
})
- self.account_type = self.env['account.account.type'].create(
- {'name': 'BAAH',
- 'internal_group': 'asset',
- 'type': 'receivable'
+ cls.account_type = cls.env['account.account.type'].create({
+ 'name': 'BAAH',
+ 'internal_group': 'asset',
+ 'type': 'receivable'
})
- self.journal = self.env['account.journal'].create({
- 'company_id': self.company.id,
+ cls.journal = cls.env['account.journal'].create({
+ 'company_id': cls.company.id,
'name': 'LAMB',
- 'code': 'L',
+ 'code': 'LL',
'type': 'purchase',
})
- self.account = self.env['account.account'].create({
- 'company_id': self.company.id,
+ cls.account = cls.env['account.account'].create({
+ 'company_id': cls.company.id,
'name': 'EWE',
- 'code': 'E',
- 'user_type_id': self.account_type.id,
+ 'code': 'EE',
+ 'user_type_id': cls.account_type.id,
'reconcile': True,
})
diff --git a/addons/account/tests/test_account_onboarding.py b/addons/account/tests/test_account_onboarding.py
index c4839a35a32..b1f0d4e0f07 100644
--- a/addons/account/tests/test_account_onboarding.py
+++ b/addons/account/tests/test_account_onboarding.py
@@ -1,18 +1,24 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
from odoo.tests.common import tagged, HttpCase
+from odoo import tools
@tagged('-at_install', 'post_install', 'document_layout')
class TestAccountDocumentLayout(HttpCase):
def test_render_account_document_layout(self):
- report_layout = self.env.ref('web.report_layout_standard')
- main_company = self.env.ref('base.main_company')
- main_company.write({
- 'primary_color': '#123456',
- 'secondary_color': '#789101',
- 'external_report_layout_id': report_layout.view_id.id,
- })
- self.env.ref('account.account_invoices_without_payment').write({
- 'report_type': 'qweb-html',
- })
- self.start_tour("/web", 'account_render_report', login='admin', timeout=200)
+ # YTI TODO: Adapt this tour without demo data
+ if not tools.config["without_demo"]:
+ report_layout = self.env.ref('web.report_layout_standard')
+ main_company = self.env.ref('base.main_company')
+ main_company.write({
+ 'primary_color': '#123456',
+ 'secondary_color': '#789101',
+ 'external_report_layout_id': report_layout.view_id.id,
+ })
+ self.env.ref('account.account_invoices_without_payment').write({
+ 'report_type': 'qweb-html',
+ })
+ self.start_tour("/web", 'account_render_report', login='admin', timeout=200)
diff --git a/addons/account/tests/test_bank_statement_reconciliation.py b/addons/account/tests/test_bank_statement_reconciliation.py
index 43e38bf1bca..6061f553644 100644
--- a/addons/account/tests/test_bank_statement_reconciliation.py
+++ b/addons/account/tests/test_bank_statement_reconciliation.py
@@ -5,13 +5,14 @@ from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestBankStatementReconciliation(AccountingTestCase):
- def setUp(self):
- super(TestBankStatementReconciliation, self).setUp()
- self.bs_model = self.env['account.bank.statement']
- self.bsl_model = self.env['account.bank.statement.line']
- self.partner = self.env['res.partner'].create({'name': 'test'})
- self.currency_usd_id = self.env.ref("base.USD").id
- self.currency_euro_id = self.env.ref("base.EUR").id
+ @classmethod
+ def setUpClass(cls):
+ super(TestBankStatementReconciliation, cls).setUpClass()
+ cls.bs_model = cls.env['account.bank.statement']
+ cls.bsl_model = cls.env['account.bank.statement.line']
+ cls.partner = cls.env['res.partner'].create({'name': 'test'})
+ cls.currency_usd_id = cls.env.ref("base.USD").id
+ cls.currency_euro_id = cls.env.ref("base.EUR").id
def test_full_reconcile(self):
self._reconcile_invoice_with_statement('pay_val')
diff --git a/addons/account/tests/test_fiscal_position.py b/addons/account/tests/test_fiscal_position.py
index 4b19431806b..a8148fc9360 100644
--- a/addons/account/tests/test_fiscal_position.py
+++ b/addons/account/tests/test_fiscal_position.py
@@ -1,55 +1,60 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
from odoo.tests import common
-class TestFiscalPosition(common.TransactionCase):
+
+class TestFiscalPosition(common.SavepointCase):
"""Tests for fiscal positions in auto apply (account.fiscal.position).
If a partner has a vat number, the fiscal positions with "vat_required=True"
are preferred.
"""
- def setUp(self):
- super(TestFiscalPosition, self).setUp()
- self.fp = self.env['account.fiscal.position']
+ @classmethod
+ def setUpClass(cls):
+ super(TestFiscalPosition, cls).setUpClass()
+ cls.fp = cls.env['account.fiscal.position']
# reset any existing FP
- self.fp.search([]).write({'auto_apply': False})
-
- self.res_partner = self.env['res.partner']
- self.be = be = self.env.ref('base.be')
- self.fr = fr = self.env.ref('base.fr')
- self.mx = mx = self.env.ref('base.mx')
- self.eu = eu = self.env.ref('base.europe')
- self.state_fr = self.env['res.country.state'].create(dict(
+ cls.fp.search([]).write({'auto_apply': False})
+
+ cls.res_partner = cls.env['res.partner']
+ cls.be = be = cls.env.ref('base.be')
+ cls.fr = fr = cls.env.ref('base.fr')
+ cls.mx = mx = cls.env.ref('base.mx')
+ cls.eu = eu = cls.env.ref('base.europe')
+ cls.state_fr = cls.env['res.country.state'].create(dict(
name="State",
code="ST",
country_id=fr.id))
- self.jc = self.res_partner.create(dict(
+ cls.jc = cls.res_partner.create(dict(
name="JCVD",
vat="BE0477472701",
country_id=be.id))
- self.ben = self.res_partner.create(dict(
+ cls.ben = cls.res_partner.create(dict(
name="BP",
country_id=be.id))
- self.george = self.res_partner.create(dict(
+ cls.george = cls.res_partner.create(dict(
name="George",
vat="BE0477472701",
country_id=fr.id))
- self.alberto = self.res_partner.create(dict(
+ cls.alberto = cls.res_partner.create(dict(
name="Alberto",
vat="BE0477472701",
country_id=mx.id))
- self.be_nat = self.fp.create(dict(
+ cls.be_nat = cls.fp.create(dict(
name="BE-NAT",
auto_apply=True,
country_id=be.id,
vat_required=False,
sequence=10))
- self.fr_b2c = self.fp.create(dict(
+ cls.fr_b2c = cls.fp.create(dict(
name="EU-VAT-FR-B2C",
auto_apply=True,
country_id=fr.id,
vat_required=False,
sequence=40))
- self.fr_b2b = self.fp.create(dict(
+ cls.fr_b2b = cls.fp.create(dict(
name="EU-VAT-FR-B2B",
auto_apply=True,
country_id=fr.id,
diff --git a/addons/account/tests/test_invoice_taxes.py b/addons/account/tests/test_invoice_taxes.py
index 90e3a385e3d..0d4df086eba 100644
--- a/addons/account/tests/test_invoice_taxes.py
+++ b/addons/account/tests/test_invoice_taxes.py
@@ -1,22 +1,26 @@
# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo.addons.base.tests.common import SavepointCaseWithUserDemo
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.tests.common import Form
from odoo.tests import tagged
@tagged('post_install', '-at_install')
-class TestInvoiceTaxes(AccountingTestCase):
+class TestInvoiceTaxes(AccountingTestCase, SavepointCaseWithUserDemo):
- def setUp(self):
- super(TestInvoiceTaxes, self).setUp()
+ @classmethod
+ def setUpClass(cls):
+ super(TestInvoiceTaxes, cls).setUpClass()
- self.percent_tax_1 = self.env['account.tax'].create({
+ cls.percent_tax_1 = cls.env['account.tax'].create({
'name': '21%',
'amount_type': 'percent',
'amount': 21,
'sequence': 10,
})
- self.percent_tax_1_incl = self.env['account.tax'].create({
+ cls.percent_tax_1_incl = cls.env['account.tax'].create({
'name': '21% incl',
'amount_type': 'percent',
'amount': 21,
@@ -24,19 +28,19 @@ class TestInvoiceTaxes(AccountingTestCase):
'include_base_amount': True,
'sequence': 20,
})
- self.percent_tax_2 = self.env['account.tax'].create({
+ cls.percent_tax_2 = cls.env['account.tax'].create({
'name': '12%',
'amount_type': 'percent',
'amount': 12,
'sequence': 30,
})
- self.group_tax = self.env['account.tax'].create({
+ cls.group_tax = cls.env['account.tax'].create({
'name': 'group 12% + 21%',
'amount_type': 'group',
'amount': 21,
'children_tax_ids': [
- (4, self.percent_tax_1_incl.id),
- (4, self.percent_tax_2.id)
+ (4, cls.percent_tax_1_incl.id),
+ (4, cls.percent_tax_2.id)
],
'sequence': 40,
})
@@ -48,7 +52,7 @@ class TestInvoiceTaxes(AccountingTestCase):
'''
self_ctx = self.env['account.move'].with_context(default_type=inv_type)
invoice_form = Form(self_ctx)
- invoice_form.partner_id = self.env.ref('base.partner_demo')
+ invoice_form.partner_id = self.partner_demo
for amount, taxes in taxes_per_line:
with invoice_form.invoice_line_ids.new() as invoice_line_form:
diff --git a/addons/account/tests/test_payment.py b/addons/account/tests/test_payment.py
index d501ada8798..8f560635e60 100644
--- a/addons/account/tests/test_payment.py
+++ b/addons/account/tests/test_payment.py
@@ -1,3 +1,6 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.tests import tagged
from odoo.tests.common import Form
@@ -8,21 +11,29 @@ import time
class TestPayment(AccountingTestCase):
def setUp(self):
+ self.env.ref('base.main_company').currency_id = self.env.ref('base.USD')
super(TestPayment, self).setUp()
self.register_payments_model = self.env['account.payment.register'].with_context(active_model='account.move')
self.payment_model = self.env['account.payment']
self.acc_bank_stmt_model = self.env['account.bank.statement']
self.acc_bank_stmt_line_model = self.env['account.bank.statement.line']
- self.partner_agrolait = self.env.ref("base.res_partner_2")
- self.partner_china_exp = self.env.ref("base.res_partner_3")
+ self.partner_agrolait = self.env['res.partner'].create({'name': 'Agrolait', 'is_company': True})
+ self.partner_china_exp = self.env['res.partner'].create({'name': 'China Export', 'is_company': True})
self.currency_chf_id = self.env.ref("base.CHF").id
self.currency_usd_id = self.env.ref("base.USD").id
self.currency_eur_id = self.env.ref("base.EUR").id
company = self.env.ref('base.main_company')
self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.currency_eur_id, company.id])
- self.product = self.env.ref("product.product_product_4")
+
+ self.product = self.env['product.product'].create({
+ 'name': 'Product Product 4',
+ 'standard_price': 500.0,
+ 'list_price': 750.0,
+ 'type': 'consu',
+ 'categ_id': self.env.ref('product.product_category_all').id,
+ })
self.payment_method_manual_in = self.env.ref("account.account_payment_method_manual_in")
self.payment_method_manual_out = self.env.ref("account.account_payment_method_manual_out")
@@ -38,12 +49,30 @@ class TestPayment(AccountingTestCase):
self.bank_journal_usd = self.env['account.journal'].create({'name': 'Bank US', 'type': 'bank', 'code': 'BNK68', 'currency_id': self.currency_usd_id})
self.account_usd = self.bank_journal_usd.default_debit_account_id
- self.transfer_account = self.env['res.users'].browse(self.env.uid).company_id.transfer_account_id
- self.diff_income_account = self.env['res.users'].browse(self.env.uid).company_id.income_currency_exchange_account_id
- self.diff_expense_account = self.env['res.users'].browse(self.env.uid).company_id.expense_currency_exchange_account_id
+ if not self.env.user.company_id.transfer_account_id:
+ self.env.user.company_id.transfer_account_id = self.usd_bnk
+ self.transfer_account = self.env.user.company_id.transfer_account_id
+ self.diff_income_account = self.env.user.company_id.income_currency_exchange_account_id
+ self.diff_expense_account = self.env.user.company_id.expense_currency_exchange_account_id
self.form_payment = Form(self.env['account.payment'])
+ self.env['res.currency.rate'].create([
+ {
+ 'currency_id': self.env.ref('base.EUR').id,
+ 'name': '2010-01-02',
+ 'rate': 1.0,
+ }, {
+ 'currency_id': self.env.ref('base.USD').id,
+ 'name': '2010-01-02',
+ 'rate': 1.2834,
+ }, {
+ 'currency_id': self.env.ref('base.USD').id,
+ 'name': time.strftime('%Y-06-05'),
+ 'rate': 1.5289,
+ }
+ ])
+
def create_invoice(self, amount=100, type='out_invoice', currency_id=None, partner=None, account_id=None):
""" Returns an open invoice """
invoice = self.env['account.move'].create({
@@ -130,6 +159,12 @@ class TestPayment(AccountingTestCase):
])
def test_payment_chf_journal_usd(self):
+ self.env['res.currency.rate'].create({
+ 'rate': 1.3086,
+ 'currency_id': self.currency_chf_id,
+ 'name': '2010-01-02',
+ })
+
payment = self.payment_model.create({
'payment_date': time.strftime('%Y') + '-07-15',
'payment_type': 'outbound',
diff --git a/addons/account/tests/test_portal_attachment.py b/addons/account/tests/test_portal_attachment.py
index 584d8e8b259..7598ca2b98f 100644
--- a/addons/account/tests/test_portal_attachment.py
+++ b/addons/account/tests/test_portal_attachment.py
@@ -14,6 +14,13 @@ class TestUi(tests.HttpCase):
def test_01_portal_attachment(self):
"""Test the portal chatter attachment route."""
+ miscellaneous_journal = self.env['account.journal'].create({
+ 'name': 'Miscellaneous - Test',
+ 'code': 'TMISC',
+ 'type': 'general',
+ 'show_on_dashboard': False,
+ })
+
base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url')
# For this test we need a parent document with an access_token field
# (in this case from portal.mixin) and also inheriting mail.thread.
diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py
index 9c754ce33e4..0877d1368bc 100644
--- a/addons/account/tests/test_reconciliation.py
+++ b/addons/account/tests/test_reconciliation.py
@@ -1,4 +1,7 @@
-from odoo import api, fields
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, tools
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.exceptions import UserError
from odoo.tests import Form, tagged
@@ -6,7 +9,6 @@ import time
from datetime import timedelta
import unittest
-
# TODO in master
# The name of this class should be TestReconciliationHelpers
class TestReconciliation(AccountingTestCase):
@@ -17,94 +19,115 @@ class TestReconciliation(AccountingTestCase):
the result will be balanced.
"""
- def setUp(self):
- super(TestReconciliation, self).setUp()
- self.acc_bank_stmt_model = self.env['account.bank.statement']
- self.acc_bank_stmt_line_model = self.env['account.bank.statement.line']
- self.res_currency_model = self.registry('res.currency')
- self.res_currency_rate_model = self.registry('res.currency.rate')
-
- self.partner_agrolait = self.env.ref("base.res_partner_2")
- self.partner_agrolait_id = self.partner_agrolait.id
- self.currency_swiss_id = self.env.ref("base.CHF").id
- self.currency_usd_id = self.env.ref("base.USD").id
- self.currency_euro_id = self.env.ref("base.EUR").id
- company = self.env.ref('base.main_company')
- self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.currency_euro_id, company.id])
- self.account_rcv = self.partner_agrolait.property_account_receivable_id or self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_receivable').id)], limit=1)
- self.account_rsa = self.partner_agrolait.property_account_payable_id or self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_payable').id)], limit=1)
- self.product = self.env.ref("product.product_product_4")
-
- self.bank_journal_euro = self.env['account.journal'].create({'name': 'Bank', 'type': 'bank', 'code': 'BNK67'})
- self.account_euro = self.bank_journal_euro.default_debit_account_id
-
- self.bank_journal_usd = self.env['account.journal'].create({'name': 'Bank US', 'type': 'bank', 'code': 'BNK68', 'currency_id': self.currency_usd_id})
- self.account_usd = self.bank_journal_usd.default_debit_account_id
-
- self.fx_journal = self.env['res.users'].browse(self.env.uid).company_id.currency_exchange_journal_id
- self.diff_income_account = self.env['res.users'].browse(self.env.uid).company_id.income_currency_exchange_account_id
- self.diff_expense_account = self.env['res.users'].browse(self.env.uid).company_id.expense_currency_exchange_account_id
-
- self.inbound_payment_method = self.env['account.payment.method'].create({
+ @classmethod
+ def setUpClass(cls):
+ super(TestReconciliation, cls).setUpClass()
+ cls.company = cls.env['res.company'].create({
+ 'name': 'A test company',
+ 'currency_id': cls.env.ref('base.EUR').id
+ })
+ cls.env.user.company_id = cls.company
+ # Generate minimal data for my new company
+ cls.create_accounting_minimal_data()
+
+ cls.acc_bank_stmt_model = cls.env['account.bank.statement']
+ cls.acc_bank_stmt_line_model = cls.env['account.bank.statement.line']
+ cls.res_currency_model = cls.registry('res.currency')
+ cls.res_currency_rate_model = cls.registry('res.currency.rate')
+
+ cls.partner_agrolait = cls.env['res.partner'].create({
+ 'name': 'Deco Addict',
+ 'is_company': True,
+ 'country_id': cls.env.ref('base.us').id,
+ })
+ cls.partner_agrolait_id = cls.partner_agrolait.id
+ cls.currency_swiss_id = cls.env.ref("base.CHF").id
+ cls.currency_usd_id = cls.env.ref("base.USD").id
+ cls.currency_euro_id = cls.env.ref("base.EUR").id
+ # YTI FIXME Some of those lines should be useless now
+ cls.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [cls.currency_euro_id, cls.company.id])
+ cls.account_rcv = cls.partner_agrolait.property_account_receivable_id or cls.env['account.account'].search([('user_type_id', '=', cls.env.ref('account.data_account_type_receivable').id)], limit=1)
+ cls.account_rsa = cls.partner_agrolait.property_account_payable_id or cls.env['account.account'].search([('user_type_id', '=', cls.env.ref('account.data_account_type_payable').id)], limit=1)
+ cls.product = cls.env['product.product'].create({
+ 'name': 'Product Product 4',
+ 'standard_price': 500.0,
+ 'list_price': 750.0,
+ 'type': 'consu',
+ 'categ_id': cls.env.ref('product.product_category_all').id,
+ })
+
+ cls.bank_journal_euro = cls.env['account.journal'].create({'name': 'Bank', 'type': 'bank', 'code': 'BNK67'})
+ cls.account_euro = cls.bank_journal_euro.default_debit_account_id
+
+ cls.bank_journal_usd = cls.env['account.journal'].create({'name': 'Bank US', 'type': 'bank', 'code': 'BNK68', 'currency_id': cls.currency_usd_id})
+ cls.account_usd = cls.bank_journal_usd.default_debit_account_id
+
+ cls.fx_journal = cls.env['res.users'].browse(cls.env.uid).company_id.currency_exchange_journal_id
+ cls.diff_income_account = cls.env['res.users'].browse(cls.env.uid).company_id.income_currency_exchange_account_id
+ cls.diff_expense_account = cls.env['res.users'].browse(cls.env.uid).company_id.expense_currency_exchange_account_id
+
+ cls.inbound_payment_method = cls.env['account.payment.method'].create({
'name': 'inbound',
'code': 'IN',
'payment_type': 'inbound',
})
- self.expense_account = self.env['account.account'].create({
+ cls.expense_account = cls.env['account.account'].create({
'name': 'EXP',
'code': 'EXP',
- 'user_type_id': self.env.ref('account.data_account_type_expenses').id,
- 'company_id': company.id,
+ 'user_type_id': cls.env.ref('account.data_account_type_expenses').id,
+ 'company_id': cls.company.id,
})
# cash basis intermediary account
- self.tax_waiting_account = self.env['account.account'].create({
+ cls.tax_waiting_account = cls.env['account.account'].create({
'name': 'TAX_WAIT',
'code': 'TWAIT',
- 'user_type_id': self.env.ref('account.data_account_type_current_liabilities').id,
+ 'user_type_id': cls.env.ref('account.data_account_type_current_liabilities').id,
'reconcile': True,
- 'company_id': company.id,
+ 'company_id': cls.company.id,
})
# cash basis final account
- self.tax_final_account = self.env['account.account'].create({
+ cls.tax_final_account = cls.env['account.account'].create({
'name': 'TAX_TO_DEDUCT',
'code': 'TDEDUCT',
- 'user_type_id': self.env.ref('account.data_account_type_current_assets').id,
- 'company_id': company.id,
+ 'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
+ 'company_id': cls.company.id,
})
- self.tax_base_amount_account = self.env['account.account'].create({
+ cls.tax_base_amount_account = cls.env['account.account'].create({
'name': 'TAX_BASE',
'code': 'TBASE',
- 'user_type_id': self.env.ref('account.data_account_type_current_assets').id,
- 'company_id': company.id,
+ 'user_type_id': cls.env.ref('account.data_account_type_current_assets').id,
+ 'company_id': cls.company.id,
})
# Journals
- self.purchase_journal = self.env['account.journal'].create({
+ cls.purchase_journal = cls.env['account.journal'].create({
'name': 'purchase',
'code': 'PURCH',
'type': 'purchase',
+ 'default_credit_account_id': cls.a_expense.id,
+ 'default_debit_account_id': cls.a_expense.id,
})
- self.cash_basis_journal = self.env['account.journal'].create({
+ cls.cash_basis_journal = cls.env['account.journal'].create({
'name': 'CABA',
'code': 'CABA',
'type': 'general',
})
- self.general_journal = self.env['account.journal'].create({
+ cls.general_journal = cls.env['account.journal'].create({
'name': 'general',
'code': 'GENE',
'type': 'general',
})
# Tax Cash Basis
- self.tax_cash_basis = self.env['account.tax'].create({
+ cls.tax_cash_basis = cls.env['account.tax'].create({
'name': 'cash basis 20%',
'type_tax_use': 'purchase',
- 'company_id': company.id,
+ 'company_id': cls.company.id,
'amount': 20,
'tax_exigibility': 'on_payment',
- 'cash_basis_transition_account_id': self.tax_waiting_account.id,
- 'cash_basis_base_account_id': self.tax_base_amount_account.id,
+ 'cash_basis_transition_account_id': cls.tax_waiting_account.id,
+ 'cash_basis_base_account_id': cls.tax_base_amount_account.id,
'invoice_repartition_line_ids': [
(0,0, {
'factor_percent': 100,
@@ -114,7 +137,7 @@ class TestReconciliation(AccountingTestCase):
(0,0, {
'factor_percent': 100,
'repartition_type': 'tax',
- 'account_id': self.tax_final_account.id,
+ 'account_id': cls.tax_final_account.id,
}),
],
'refund_repartition_line_ids': [
@@ -126,13 +149,29 @@ class TestReconciliation(AccountingTestCase):
(0,0, {
'factor_percent': 100,
'repartition_type': 'tax',
- 'account_id': self.tax_final_account.id,
+ 'account_id': cls.tax_final_account.id,
}),
],
})
+ cls.env['res.currency.rate'].create([
+ {
+ 'currency_id': cls.env.ref('base.EUR').id,
+ 'name': '2010-01-02',
+ 'rate': 1.0,
+ }, {
+ 'currency_id': cls.env.ref('base.USD').id,
+ 'name': '2010-01-02',
+ 'rate': 1.2834,
+ }, {
+ 'currency_id': cls.env.ref('base.USD').id,
+ 'name': time.strftime('%Y-06-05'),
+ 'rate': 1.5289,
+ }
+ ])
def _create_invoice(self, type='out_invoice', invoice_amount=50, currency_id=None, partner_id=None, date_invoice=None, payment_term_id=False, auto_validate=False):
date_invoice = date_invoice or time.strftime('%Y') + '-07-01'
+
invoice_vals = {
'type': type,
'partner_id': partner_id or self.partner_agrolait_id,
@@ -258,6 +297,11 @@ class TestReconciliationExec(TestReconciliation):
])
def test_statement_usd_invoice_chf_transaction_chf(self):
+ self.env['res.currency.rate'].create({
+ 'rate': 1.3086,
+ 'currency_id': self.env.ref('base.CHF').id,
+ 'name': '2010-01-02',
+ })
customer_move_lines, supplier_move_lines = self.make_customer_and_supplier_flows(self.currency_swiss_id, 50, self.bank_journal_usd, 42, 50, self.currency_swiss_id)
self.assertRecordValues(customer_move_lines, [
{'debit': 0.0, 'credit': 27.47, 'amount_currency': -50, 'currency_id': self.currency_swiss_id},
@@ -676,7 +720,7 @@ class TestReconciliationExec(TestReconciliation):
# Balance Debit = 18.75
# Counterpart Credit goes in Exchange diff
- dest_journal_id = self.env['account.journal'].search([('type', '=', 'purchase'), ('company_id', '=', self.env.ref('base.main_company').id)], limit=1)
+ dest_journal_id = self.env['account.journal'].search([('type', '=', 'purchase'), ('company_id', '=', self.company.id)], limit=1)
self.bank_journal_euro.write({'default_debit_account_id': self.account_rsa.id,
'default_credit_account_id': self.account_rsa.id})
@@ -686,17 +730,17 @@ class TestReconciliationExec(TestReconciliation):
self.env['res.currency.rate'].create({'name': time.strftime('%Y') + '-' + '07' + '-01',
'rate': 0.5,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id})
+ 'company_id': self.company.id})
self.env['res.currency.rate'].create({'name': time.strftime('%Y') + '-' + '08' + '-01',
'rate': 0.75,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id})
+ 'company_id': self.company.id})
self.env['res.currency.rate'].create({'name': time.strftime('%Y') + '-' + '09' + '-01',
'rate': 0.80,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id})
+ 'company_id': self.company.id})
# Preparing Invoices (from vendor)
invoice_a = self.env['account.move'].with_context(default_type='in_invoice').create({
@@ -727,7 +771,7 @@ class TestReconciliationExec(TestReconciliation):
'amount': 25,
'currency_id': self.currency_usd_id,
'journal_id': self.bank_journal_euro.id,
- 'company_id': self.env.ref('base.main_company').id,
+ 'company_id': self.company.id,
'payment_date': time.strftime('%Y') + '-' + '07' + '-01',
'partner_id': self.partner_agrolait_id,
'payment_method_id': self.env.ref('account.account_payment_method_manual_out').id,
@@ -739,7 +783,7 @@ class TestReconciliationExec(TestReconciliation):
'amount': 50,
'currency_id': self.currency_usd_id,
'journal_id': self.bank_journal_euro.id,
- 'company_id': self.env.ref('base.main_company').id,
+ 'company_id': self.company.id,
'payment_date': time.strftime('%Y') + '-' + '08' + '-01',
'partner_id': self.partner_agrolait_id,
'payment_method_id': self.env.ref('account.account_payment_method_manual_out').id,
@@ -751,7 +795,7 @@ class TestReconciliationExec(TestReconciliation):
'amount': 25,
'currency_id': self.currency_usd_id,
'journal_id': self.bank_journal_euro.id,
- 'company_id': self.env.ref('base.main_company').id,
+ 'company_id': self.company.id,
'payment_date': time.strftime('%Y') + '-' + '09' + '-01',
'partner_id': self.partner_agrolait_id,
'payment_method_id': self.env.ref('account.account_payment_method_manual_out').id,
@@ -840,13 +884,13 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.0,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': self.company.id
})
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-08-01',
'rate': 0.5,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': self.company.id
})
inv = self.create_invoice(invoice_amount=111, currency_id=self.currency_usd_id)
payment = self.env['account.payment'].create({
@@ -946,13 +990,13 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.0,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': self.company.id
})
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-08-01',
'rate': 0.5,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': self.company.id
})
inv = self.create_invoice(invoice_amount=111, currency_id=self.currency_usd_id)
payment = self.env['account.payment'].create({
@@ -994,7 +1038,7 @@ class TestReconciliationExec(TestReconciliation):
####
dest_journal_id = self.env['account.journal'].search(
[('type', '=', 'purchase'),
- ('company_id', '=', self.env.ref('base.main_company').id)],
+ ('company_id', '=', self.company.id)],
limit=1)
# Delete any old rate - to make sure that we use the ones we need.
@@ -1104,7 +1148,7 @@ class TestReconciliationExec(TestReconciliation):
# one is subject to a cash basis tax
# the other is not subject to tax
- company = self.env.ref('base.main_company')
+ company = self.company
company.tax_cash_basis_journal_id = self.cash_basis_journal
purchase_move = self.env['account.move'].create({
@@ -1196,7 +1240,7 @@ class TestReconciliationExec(TestReconciliation):
# with 2 payment terms
# And partial payment not martching any payment term
- company = self.env.ref('base.main_company')
+ company = self.company
company.tax_cash_basis_journal_id = self.cash_basis_journal
tax_cash_basis10percent = self.tax_cash_basis.copy({'amount': 10})
tax_waiting_account10 = self.tax_waiting_account.copy({
@@ -1395,7 +1439,7 @@ class TestReconciliationExec(TestReconciliation):
Taxes -848.16 USD 0.00 17,094.66
"""
- company = self.env.ref('base.main_company')
+ company = self.company
company.country_id = self.ref('base.us')
company.tax_cash_basis_journal_id = self.cash_basis_journal
@@ -1558,7 +1602,7 @@ class TestReconciliationExec(TestReconciliation):
Taxes -848.16 USD 0.00 17,094.66
"""
- company = self.env.ref('base.main_company')
+ company = self.company
company.country_id = self.ref('base.us')
company.tax_cash_basis_journal_id = self.cash_basis_journal
@@ -1698,7 +1742,7 @@ class TestReconciliationExec(TestReconciliation):
.debit, 17094.66)
def test_reconciliation_cash_basis_revert(self):
- company = self.env.ref('base.main_company')
+ company = self.company
company.tax_cash_basis_journal_id = self.cash_basis_journal
tax_cash_basis10percent = self.tax_cash_basis.copy({'amount': 10})
self.tax_waiting_account.reconcile = True
@@ -1763,7 +1807,7 @@ class TestReconciliationExec(TestReconciliation):
self.assertEqual(reverted_expected.full_reconcile_id, inv_line.full_reconcile_id)
def test_reconciliation_revert_future(self):
- company = self.env.ref('base.main_company')
+ company = self.company
company.tax_cash_basis_journal_id = self.cash_basis_journal
tax_cash_basis10percent = self.tax_cash_basis.copy({'amount': 10})
self.tax_waiting_account.reconcile = True
@@ -1832,6 +1876,7 @@ class TestReconciliationExec(TestReconciliation):
self.assertEqual(reverse_move.date, reverse_date)
def test_reconciliation_cash_basis_foreign_currency_low_values(self):
+ self.company.tax_cash_basis_journal_id = self.cash_basis_journal
journal = self.env['account.journal'].create({
'name': 'Bank', 'type': 'bank', 'code': 'THE',
'currency_id': self.currency_usd_id,
@@ -1842,7 +1887,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y-01-01'),
'rate': 1/17.0,
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id,
+ 'company_id': self.company.id,
})
move_form = Form(self.env['account.move'].with_context(default_type='out_invoice'))
@@ -1958,7 +2003,7 @@ class TestReconciliationExec(TestReconciliation):
self.assertEqual(aml.amount_residual, 0.0)
def test_inv_refund_foreign_payment_writeoff_domestic2(self):
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -1970,7 +2015,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.110600, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': self.company.id
})
inv1 = self.create_invoice(invoice_amount=800, currency_id=self.currency_usd_id)
inv2 = self.create_invoice(type="out_refund", invoice_amount=400, currency_id=self.currency_usd_id)
@@ -2025,7 +2070,7 @@ class TestReconciliationExec(TestReconciliation):
Reconciliation should be full
Invoices should be marked as paid
"""
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -2037,7 +2082,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.110600, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
inv1 = self.create_invoice(invoice_amount=658, currency_id=self.currency_usd_id)
inv2 = self.create_invoice(type="out_refund", invoice_amount=225, currency_id=self.currency_usd_id)
@@ -2096,7 +2141,7 @@ class TestReconciliationExec(TestReconciliation):
Reconciliation should be full
Invoices should be marked as paid
"""
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -2108,13 +2153,13 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.0, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-15',
'rate': 1.110600, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
inv1 = self._create_invoice(invoice_amount=658, currency_id=self.currency_usd_id, date_invoice=time.strftime('%Y') + '-07-01', auto_validate=True)
inv2 = self._create_invoice(type="out_refund", invoice_amount=225, currency_id=self.currency_usd_id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
@@ -2177,7 +2222,7 @@ class TestReconciliationExec(TestReconciliation):
Reconciliation should be full, without exchange difference
Invoices should be marked as paid
"""
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -2189,7 +2234,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.0, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
inv1 = self._create_invoice(invoice_amount=600, currency_id=self.currency_usd_id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
@@ -2241,7 +2286,7 @@ class TestReconciliationExec(TestReconciliation):
| 225.10 (250.00) INV 2 > Done in foreign
| 315.15 (350.00) PAYMENT > Done in domestic (the 350.00 is virtual, non stored)
"""
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -2253,7 +2298,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.1106, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
inv1 = self._create_invoice(invoice_amount=600, currency_id=self.currency_usd_id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
inv2 = self._create_invoice(type="out_refund", invoice_amount=250, currency_id=self.currency_usd_id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
@@ -2309,7 +2354,7 @@ class TestReconciliationExec(TestReconciliation):
})
foreign_1 = self.env['res.currency'].browse(self.currency_usd_id)
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -2328,7 +2373,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.1106, # Don't change this !
'currency_id': foreign_1.id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
inv1 = self._create_invoice(invoice_amount=600, currency_id=foreign_1.id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
inv2 = self._create_invoice(type="out_refund", invoice_amount=250, currency_id=foreign_1.id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
@@ -2384,7 +2429,7 @@ class TestReconciliationExec(TestReconciliation):
Reconciliation should be full, without exchange difference
Invoices should be marked as paid
"""
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -2396,7 +2441,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.1106, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
inv1 = self._create_invoice(invoice_amount=5980, currency_id=self.currency_usd_id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
@@ -2436,7 +2481,7 @@ class TestReconciliationExec(TestReconciliation):
Though it simulates going through the reconciliation widget
Because the WriteOff is on a different line than the payment
"""
- company = self.env.ref('base.main_company')
+ company = self.company
self.env['res.currency.rate'].search([]).unlink()
self.env['res.currency.rate'].create({
'name': time.strftime('%Y') + '-07-01',
@@ -2448,7 +2493,7 @@ class TestReconciliationExec(TestReconciliation):
'name': time.strftime('%Y') + '-07-01',
'rate': 1.1106, # Don't change this !
'currency_id': self.currency_usd_id,
- 'company_id': self.env.ref('base.main_company').id
+ 'company_id': company.id
})
inv1 = self._create_invoice(invoice_amount=5980, currency_id=self.currency_usd_id, date_invoice=time.strftime('%Y') + '-07-15', auto_validate=True)
diff --git a/addons/account/tests/test_reconciliation_matching_rules.py b/addons/account/tests/test_reconciliation_matching_rules.py
index 6b178fe0b79..466f60c4131 100644
--- a/addons/account/tests/test_reconciliation_matching_rules.py
+++ b/addons/account/tests/test_reconciliation_matching_rules.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-from odoo import fields
+from odoo import fields, tools
from odoo.addons.account.tests.account_test_classes import AccountingTestCase
from odoo.tests.common import Form
from odoo.tests import tagged
@@ -7,54 +7,48 @@ from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestReconciliationMatchingRules(AccountingTestCase):
- def _create_invoice_line(self, amount, partner, type):
- ''' Create an invoice on the fly.'''
- invoice_form = Form(self.env['account.move'].with_context(default_type=type))
- invoice_form.invoice_date = fields.Date.from_string('2019-09-01')
- invoice_form.partner_id = partner
- with invoice_form.invoice_line_ids.new() as invoice_line_form:
- invoice_line_form.name = 'xxxx'
- invoice_line_form.quantity = 1
- invoice_line_form.price_unit = amount
- invoice_line_form.tax_ids.clear()
- invoice = invoice_form.save()
- invoice.post()
- lines = invoice.line_ids
- return lines.filtered(lambda l: l.account_id.user_type_id.type in ('receivable', 'payable'))
-
- def _check_statement_matching(self, rules, expected_values, statements=None):
- if statements is None:
- statements = self.bank_st + self.cash_st
- statement_lines = statements.mapped('line_ids').sorted()
- matching_values = rules._apply_rules(statement_lines)
- for st_line_id, values in matching_values.items():
- values.pop('reconciled_lines', None)
- self.assertDictEqual(values, expected_values[st_line_id])
-
- def setUp(self):
- super(AccountingTestCase, self).setUp()
-
- self.account_pay = self.env['account.account'].search([('internal_type', '=', 'payable')], limit=1)
- self.account_liq = self.env['account.account'].search([('internal_type', '=', 'liquidity')], limit=1)
- self.account_rcv = self.env['account.account'].search([('internal_type', '=', 'receivable')], limit=1)
-
- self.partner_1 = self.env['res.partner'].create({'name': 'partner_1'})
- self.partner_2 = self.env['res.partner'].create({'name': 'partner_2'})
-
- self.invoice_line_1 = self._create_invoice_line(100, self.partner_1, 'out_invoice')
- self.invoice_line_2 = self._create_invoice_line(200, self.partner_1, 'out_invoice')
- self.invoice_line_3 = self._create_invoice_line(300, self.partner_1, 'in_refund')
- self.invoice_line_4 = self._create_invoice_line(1000, self.partner_2, 'in_invoice')
-
- current_assets_account = self.env['account.account'].search(
- [('user_type_id', '=', self.env.ref('account.data_account_type_current_assets').id)], limit=1)
- self.rule_0 = self.env['account.reconcile.model'].search([('company_id', '=', self.env.company.id), ('rule_type', '=', 'invoice_matching')])
- self.rule_1 = self.rule_0.copy()
- self.rule_1.account_id = current_assets_account
- self.rule_1.match_partner = True
- self.rule_1.match_partner_ids |= self.partner_1 + self.partner_2
- self.rule_2 = self.env['account.reconcile.model'].create({
+ @classmethod
+ def setUpClass(cls):
+ super(TestReconciliationMatchingRules, cls).setUpClass()
+ cls.company = cls.env.user.company_id
+ cls.account_pay = cls.a_pay
+ cls.account_liq = cls.bnk
+ cls.account_rcv = cls.a_recv
+
+ cls.partner_1 = cls.env['res.partner'].create({'name': 'partner_1', 'company_id': cls.company.id})
+ cls.partner_2 = cls.env['res.partner'].create({'name': 'partner_2', 'company_id': cls.company.id})
+
+ cls.invoice_line_1 = cls._create_invoice_line(100, cls.partner_1, 'out_invoice')
+ cls.invoice_line_2 = cls._create_invoice_line(200, cls.partner_1, 'out_invoice')
+ cls.invoice_line_3 = cls._create_invoice_line(300, cls.partner_1, 'in_refund')
+ cls.invoice_line_3.move_id.name = "RBILL/2018/0013" # Without demo data, avoid to match with the first invoice
+ cls.invoice_line_4 = cls._create_invoice_line(1000, cls.partner_2, 'in_invoice')
+
+ current_assets_account = cls.env['account.account'].search([
+ ('user_type_id', '=', cls.env.ref('account.data_account_type_current_assets').id),
+ ('company_id', '=', cls.company.id)], limit=1)
+
+ cls.rule_0 = cls.env['account.reconcile.model'].search([('company_id', '=', cls.env.company.id), ('rule_type', '=', 'invoice_matching')])
+ if not cls.rule_0:
+ cls.rule_0 = cls.env['account.reconcile.model'].sudo().create({
+ "name": 'Invoices Matching Rule',
+ "sequence": '1',
+ "rule_type": 'invoice_matching',
+ "auto_reconcile": False,
+ "match_nature": 'both',
+ "match_same_currency": True,
+ "match_total_amount": True,
+ "match_total_amount_param": 100,
+ "match_partner": True,
+ "company_id": cls.company.id,
+ })
+
+ cls.rule_1 = cls.rule_0.copy()
+ cls.rule_1.account_id = current_assets_account
+ cls.rule_1.match_partner = True
+ cls.rule_1.match_partner_ids |= cls.partner_1 + cls.partner_2
+ cls.rule_2 = cls.env['account.reconcile.model'].create({
'name': 'write-off model',
'rule_type': 'writeoff_suggestion',
'match_partner': True,
@@ -62,46 +56,72 @@ class TestReconciliationMatchingRules(AccountingTestCase):
'account_id': current_assets_account.id,
})
- invoice_number = self.invoice_line_1.move_id.name
+ invoice_number = cls.invoice_line_1.move_id.name
- self.bank_journal = self.env['account.journal'].search([('type', '=', 'bank')], limit=1)
+ cls.bank_journal = cls.env['account.journal'].search([('type', '=', 'bank'), ('company_id', '=', cls.company.id)], limit=1)
- self.bank_st = self.env['account.bank.statement'].create({
- 'name': 'test bank journal', 'journal_id': self.bank_journal.id,
+ cls.bank_st = cls.env['account.bank.statement'].create({
+ 'name': 'test bank journal', 'journal_id': cls.bank_journal.id,
})
- self.bank_line_1 = self.env['account.bank.statement.line'].create({
- 'statement_id': self.bank_st.id,
+ cls.bank_line_1 = cls.env['account.bank.statement.line'].create({
+ 'statement_id': cls.bank_st.id,
'name': 'invoice %s-%s' % (invoice_number.split('/')[1], invoice_number.split('/')[2]),
- 'partner_id': self.partner_1.id,
+ 'partner_id': cls.partner_1.id,
'amount': 100,
'sequence': 1,
})
- self.bank_line_2 = self.env['account.bank.statement.line'].create({
- 'statement_id': self.bank_st.id,
+ cls.bank_line_2 = cls.env['account.bank.statement.line'].create({
+ 'statement_id': cls.bank_st.id,
'name': 'xxxxx',
- 'partner_id': self.partner_1.id,
+ 'partner_id': cls.partner_1.id,
'amount': 600,
'sequence': 2,
})
- cash_journal = self.env['account.journal'].search([('type', '=', 'cash')], limit=1)
- self.cash_st = self.env['account.bank.statement'].create({
+ cash_journal = cls.env['account.journal'].search([('type', '=', 'cash'), ('company_id', '=', cls.company.id)], limit=1)
+ cls.cash_st = cls.env['account.bank.statement'].create({
'name': 'test cash journal', 'journal_id': cash_journal.id,
})
- self.cash_line_1 = self.env['account.bank.statement.line'].create({
- 'statement_id': self.cash_st.id,
+ cls.cash_line_1 = cls.env['account.bank.statement.line'].create({
+ 'statement_id': cls.cash_st.id,
'name': 'yyyyy',
- 'partner_id': self.partner_2.id,
+ 'partner_id': cls.partner_2.id,
'amount': -1000,
'sequence': 1,
})
- self.tax21 = self.env['account.tax'].create({
+ cls.tax21 = cls.env['account.tax'].create({
'name': '21%',
'type_tax_use': 'purchase',
'amount': 21,
})
+ @classmethod
+ def _create_invoice_line(cls, amount, partner, type):
+ ''' Create an invoice on the fly.'''
+ invoice_form = Form(cls.env['account.move'].with_context(default_type=type))
+ invoice_form.invoice_date = fields.Date.from_string('2019-09-01')
+ invoice_form.partner_id = partner
+ with invoice_form.invoice_line_ids.new() as invoice_line_form:
+ invoice_line_form.name = 'xxxx'
+ invoice_line_form.quantity = 1
+ invoice_line_form.price_unit = amount
+ invoice_line_form.tax_ids.clear()
+ invoice = invoice_form.save()
+ invoice.post()
+ lines = invoice.line_ids
+ return lines.filtered(lambda l: l.account_id.user_type_id.type in ('receivable', 'payable'))
+
+ def _check_statement_matching(self, rules, expected_values, statements=None):
+ if statements is None:
+ statements = self.bank_st + self.cash_st
+ statement_lines = statements.mapped('line_ids').sorted()
+ matching_values = rules._apply_rules(statement_lines)
+ for st_line_id, values in matching_values.items():
+ values.pop('reconciled_lines', None)
+ self.assertDictEqual(values, expected_values[st_line_id])
+
+
def test_matching_fields(self):
''' Test all fields used to restrict the rules's applicability.'''
@@ -236,7 +256,7 @@ class TestReconciliationMatchingRules(AccountingTestCase):
self.bank_line_1.amount += 5
# Check match_partner_category_ids.
- test_category = self.env.ref('base.res_partner_category_8')
+ test_category = self.env['res.partner.category'].create({'name': 'Consulting Services'})
self.partner_2.category_id = test_category
self.rule_1.match_partner_category_ids |= test_category
self._check_statement_matching(self.rule_1, {
@@ -367,11 +387,14 @@ class TestReconciliationMatchingRules(AccountingTestCase):
move.post()
move_reversed = move._reverse_moves()
+
self.assertTrue(move_reversed.exists())
bank_st = self.env['account.bank.statement'].create({
'name': 'test bank journal', 'journal_id': self.bank_journal.id,
})
+ bank_st.journal_id.default_credit_account_id = payment_bnk_line.account_id
+ bank_st.journal_id.default_debit_account_id = payment_bnk_line.account_id
bank_line_1 = self.env['account.bank.statement.line'].create({
'statement_id': bank_st.id,
'name': '8',
@@ -379,7 +402,7 @@ class TestReconciliationMatchingRules(AccountingTestCase):
'amount': -10,
'sequence': 1,
})
-
+ bank_st.flush()
expected_values = {
bank_line_1.id: {'aml_ids': [payment_bnk_line.id], 'model': self.rule_0}
}
diff --git a/addons/account/tests/test_tax.py b/addons/account/tests/test_tax.py
index 48119a58cba..a9adc25cf7e 100644
--- a/addons/account/tests/test_tax.py
+++ b/addons/account/tests/test_tax.py
@@ -6,77 +6,78 @@ from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestTax(AccountTestUsers):
- def setUp(self):
- super(TestTax, self).setUp()
+ @classmethod
+ def setUpClass(cls):
+ super(TestTax, cls).setUpClass()
- self.fixed_tax = self.tax_model.create({
+ cls.fixed_tax = cls.tax_model.create({
'name': "Fixed tax",
'amount_type': 'fixed',
'amount': 10,
'sequence': 1,
})
- self.fixed_tax_bis = self.tax_model.create({
+ cls.fixed_tax_bis = cls.tax_model.create({
'name': "Fixed tax bis",
'amount_type': 'fixed',
'amount': 15,
'sequence': 2,
})
- self.percent_tax = self.tax_model.create({
+ cls.percent_tax = cls.tax_model.create({
'name': "Percent tax",
'amount_type': 'percent',
'amount': 10,
'sequence': 3,
})
- self.percent_tax_bis = self.tax_model.create({
+ cls.percent_tax_bis = cls.tax_model.create({
'name': "Percent tax bis",
'amount_type': 'percent',
'amount': 10,
'sequence': 4,
})
- self.division_tax = self.tax_model.create({
+ cls.division_tax = cls.tax_model.create({
'name': "Division tax",
'amount_type': 'division',
'amount': 10,
'sequence': 4,
})
- self.group_tax = self.tax_model.create({
+ cls.group_tax = cls.tax_model.create({
'name': "Group tax",
'amount_type': 'group',
'amount': 0,
'sequence': 5,
'children_tax_ids': [
- (4, self.fixed_tax.id, 0),
- (4, self.percent_tax.id, 0)
+ (4, cls.fixed_tax.id, 0),
+ (4, cls.percent_tax.id, 0)
]
})
- self.group_tax_bis = self.tax_model.create({
+ cls.group_tax_bis = cls.tax_model.create({
'name': "Group tax bis",
'amount_type': 'group',
'amount': 0,
'sequence': 6,
'children_tax_ids': [
- (4, self.fixed_tax.id, 0),
- (4, self.percent_tax.id, 0)
+ (4, cls.fixed_tax.id, 0),
+ (4, cls.percent_tax.id, 0)
]
})
- self.group_of_group_tax = self.tax_model.create({
+ cls.group_of_group_tax = cls.tax_model.create({
'name': "Group of group tax",
'amount_type': 'group',
'amount': 0,
'sequence': 7,
'children_tax_ids': [
- (4, self.group_tax.id, 0),
- (4, self.group_tax_bis.id, 0)
+ (4, cls.group_tax.id, 0),
+ (4, cls.group_tax_bis.id, 0)
]
})
- self.tax_with_no_account = self.tax_model.create({
+ cls.tax_with_no_account = cls.tax_model.create({
'name': "Tax with no account",
'amount_type': 'fixed',
'amount': 0,
'sequence': 8,
})
- some_account = self.env['account.account'].search([], limit=1)
- self.tax_with_account = self.tax_model.create({
+ some_account = cls.env['account.account'].search([], limit=1)
+ cls.tax_with_account = cls.tax_model.create({
'name': "Tax with account",
'amount_type': 'fixed',
'amount': 0,
@@ -106,9 +107,9 @@ class TestTax(AccountTestUsers):
}),
],
})
- self.bank_journal = self.env['account.journal'].search([('type', '=', 'bank'), ('company_id', '=', self.account_manager.company_id.id)])[0]
- self.bank_account = self.bank_journal.default_debit_account_id
- self.expense_account = self.env['account.account'].search([('user_type_id.type', '=', 'payable')], limit=1) #Should be done by onchange later
+ cls.bank_journal = cls.env['account.journal'].search([('type', '=', 'bank'), ('company_id', '=', cls.account_manager.company_id.id)])[0]
+ cls.bank_account = cls.bank_journal.default_debit_account_id
+ cls.expense_account = cls.env['account.account'].search([('user_type_id.type', '=', 'payable')], limit=1) #Should be done by onchange later
def _check_compute_all_results(self, total_included, total_excluded, taxes, res):
self.assertAlmostEqual(res['total_included'], total_included)