初始提交

This commit is contained in:
2026-11-04 19:58:07 +08:00
commit 53b7d22429
829 changed files with 469986 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
from . import test_account_fiscal_year
from . import test_account_bank_statement
from . import test_account_bank_statement_tour
from . import test_account_payment
from . import test_prediction
from . import test_reconciliation_matching_rules
from . import test_account_auto_reconcile_wizard
from . import test_account_reconcile_wizard
from . import test_deferred_management
from . import test_ui
from . import test_signature
from . import test_change_lock_date_wizard
from . import test_journal_item_split

View File

@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-
from odoo import Command
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import freeze_time
class TestBankRecWidgetCommon(AccountTestInvoicingCommon):
_test_user_groups = None # FIXME list needed groups
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.other_currency = cls.setup_other_currency('EUR')
cls.other_currency_2 = cls.setup_other_currency('CAD', rounding=0.001, rates=[('2016-01-01', 6.0), ('2017-01-01', 4.0)])
cls.other_currency_3 = cls.setup_other_currency('XAF', rounding=0.001, rates=[('2016-01-01', 12.0), ('2017-01-01', 8.0)])
cls.early_payment_term = cls.env['account.payment.term'].create({
'name': "Early_payment_term",
'company_id': cls.company_data['company'].id,
'discount_percentage': 10,
'discount_days': 10,
'early_discount': True,
'line_ids': [
Command.create({
'value': 'percent',
'value_amount': 100,
'nb_days': 20,
}),
],
})
@classmethod
@freeze_time('2017-01-01')
def _create_invoice_one_line_reco(cls, **invoice_args):
''' Create an invoice on the fly.'''
invoice = cls._create_invoice_one_line(**invoice_args, post=True)
return invoice.line_ids.filtered(
lambda l: l.account_id.account_type in ('asset_receivable', 'liability_payable'))
@classmethod
def _create_st_line(cls, amount, date='2019-01-01', payment_ref='turlututu', update_create_date=True, **kwargs):
st_line = cls.env['account.bank.statement.line'].create({
'amount': amount,
'date': date,
'payment_ref': payment_ref,
'journal_id': kwargs.get('journal_id', cls.company_data['default_journal_bank'].id),
**kwargs,
})
if update_create_date:
# The automatic reconcile cron checks the create_date when considering st_lines to run on.
# create_date is a protected field so this is the only way to set it correctly
cls.env.cr.execute("UPDATE account_bank_statement_line SET create_date = %s WHERE id=%s",
(st_line.date, st_line.id))
return st_line

View File

@@ -0,0 +1,245 @@
from odoo import fields
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.exceptions import UserError
from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestAccountAutoReconcileWizard(AccountTestInvoicingCommon):
""" Tests the account automatic reconciliation and its wizard. """
_test_user_groups = None # FIXME list needed groups
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.comp_curr = cls.company_data['currency']
cls.foreign_curr = cls.setup_other_currency('EUR')
cls.misc_journal = cls.company_data['default_journal_misc']
cls.partners = cls.partner_a + cls.partner_b
cls.receivable_account = cls.company_data['default_account_receivable']
cls.payable_account = cls.company_data['default_account_payable']
cls.revenue_account = cls.company_data['default_account_revenue']
cls.test_date = fields.Date.from_string('2016-01-01')
def _create_many_lines(self):
self.line_1_group_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
self.line_2_group_1 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
self.line_3_group_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-03', partner=self.partner_a)
self.line_4_group_1 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-04', partner=self.partner_a)
self.line_5_group_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-05', partner=self.partner_a)
self.group_1 = self.line_1_group_1 + self.line_2_group_1 + self.line_3_group_1 + self.line_4_group_1 + self.line_5_group_1
self.line_1_group_2 = self.create_line_for_reconciliation(500.0, 500.0, self.comp_curr, '2016-01-01', partner=self.partner_b)
self.line_2_group_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.comp_curr, '2016-01-01', partner=self.partner_b)
self.line_3_group_2 = self.create_line_for_reconciliation(500.0, 500.0, self.comp_curr, '2017-01-02', partner=self.partner_b)
self.line_4_group_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.comp_curr, '2017-01-02', partner=self.partner_b)
self.group_2 = self.line_1_group_2 + self.line_2_group_2 + self.line_3_group_2 + self.line_4_group_2
self.line_1_group_3 = self.create_line_for_reconciliation(1500.0, 3000.0, self.foreign_curr, '2016-01-01', partner=self.partner_b)
self.line_2_group_3 = self.create_line_for_reconciliation(-1000.0, -3000.0, self.foreign_curr, '2017-01-01', partner=self.partner_b)
self.line_3_group_3 = self.create_line_for_reconciliation(3000.0, 3000.0, self.comp_curr, '2016-01-01', partner=self.partner_b)
self.line_4_group_3 = self.create_line_for_reconciliation(-3000.0, -3000.0, self.comp_curr, '2016-01-01', partner=self.partner_b)
self.group_3 = self.line_1_group_3 + self.line_2_group_3 + self.line_3_group_3 + self.line_4_group_3
self.line_1_group_4 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', account_1=self.payable_account, partner=self.partner_a)
self.line_2_group_4 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', account_1=self.payable_account, partner=self.partner_a)
self.group_4 = self.line_1_group_4 + self.line_2_group_4
def test_auto_reconcile_one_to_one(self):
self._create_many_lines()
should_be_reconciled = self.line_1_group_1 + self.line_2_group_1 + self.line_3_group_1 + self.line_4_group_1 \
+ self.line_1_group_2 + self.line_2_group_2 \
+ self.line_1_group_3 + self.line_2_group_3 + self.line_3_group_3 + self.line_4_group_3
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'account_ids': self.receivable_account.ids,
'partner_ids': self.partners.ids,
'search_mode': 'one_to_one',
})
wizard.auto_reconcile()
self.assertTrue(should_be_reconciled.full_reconcile_id)
self.assertEqual(self.line_1_group_1.full_reconcile_id, self.line_2_group_1.full_reconcile_id,
"Entries should be reconciled together since they are in the same group and have closer dates.")
self.assertEqual(self.line_3_group_1.full_reconcile_id, self.line_4_group_1.full_reconcile_id,
"Entries should be reconciled together since they are in the same group and have closer dates.")
self.assertEqual(self.line_1_group_2.full_reconcile_id, self.line_1_group_2.full_reconcile_id,
"Entries should be reconciled together since they are in the same group and have closer dates.")
self.assertEqual(self.line_1_group_3.full_reconcile_id, self.line_2_group_3.full_reconcile_id,
"Entries should be reconciled together since they are in the same group and have closer dates.")
self.assertEqual(self.line_3_group_3.full_reconcile_id, self.line_4_group_3.full_reconcile_id,
"Entries should be reconciled together since they are in the same group and have closer dates.")
self.assertNotEqual(self.line_2_group_3.full_reconcile_id, self.line_3_group_3.full_reconcile_id,
"Entries should NOT be reconciled together as they are of different currencies.")
self.assertFalse(self.line_5_group_1.reconciled,
"This entry shouldn't be reconciled since group 1 has an odd number of lines, they can't all be reconciled, and it's the most recent one.")
self.assertFalse((self.line_3_group_2 + self.line_4_group_2).full_reconcile_id,
"Entries shouldn't be reconciled since it's outside of accepted date range of the wizard.")
self.assertFalse((self.line_1_group_4 + self.line_2_group_4).full_reconcile_id,
"Entries shouldn't be reconciled since their account is out of the wizard's scope.")
def test_auto_reconcile_zero_balance(self):
self._create_many_lines()
should_be_reconciled = self.line_1_group_2 + self.line_2_group_2 + self.group_3
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'account_ids': self.receivable_account.ids,
'partner_ids': self.partners.ids,
'search_mode': 'zero_balance',
})
wizard.auto_reconcile()
self.assertTrue(should_be_reconciled.full_reconcile_id)
self.assertFalse(self.group_1.full_reconcile_id,
"Entries shouldn't be reconciled since their total balance is not zero.")
self.assertEqual((self.line_1_group_2 + self.line_2_group_2).mapped('matching_number'), [self.line_1_group_2.matching_number] * 2,
"Entries should be reconciled together as their total balance is zero.")
self.assertEqual((self.line_1_group_3 + self.line_2_group_3).mapped('matching_number'), [self.line_1_group_3.matching_number] * 2,
"Entries should be reconciled together as their total balance is zero with the same currency.")
self.assertEqual((self.line_3_group_3 + self.line_4_group_3).mapped('matching_number'), [self.line_3_group_3.matching_number] * 2,
"Lines 3 and 4 are reconciled but not with two first lines since their currency is different.")
self.assertFalse(self.group_4.full_reconcile_id,
"Entries shouldn't be reonciled since their account is out of the wizard's scope.")
def test_nothing_to_auto_reconcile(self):
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'account_ids': self.receivable_account.ids,
'partner_ids': self.partners.ids,
'search_mode': 'zero_balance',
})
with self.assertRaises(UserError):
wizard.auto_reconcile()
def test_auto_reconcile_no_account_nor_partner_one_to_one(self):
self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
})
reconciled_amls = wizard._auto_reconcile_one_to_one()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_auto_reconcile_no_account_nor_partner_zero_balance(self):
self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
})
reconciled_amls = wizard._auto_reconcile_zero_balance()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_auto_reconcile_no_account_one_to_one(self):
self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'partner_ids': self.partners.ids,
})
reconciled_amls = wizard._auto_reconcile_one_to_one()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_auto_reconcile_no_account_zero_balance(self):
self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'partner_ids': self.partners.ids,
})
reconciled_amls = wizard._auto_reconcile_zero_balance()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_auto_reconcile_no_partner_one_to_one(self):
self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'account_ids': self.receivable_account.ids,
})
reconciled_amls = wizard._auto_reconcile_one_to_one()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_auto_reconcile_no_partner_zero_balance(self):
self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'account_ids': self.receivable_account.ids,
})
reconciled_amls = wizard._auto_reconcile_zero_balance()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_auto_reconcile_rounding_one_to_one(self):
""" Checks that two lines with different values, currency rounding aside, are reconciled in one-to-one mode. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
line_2 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
# Need to manually update the values to bypass ORM
self.env.cr.execute(
"""
UPDATE account_move_line SET amount_residual_currency = 1000.0000001 WHERE id = %(line_1_id)s;
UPDATE account_move_line SET amount_residual_currency = -999.999999 WHERE id = %(line_2_id)s;
""",
{'line_1_id': line_1.id, 'line_2_id': line_2.id}
)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'account_ids': self.receivable_account.ids,
})
reconciled_amls = wizard._auto_reconcile_one_to_one()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_auto_reconcile_rounding_zero_balance(self):
""" Checks that two lines with different values, currency rounding aside, are reconciled in zero balance mode. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-01', partner=self.partner_a)
line_2 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-02', partner=self.partner_a)
# Need to manually update the values to bypass ORM
self.env.cr.execute(
"""
UPDATE account_move_line SET amount_residual_currency = 1000.0000001 WHERE id = %(line_1_id)s;
UPDATE account_move_line SET amount_residual_currency = -999.999999 WHERE id = %(line_2_id)s;
""",
{'line_1_id': line_1.id, 'line_2_id': line_2.id}
)
wizard = self.env['account.auto.reconcile.wizard'].new({
'from_date': '2016-01-01',
'to_date': '2017-01-01',
'account_ids': self.receivable_account.ids,
})
reconciled_amls = wizard._auto_reconcile_zero_balance()
self.assertTrue(reconciled_amls.full_reconcile_id)
def test_preset_wizard(self):
""" Tests that giving lines_ids to wizard presets correctly values. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-30', partner=self.partner_a)
line_2 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.comp_curr, '2016-01-31', partner=self.partner_a)
wizard = self.env['account.auto.reconcile.wizard'].with_context(domain=[('id', 'in', (line_1 + line_2).ids)]).create({})
self.assertRecordValues(wizard, [{
'account_ids': self.receivable_account.ids,
'partner_ids': self.partner_a.ids,
'from_date': fields.Date.from_string('2016-01-30'),
'to_date': fields.Date.from_string('2016-01-31'),
'search_mode': 'zero_balance',
}])
line_3 = self.create_line_for_reconciliation(1000.0, 1000.0, self.comp_curr, '2016-01-31', partner=self.partner_a)
line_4 = self.create_line_for_reconciliation(-500.0, -500.0, self.comp_curr, '2016-02-28', partner=None)
wizard = self.env['account.auto.reconcile.wizard'].with_context(domain=[('id', 'in', (line_3 + line_4).ids)]).create({})
self.assertRecordValues(wizard, [{
'account_ids': self.receivable_account.ids,
'partner_ids': [],
'from_date': fields.Date.from_string('2016-01-31'),
'to_date': fields.Date.from_string('2016-02-28'),
'search_mode': 'one_to_one',
}])

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,80 @@
from requests import Session, PreparedRequest, Response
from .common import TestBankRecWidgetCommon
from odoo.tests import tagged, HttpCase
@tagged('post_install', '-at_install')
class TestAccountBankStatementTour(TestBankRecWidgetCommon, HttpCase):
_test_user_groups = None # FIXME list needed groups
@classmethod
def _request_handler(cls, s: Session, r: PreparedRequest, /, **kw):
# mock odoofin requests
if 'proxy/v2/get_dashboard_institutions' in r.url:
r = Response()
r.status_code = 200
r.json = list
return r
return super()._request_handler(s, r, **kw)
def test_tour_bank_rec_widget(self):
self.partner_a.name = "AAAA" # To have this partner as the first one in the list
self._create_invoice_one_line_reco(partner_id=self.partner_a.id, price_unit=100.0)
self._create_invoice_one_line_reco(partner_id=self.partner_a.id, price_unit=150.0)
self.env['account.bank.statement'].create({
'name': 'Test Statement',
'journal_id': self.company_data['default_journal_bank'].id,
'date': '2019-01-01',
})
self.start_tour('/odoo', 'account_accountant_bank_rec_widget', login=self.env.user.login)
def test_tour_bank_reconciliation_widget_reload_activities_when_add_a_new_one(self):
self._create_st_line(amount=100.0)
self.start_tour('/odoo', 'account_accountant_bank_reconciliation_widget_reload_activies_when_add_a_new_one', login=self.env.user.login)
def test_tour_set_partner_with_child_contact(self):
""" Test that a contact that has a parent contact can't be selected via the 'Set Partner' button """
partner = self.env['res.partner'].create({'name': 'test child contact', 'parent_id': self.partner_a.id})
self._create_invoice_one_line_reco(partner_id=partner.id, price_unit=100.0)
self.start_tour('/odoo', 'account_accountant_set_partner_with_child_contact', login=self.env.user.login)
def test_tour_bank_rec_set_partner_branch_company(self):
"""
Test that the partner lookup in bank reconciliation uses the 'parent_of' domain,
making contacts of ancestor companies visible when reconciling from a branch company.
"""
# Create a branch company whose parent is the main test company
branch_company = self.env['res.company'].create({
'name': 'Test Branch',
'parent_id': self.company_data['company'].id,
})
# Partner linked to the parent company — must appear in the branch's partner lookup
self.env['res.partner'].create({
'name': 'AAAA Parent Partner',
'company_id': self.company_data['company'].id,
})
branch_journal = self.env['account.journal'].with_company(branch_company).create({
'name': 'Branch Bank',
'type': 'bank',
'code': 'BBNK',
'suspense_account_id': self.company_data['default_journal_bank'].suspense_account_id.id,
})
self.env['account.bank.statement.line'].with_company(branch_company).create({
'amount': 100.0,
'date': '2019-01-01',
'payment_ref': 'branch line',
'journal_id': branch_journal.id,
})
# Switch the user to the branch company so the dashboard shows the branch journal
self.env.user.write({
'company_ids': [(4, branch_company.id)],
'company_id': branch_company.id,
})
self.start_tour(
'/odoo',
'account_accountant_bank_rec_set_partner_branch_company',
login=self.env.user.login,
)

View File

@@ -0,0 +1,209 @@
# -*- coding: utf-8 -*-
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.exceptions import ValidationError
from odoo.tests import tagged
from odoo import fields
@tagged('post_install', '-at_install')
class TestFiscalPosition(AccountTestInvoicingCommon):
_test_user_groups = None # FIXME list needed groups
def check_compute_fiscal_year(self, company, date, expected_date_from, expected_date_to):
'''Compute the fiscal year at a certain date for the company passed as parameter.
Then, check if the result matches the 'expected_date_from'/'expected_date_to' dates.
:param company: The company.
:param date: The date belonging to the fiscal year.
:param expected_date_from: The expected date_from after computation.
:param expected_date_to: The expected date_to after computation.
'''
current_date = fields.Date.from_string(date)
res = company.compute_fiscalyear_dates(current_date)
self.assertEqual(res['date_from'], fields.Date.from_string(expected_date_from))
self.assertEqual(res['date_to'], fields.Date.from_string(expected_date_to))
def test_default_fiscal_year(self):
'''Basic case with a fiscal year xxxx-01-01 - xxxx-12-31.'''
company = self.env.company
company.fiscalyear_last_day = 31
company.fiscalyear_last_month = '12'
self.check_compute_fiscal_year(
company,
'2017-12-31',
'2017-01-01',
'2017-12-31',
)
self.check_compute_fiscal_year(
company,
'2017-01-01',
'2017-01-01',
'2017-12-31',
)
def test_leap_fiscal_year_1(self):
'''Case with a leap year ending the 29 February.'''
company = self.env.company
company.fiscalyear_last_day = 29
company.fiscalyear_last_month = '2'
self.check_compute_fiscal_year(
company,
'2016-02-29',
'2015-03-01',
'2016-02-29',
)
self.check_compute_fiscal_year(
company,
'2015-03-01',
'2015-03-01',
'2016-02-29',
)
def test_leap_fiscal_year_2(self):
'''Case with a leap year ending the 28 February.'''
company = self.env.company
company.fiscalyear_last_day = 28
company.fiscalyear_last_month = '2'
self.check_compute_fiscal_year(
company,
'2016-02-29',
'2015-03-01',
'2016-02-29',
)
self.check_compute_fiscal_year(
company,
'2016-03-01',
'2016-03-01',
'2017-02-28',
)
def test_custom_fiscal_year(self):
'''Case with custom fiscal years.'''
company = self.env.company
company.fiscalyear_last_day = 31
company.fiscalyear_last_month = '12'
# Create custom fiscal year covering the 6 first months of 2017.
self.env['account.fiscal.year'].create({
'name': '6 month 2017',
'date_from': '2017-01-01',
'date_to': '2017-05-31',
'company_id': company.id,
})
# Check before the custom fiscal year).
self.check_compute_fiscal_year(
company,
'2017-02-01',
'2017-01-01',
'2017-05-31',
)
# Check after the custom fiscal year.
self.check_compute_fiscal_year(
company,
'2017-11-01',
'2017-06-01',
'2017-12-31',
)
# Create custom fiscal year covering the 3 last months of 2017.
self.env['account.fiscal.year'].create({
'name': 'last 3 month 2017',
'date_from': '2017-10-01',
'date_to': '2017-12-31',
'company_id': company.id,
})
# Check inside the custom fiscal years.
self.check_compute_fiscal_year(
company,
'2017-07-01',
'2017-06-01',
'2017-09-30',
)
def test_sequencing_invoice(self):
self.ensure_installed("account_fiscal_year")
self.env['account.fiscal.year'].create([
{
'name': 'end 2024 - 2026',
'date_from': '2024-12-01',
'date_to': '2026-03-31',
'company_id': self.company.id,
},
{
'name': '2026 - 2027',
'date_from': '2026-04-01',
'date_to': '2027-12-31',
'company_id': self.company.id,
},
])
for date, expected_name in [
('2024-12-04', 'INV/24-26/0001'),
('2025-05-15', 'INV/24-26/0002'),
('2026-03-15', 'INV/24-26/0003'),
('2026-04-15', 'INV/26-27/0001'),
('2027-01-01', 'INV/26-27/0001'),
# Back to normal years
('2028-02-02', 'INV/2028/0001'),
]:
move = self._create_invoice(date=date, journal=self.company_data['default_journal_sale'], post=True)
self.assertEqual(move.name, expected_name)
def test_fiscal_year_overlap_constrain(self):
company = self.env.company
self.env['account.fiscal.year'].create({
'name': 'FY 2026',
'date_from': '2026-01-01',
'date_to': '2026-12-31',
'company_id': company.id
})
with self.assertRaises(ValidationError):
self.env['account.fiscal.year'].create({
'name': 'FY 2026 (invalid dates)',
'date_from': '2026-01-01',
'date_to': '2025-12-31',
'company_id': company.id
})
with self.assertRaises(ValidationError):
self.env['account.fiscal.year'].create({
'name': 'FY 2026 (start overlap)',
'date_from': '2026-05-01',
'date_to': '2027-05-01',
'company_id': company.id
})
with self.assertRaises(ValidationError):
self.env['account.fiscal.year'].create({
'name': 'FY 2026 (end overlap)',
'date_from': '2025-05-01',
'date_to': '2026-05-01',
'company_id': company.id
})
with self.assertRaises(ValidationError):
self.env['account.fiscal.year'].create({
'name': 'FY 2026 (smaller year)',
'date_from': '2026-05-01',
'date_to': '2026-08-01',
'company_id': company.id
})
with self.assertRaises(ValidationError):
self.env['account.fiscal.year'].create({
'name': 'FY 2026 (larger year)',
'date_from': '2025-05-01',
'date_to': '2027-08-01',
'company_id': company.id
})

View File

@@ -0,0 +1,41 @@
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.tests import tagged
@tagged('post_install', '-at_install')
class TestAccountBillPayment(AccountTestInvoicingCommon):
_test_user_groups = None # FIXME list needed groups
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.bank_journal_1 = cls.company_data['default_journal_bank']
def test_bill_state_change_on_payment_state(self):
"""Test that bill payment state changes correctly when payment state transitions occur.
• Draft payment case: Bill state reverts to 'not_paid' when payment is drafted
• Payment unlink case: Bill state reverts to 'not_paid' when payment is deleted
"""
bill = self.init_invoice('in_invoice', post=True, partner=self.partner_a, products=self.product_a)
# We have to test it without any Outstanding Payment account set in Journal
self.bank_journal_1.outbound_payment_method_line_ids.payment_account_id = False
payment = self.env['account.payment.register']\
.with_context(active_model='account.move', active_ids=bill.ids)\
.create({})\
._create_payments()
self.assertEqual(bill.payment_state, self.env['account.move']._get_invoice_in_payment_state())
payment.action_draft()
self.assertEqual(payment.state, 'draft')
# With accountant module is installed, payment has no move_id, so bill goes to 'not_paid'.
# Without it, payment has move_id (journal entry), so bill stays 'paid'.
accountant_module = self.env['ir.module.module'].search([
('name', '=', 'accountant'), ('state', '=', 'installed')])
expected_state = 'not_paid' if accountant_module else 'paid'
self.assertEqual(payment.invoice_ids.payment_state, expected_state)
payment.unlink()
self.assertEqual(bill.payment_state, 'not_paid')

View File

@@ -0,0 +1,944 @@
import re
from odoo import Command, fields
from odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged('post_install', '-at_install')
class TestAccountReconcileWizard(AccountTestInvoicingCommon):
""" Tests the account reconciliation and its wizard. """
_test_user_groups = None # FIXME list needed groups
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.receivable_account = cls.company_data['default_account_receivable']
cls.payable_account = cls.company_data['default_account_payable']
cls.revenue_account = cls.company_data['default_account_revenue']
cls.payable_account_2 = cls.env['account.account'].create({
'name': 'Payable Account 2',
'account_type': 'liability_payable',
'code': 'PAY2.TEST',
})
cls.write_off_account = cls.env['account.account'].create({
'name': 'Write-Off Account',
'account_type': 'liability_current',
'code': 'WO.TEST',
})
cls.analytic_account = cls.env['account.analytic.account'].create({
'name': 'Reconcile Wizard Analytic Account',
'plan_id': cls.env['account.analytic.plan'].create({'name': 'Reconcile Wizard Plan'}).id,
})
cls.misc_journal = cls.company_data['default_journal_misc']
cls.test_date = fields.Date.from_string('2016-01-01')
cls.company_currency = cls.company_data['currency']
cls.foreign_currency = cls.setup_other_currency('EUR')
cls.foreign_currency_2 = cls.setup_other_currency('XAF', rates=[('2015-12-31', 6.0), ('2016-12-31', 4.0)])
# -------------------------------------------------------------------------
# HELPERS
# -------------------------------------------------------------------------
def assertWizardReconcileValues(self, selected_lines, input_values, wo_expected_values, expected_transfer_values=None):
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=selected_lines.ids,
).new(input_values)
if expected_transfer_values:
transfer_move = wizard.create_transfer()
# transfer move values
self.assertRecordValues(transfer_move.line_ids.sorted('balance'), expected_transfer_values)
# transfer warning message
self.assertTrue(wizard.transfer_warning_message)
regex_match = re.findall(r'([+-]*\d*,*\d+\.*\d+)', wizard.transfer_warning_message)
# match transferred amount
self.assertEqual(
float(regex_match[0].replace(',', '')),
transfer_move.amount_total_in_currency_signed or transfer_move.amount_total_signed
)
transfer_from_account = transfer_move.line_ids.filtered(lambda aml: 'Transfer from' in aml.name).account_id
transfer_to_account = transfer_move.line_ids.account_id - transfer_from_account
transfer_from_amls = transfer_move.line_ids.filtered(lambda aml: aml.account_id == transfer_from_account)
transfer_amount = sum(aml.balance for aml in transfer_from_amls)
# match account codes
if transfer_amount > 0:
self.assertEqual(regex_match[1:], [transfer_from_account.code, transfer_to_account.code])
else:
self.assertEqual(regex_match[1:], [transfer_to_account.code, transfer_from_account.code])
write_off_move = wizard.create_write_off()
self.assertRecordValues(write_off_move.line_ids.sorted('balance'), wo_expected_values)
wizard.reconcile()
if wizard.allow_partials or (
wizard.edit_mode
and wizard.reco_currency_id.compare_amounts(wizard.edit_mode_amount_currency, wizard.amount_currency)
):
# partial reconcile
self.assertTrue(len(selected_lines.matched_debit_ids) > 0 or len(selected_lines.matched_credit_ids) > 0)
else:
# full reconcile
self.assertTrue(selected_lines.full_reconcile_id)
self.assertRecordValues(
selected_lines,
[{'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}] * len(selected_lines),
)
# -------------------------------------------------------------------------
# TESTS
# -------------------------------------------------------------------------
def test_wizard_should_not_open(self):
""" Test that when we reconcile two lines that belong to the same account and have a 0 balance should
reconcile silently and not open the write-off wizard.
"""
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.company_currency, '2016-01-01')
(line_1 + line_2).action_reconcile()
self.assertRecordValues(
line_1 + line_2,
[{'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}] * 2
)
def test_wizard_should_open(self):
""" Test that when a write-off is required (because of transfer or non-zero balance) the wizard opens. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-01-01')
line_3 = self.create_line_for_reconciliation(-500.0, -1500.0, self.foreign_currency, '2016-01-01')
line_4 = self.create_line_for_reconciliation(-900.0, -900.0, self.company_currency, '2016-01-01', account_1=self.payable_account)
for batch, sub_test_name in (
(line_1 + line_2, 'Batch with non-zero balance in company currency'),
(line_1 + line_3, 'Batch with non-zero balance in foreign currency'),
(line_1 + line_4, 'Batch with different accounts'),
):
with self.subTest(sub_test_name=sub_test_name):
returned_action = batch.action_reconcile()
self.assertEqual(returned_action.get('res_model'), 'account.reconcile.wizard')
def test_reconcile_silently_same_account(self):
""" When balance is 0 we can silently reconcile items. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.company_currency, '2016-01-01')
lines = (line_1 + line_2)
lines.action_reconcile()
self.assertTrue(lines.full_reconcile_id)
self.assertRecordValues(
lines,
[{'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}] * len(lines),
)
def test_reconcile_silently_transfer(self):
""" When balance is 0, and we need a transfer, we do the transfer+reconcile silently. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.company_currency, '2016-01-01', account_1=self.payable_account)
lines = (line_1 + line_2)
lines.action_reconcile()
self.assertTrue(lines.full_reconcile_id)
self.assertRecordValues(
lines,
[{'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}] * len(lines),
)
def test_write_off_same_currency(self):
""" Reconciliation of two lines with no transfer/foreign currencies/taxes/reco models."""
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
write_off_expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': -500.0},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label', 'balance': 500.0},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, write_off_expected_values)
def test_write_off_with_analytic_distribution(self):
"""The wizard should preserve the analytic distribution on the created write-off line."""
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off With Analytic',
'allow_partials': False,
'date': self.test_date,
'analytic_distribution': {self.analytic_account.id: 100.0},
}
write_off_expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off With Analytic',
'balance': -500.0, 'analytic_distribution': False},
{'account_id': self.write_off_account.id, 'name': 'Write-Off With Analytic',
'balance': 500.0, 'analytic_distribution': {str(self.analytic_account.id): 100.0}},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, write_off_expected_values)
def test_write_off_one_foreign_currency(self):
""" Reconciliation of two lines with one of the two using foreign currency should reconcile in foreign currency."""
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -1500.0, self.foreign_currency, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -500.0, 'amount_currency': -1500.0, 'currency_id': self.foreign_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 500.0, 'amount_currency': 1500.0, 'currency_id': self.foreign_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values)
def test_write_off_one_foreign_currency_rounding(self):
""" Reconciliation of two lines with one of the two using foreign currency should reconcile in foreign currency."""
self.write_off_account.reconcile = True
foreign_currency = self.setup_other_currency('CAD', rounding=0.01, rates=[('2015-12-31', 0.052972554919), ('2016-12-31', 4.0)])
# Check that the reconciliation works independently of
# - whether the foreign amount is debit or credit
# - the account type (payable / receivable)
self.assertFalse(self.write_off_account.account_type in ('asset_receivable', 'liability_payable'))
self.assertTrue(self.receivable_account.account_type in ('asset_receivable', 'liability_payable'))
for foreign_amount_sign, account in [
(-1, self.write_off_account),
(1, self.write_off_account),
(-1, self.receivable_account),
(1, self.receivable_account),
]:
with self.subTest(sub_test_name=f'sign: {foreign_amount_sign}, account: {account.name}'):
line_1 = self.create_line_for_reconciliation(
-foreign_amount_sign * 372239.38, -foreign_amount_sign * 372239.38, self.company_currency,
'2016-01-01', account_1=account,
)
line_2 = self.create_line_for_reconciliation(
foreign_amount_sign * 377554.0, foreign_amount_sign * 20000.0, foreign_currency,
'2016-01-01', account_1=account,
)
lines = line_1 + line_2
# Test the opening of the wizard without input values
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=lines.ids,
).new()
self.assertRecordValues(wizard, [{
'is_write_off_required': True,
'amount': foreign_amount_sign * 5314.62,
'amount_currency': foreign_amount_sign * 281.53,
'reco_currency_id': foreign_currency.id,
}])
# Check the created write-off move and that there is no residual
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
# We sort the expected values the same way as `assertWizardReconcileValues` sorts the lines
expected_values = sorted([
{'account_id': account.id, 'name': 'Write-Off Test Label',
'balance': -foreign_amount_sign * 5314.62,
'amount_currency': -foreign_amount_sign * 281.53, 'currency_id': foreign_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': foreign_amount_sign * 5314.62,
'amount_currency': foreign_amount_sign * 281.53, 'currency_id': foreign_currency.id},
], key=lambda vals: vals['balance'])
self.assertWizardReconcileValues(lines, wizard_input_values, expected_values)
full_reconcile = lines.full_reconcile_id
self.assertTrue(full_reconcile)
def test_write_off_mixed_foreign_currencies(self):
""" Write off with multiple currencies should reconcile in company currency."""
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -1500.0, self.foreign_currency, '2016-01-01')
line_3 = self.create_line_for_reconciliation(-400.0, -2400.0, self.foreign_currency_2, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -100.0, 'amount_currency': -100.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 100.0, 'amount_currency': 100.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2 + line_3, wizard_input_values, expected_values)
def test_write_off_one_foreign_currency_change_rate(self):
""" Tests that write-off use the correct rate from/at wizard's date. """
foreign_currency = self.setup_other_currency('CAD', rounding=0.001, rates=[('2015-12-31', 0.5), ('2016-12-31', 1 / 3)])
new_date = fields.Date.from_string('2017-02-01')
line_1 = self.create_line_for_reconciliation(-2000.0, -2000.0, self.company_currency, '2017-01-01') # conversion in 2017 => -666.67🍫
line_2 = self.create_line_for_reconciliation(2000.0, 1000.0, foreign_currency, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': new_date,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -1000.0, 'amount_currency': -333.333, 'currency_id': foreign_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 1000.0, 'amount_currency': 333.333, 'currency_id': foreign_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values)
def test_write_off_mixed_foreign_currencies_change_rate(self):
""" Tests that write-off use the correct rate from/at wizard's date. """
new_date = fields.Date.from_string('2017-02-01')
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -1500.0, self.foreign_currency, '2016-01-01')
line_3 = self.create_line_for_reconciliation(-400.0, -2400.0, self.foreign_currency_2, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': new_date,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -100.0, 'amount_currency': -100.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 100.0, 'amount_currency': 100.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2 + line_3, wizard_input_values, expected_values)
def test_write_off_both_same_foreign_currency_ensure_no_exchange_diff(self):
""" Test that if both AMLs have the same foreign currency and rate, the amount in company currency
is computed on the write-off in such a way that no exchange diff is created.
"""
foreign_currency = self.setup_other_currency('CAD', rounding=0.01, rates=[('2015-12-31', 1 / 0.225)])
new_date = fields.Date.from_string('2017-02-01')
line_1 = self.create_line_for_reconciliation(21.38, 95.0, foreign_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(1.13, 5.0, foreign_currency, '2016-01-01')
line_3 = self.create_line_for_reconciliation(1.13, 5.0, foreign_currency, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': new_date,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -23.64, 'amount_currency': -105.0, 'currency_id': foreign_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 23.64, 'amount_currency': 105.0, 'currency_id': foreign_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2 + line_3, wizard_input_values, expected_values)
def test_write_off_with_transfer_account_same_currency(self):
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(100.0, 100.0, self.company_currency, '2016-01-01', account_1=self.payable_account)
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_transfer_values = [
{'account_id': self.payable_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': -100.0, 'amount_currency': -100.0, 'currency_id': self.company_currency.id},
{'account_id': self.receivable_account.id, 'name': f'Transfer from {self.payable_account.display_name}',
'balance': 100.0, 'amount_currency': 100.0, 'currency_id': self.company_currency.id},
]
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -1100.0, 'amount_currency': -1100.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 1100.0, 'amount_currency': 1100.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values, expected_transfer_values=expected_transfer_values)
def test_write_off_with_transfer_account_one_foreign_currency(self):
line_1 = self.create_line_for_reconciliation(1100.0, 1100.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(100.0, 300.0, self.foreign_currency, '2016-01-01', account_1=self.payable_account)
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_transfer_values = [
{'account_id': self.payable_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': -100.0, 'amount_currency': -300.0, 'currency_id': self.foreign_currency.id},
{'account_id': self.receivable_account.id, 'name': f'Transfer from {self.payable_account.display_name}',
'balance': 100.0, 'amount_currency': 300.0, 'currency_id': self.foreign_currency.id},
]
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -1200.0, 'amount_currency': -3600.0, 'currency_id': self.foreign_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 1200.0, 'amount_currency': 3600.0, 'currency_id': self.foreign_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values, expected_transfer_values=expected_transfer_values)
def test_write_off_with_complex_transfer(self):
partner_1 = self.env['res.partner'].create({'name': 'Test Partner 1'})
partner_2 = self.env['res.partner'].create({'name': 'Test Partner 2'})
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01', partner=partner_2)
line_2 = self.create_line_for_reconciliation(-100.0, -300.0, self.foreign_currency, '2016-01-01', account_1=self.payable_account, partner=partner_1)
line_3 = self.create_line_for_reconciliation(-200.0, -200.0, self.company_currency, '2016-01-01', account_1=self.payable_account, partner=partner_2)
line_4 = self.create_line_for_reconciliation(-200.0, -600.0, self.foreign_currency, '2016-01-01', account_1=self.payable_account, partner=partner_2)
line_5 = self.create_line_for_reconciliation(-200.0, -600.0, self.foreign_currency, '2016-01-01', account_1=self.payable_account, partner=partner_2)
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_transfer_values = [
{'account_id': self.receivable_account.id, 'name': f'Transfer from {self.payable_account.display_name}',
'balance': -400.0, 'amount_currency': -1200.0, 'currency_id': self.foreign_currency.id, 'partner_id': partner_2.id},
{'account_id': self.receivable_account.id, 'name': f'Transfer from {self.payable_account.display_name}',
'balance': -200.0, 'amount_currency': -200.0, 'currency_id': self.company_currency.id, 'partner_id': partner_2.id},
{'account_id': self.receivable_account.id, 'name': f'Transfer from {self.payable_account.display_name}',
'balance': -100.0, 'amount_currency': -300.0, 'currency_id': self.foreign_currency.id, 'partner_id': partner_1.id},
{'account_id': self.payable_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': 100.0, 'amount_currency': 300.0, 'currency_id': self.foreign_currency.id, 'partner_id': partner_1.id},
{'account_id': self.payable_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': 200.0, 'amount_currency': 200.0, 'currency_id': self.company_currency.id, 'partner_id': partner_2.id},
{'account_id': self.payable_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': 400.0, 'amount_currency': 1200.0, 'currency_id': self.foreign_currency.id, 'partner_id': partner_2.id},
]
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -300.0, 'amount_currency': -900.0, 'currency_id': self.foreign_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 300.0, 'amount_currency': 900.0, 'currency_id': self.foreign_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2 + line_3 + line_4 + line_5, wizard_input_values, expected_values, expected_transfer_values=expected_transfer_values)
def test_write_off_with_tax(self):
""" Tests write-off with a tax set on the wizard. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-01-01')
tax_recover_account_id = self.env['account.account'].create({
'name': 'Tax Account Test',
'account_type': 'liability_current',
'code': 'TAX.TEST',
})
base_tag = self.env['account.account.tag'].create({
'applicability': 'taxes',
'name': 'base_tax_tag',
'country_id': self.company_data['company'].country_id.id,
})
tax_tag = self.env['account.account.tag'].create({
'applicability': 'taxes',
'name': 'tax_tax_tag',
'country_id': self.company_data['company'].country_id.id,
})
tax_id = self.env['account.tax'].create({
'name': 'tax_test',
'amount_type': 'percent',
'amount': 25.0,
'type_tax_use': 'sale',
'company_id': self.company_data['company'].id,
'invoice_repartition_line_ids': [
Command.create({'factor_percent': 100, 'repartition_type': 'base', 'tag_ids': [Command.set(base_tag.ids)]}),
Command.create({'factor_percent': 100, 'account_id': tax_recover_account_id.id, 'tag_ids': [Command.set(tax_tag.ids)]}),
],
'refund_repartition_line_ids': [
Command.create({'factor_percent': 100, 'repartition_type': 'base', 'tag_ids': [Command.set(base_tag.ids)]}),
Command.create({'factor_percent': 100, 'account_id': tax_recover_account_id.id, 'tag_ids': [Command.set(tax_tag.ids)]}),
],
})
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'tax_id': tax_id.id,
'allow_partials': False,
'date': self.test_date,
}
write_off_expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': -500.0},
{'account_id': tax_recover_account_id.id, 'name': f'{tax_id.name}', 'balance': 100.0},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label', 'balance': 400.0},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, write_off_expected_values)
def test_reconcile_partials_allowed(self):
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-01-01')
lines = line_1 + line_2
wizard_input_values = {
'allow_partials': True,
}
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=lines.ids,
).new(wizard_input_values)
wizard.reconcile()
self.assertTrue(len(lines.matched_debit_ids) > 0 or len(lines.matched_credit_ids) > 0)
def test_raise_lock_date_violation(self):
""" If a write-off violates the lock date we display a banner and change the date afterwards. """
company_id = self.company_data['company']
company_id.fiscalyear_lock_date = fields.Date.from_string('2016-12-01')
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-06-01')
line_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-06-01')
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=(line_1 + line_2).ids,
).new({'date': self.test_date})
self.assertTrue(bool(wizard.lock_date_violated_warning_message))
def test_raise_reconcile_too_many_accounts(self):
""" If you try to reconcile lines from more than 2 accounts, it should raise an error. """
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-01-01', account_1=self.payable_account)
line_3 = self.create_line_for_reconciliation(-500.0, -500.0, self.company_currency, '2016-01-01', account_1=self.payable_account_2)
with self.assertRaises(UserError):
(line_1 + line_2 + line_3).action_reconcile()
def test_reconcile_no_receivable_no_payable_account(self):
""" If you try to reconcile lines in an account that is neither from payable nor receivable
it should reconcile in company currency.
"""
account = self.company_data['default_account_expense']
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01', account_1=account)
line_2 = self.create_line_for_reconciliation(-500.0, -1500.0, self.foreign_currency, '2016-01-01', account_1=account)
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_values = [
{'account_id': account.id, 'name': 'Write-Off Test Label',
'balance': -500.0, 'amount_currency': -500.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 500.0, 'amount_currency': 500.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values)
def test_reconcile_exchange_diff_foreign_currency(self):
""" When reconciling exchange_diff with amount_residual_currency = 0 we need to reconcile in company_currency.
"""
exchange_gain_account = self.company_data['company'].income_currency_exchange_account_id
line_1 = self.create_line_for_reconciliation(150.0, 0.0, self.foreign_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-100.0, 0.0, self.foreign_currency, '2016-01-01', account_1=exchange_gain_account)
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
# Note the transfer will always be in the currency of the line transferred
expected_transfer_values = [
{'account_id': self.receivable_account.id, 'name': f'Transfer from {exchange_gain_account.display_name}',
'balance': -100.0, 'amount_currency': 0.0, 'currency_id': self.foreign_currency.id},
{'account_id': exchange_gain_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': 100.0, 'amount_currency': 0.0, 'currency_id': self.foreign_currency.id},
]
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -50.0, 'amount_currency': -50.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 50.0, 'amount_currency': 50.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values, expected_transfer_values=expected_transfer_values)
def test_write_off_on_same_account(self):
""" When creating a write-off in the same account than the one used by the lines to reconcile,
the lines and the write-off should be fully reconciled.
"""
line_1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(2000.0, 2000.0, self.company_currency, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.receivable_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
write_off_expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': -3000.0},
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': 3000.0},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, write_off_expected_values)
def test_reconcile_exchange_diff_foreign_currency_full(self):
""" When reconciling exchange_diff with amount_residual_currency = 0 we need to reconcile in company_currency.
"""
exchange_gain_account = self.company_data['company'].income_currency_exchange_account_id
line_1 = self.create_line_for_reconciliation(100.0, 0.0, self.foreign_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-100.0, 0.0, self.foreign_currency, '2016-01-01', account_1=exchange_gain_account)
lines = line_1 + line_2
lines.action_reconcile()
self.assertTrue(lines.full_reconcile_id)
self.assertRecordValues(
lines,
[{'amount_residual': 0.0, 'amount_residual_currency': 0.0, 'reconciled': True}] * len(lines),
)
def test_write_off_kpmg_case(self):
""" Test that write-off does a full reconcile with 2 foreign currencies using a custom exchange rate. """
new_date = fields.Date.from_string('2017-02-01')
line_1 = self.create_line_for_reconciliation(1000.0, 1500.0, self.foreign_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(-900.0, -5400.0, self.foreign_currency_2, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': new_date,
}
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, [
{
'account_id': self.receivable_account.id,
'balance': -100.0,
'amount_currency': -150.0,
'currency_id': self.foreign_currency.id,
},
{
'account_id': self.write_off_account.id,
'balance': 100.0,
'amount_currency': 150.0,
'currency_id': self.foreign_currency.id,
},
])
def test_write_off_multi_curr_multi_residuals_force_partials(self):
""" Test that we raise an error when trying to reconcile lines with multiple residuals.
Here debit1 will be reconciled with credit1 first as they have the same currency.
Then residual of debit1 will try to reconcile with debit2 which is impossible
=> 2 residuals both in foreign currency, we don't know in which currency we should make the write-off
=> We should only allow partial reconciliation. """
debit_1 = self.create_line_for_reconciliation(2000.0, 12000.0, self.foreign_currency_2, '2016-01-01')
credit_1 = self.create_line_for_reconciliation(-1000.0, -6000.0, self.foreign_currency_2, '2016-01-01')
debit_2 = self.create_line_for_reconciliation(2000.0, 3000.0, self.foreign_currency, '2016-01-01')
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=(debit_1 + debit_2 + credit_1).ids,
).new()
self.assertRecordValues(wizard, [{'force_partials': True, 'allow_partials': True}])
def test_write_off_multi_curr_multi_residuals_exch_diff_force_partials(self):
debit_1 = self.create_line_for_reconciliation(2000.0, 0.0, self.foreign_currency_2, '2016-01-01')
credit_1 = self.create_line_for_reconciliation(-1000.0, 0.0, self.foreign_currency_2, '2016-01-01')
debit_2 = self.create_line_for_reconciliation(2000.0, 0.0, self.foreign_currency, '2016-01-01')
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=(debit_1 + debit_2 + credit_1).ids,
).new()
self.assertRecordValues(wizard, [{'force_partials': True, 'allow_partials': True}])
def test_reconcile_with_partner_change(self):
partner_1 = self.env['res.partner'].create({'name': 'Test Partner 1'})
partner_2 = self.env['res.partner'].create({'name': 'Test Partner 2'})
line_1 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.company_currency, '2016-01-01', partner=partner_1)
line_2 = self.create_line_for_reconciliation(2000.0, 2000.0, self.company_currency, '2016-01-01')
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.receivable_account.id,
'to_partner_id': partner_2.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
'tax_id': self.tax_sale_a.id,
}
write_off_expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': -1000.0, 'partner_id': partner_1.id},
{'account_id': self.company_data['default_account_tax_sale'].id, 'name': '15%', 'balance': 130.43, 'partner_id': partner_2.id},
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': 869.57, 'partner_id': partner_2.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, write_off_expected_values)
def test_reconcile_with_partner_change_and_transfer(self):
partner_1 = self.env['res.partner'].create({'name': 'Test Partner 1'})
partner_2 = self.env['res.partner'].create({'name': 'Test Partner 2'})
line_1 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.company_currency, '2016-01-01', account_1=self.payable_account)
line_2 = self.create_line_for_reconciliation(2000.0, 2000.0, self.company_currency, '2016-01-01', partner=partner_1)
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.receivable_account.id,
'to_partner_id': partner_2.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_transfer_values = [
{'account_id': self.receivable_account.id, 'name': f'Transfer from {self.payable_account.display_name}',
'balance': -1000.0, 'amount_currency': -1000.0, 'currency_id': self.company_currency.id},
{'account_id': self.payable_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': 1000.0, 'amount_currency': 1000.0, 'currency_id': self.company_currency.id},
]
write_off_expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': -1000.0, 'partner_id': partner_1.id},
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label', 'balance': 1000.0, 'partner_id': partner_2.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, write_off_expected_values, expected_transfer_values)
def test_reconcile_edit_mode_partial_foreign_curr(self):
line_1 = self.create_line_for_reconciliation(100.0, 300.0, self.foreign_currency, '2016-01-01')
wizard_input_values = {
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'date': self.test_date,
'edit_mode_amount_currency': 30.0,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -10.0, 'amount_currency': -30.0, 'currency_id': self.foreign_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 10.0, 'amount_currency': 30.0, 'currency_id': self.foreign_currency.id},
]
self.assertWizardReconcileValues(line_1, wizard_input_values, expected_values)
def test_reconcile_edit_mode_partial_company_curr(self):
line_1 = self.create_line_for_reconciliation(300.0, 300.0, self.company_currency, '2016-01-01')
wizard_input_values = {
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'date': self.test_date,
'edit_mode_amount_currency': 100.0,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -100.0, 'amount_currency': -100.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 100.0, 'amount_currency': 100.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1, wizard_input_values, expected_values)
def test_reconcile_edit_mode_partial_wrong_amount_raises(self):
line_1 = self.create_line_for_reconciliation(300.0, 300.0, self.company_currency, '2016-01-01')
wizard_input_values = {
'account_id': self.write_off_account.id,
}
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=line_1.ids,
).create(wizard_input_values)
with self.assertRaisesRegex(UserError, 'The amount of the write-off'):
wizard.edit_mode_amount_currency = -100.0
def test_reconcile_edit_mode_full_reconcile(self):
line_1 = self.create_line_for_reconciliation(300.0, 300.0, self.company_currency, '2016-01-01')
wizard_input_values = {
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'edit_mode_amount_currency': 300.0,
}
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -300.0, 'amount_currency': -300.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 300.0, 'amount_currency': 300.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1, wizard_input_values, expected_values)
def test_reconcile_same_currency_same_side_not_recpay(self):
"""
Test the reconciliation with two lines on the same side (debit/credit), same currency and not on a receivable/payable account
"""
current_assets_account = self.company_data['default_account_assets'].copy({'name': 'Current Assets', 'account_type': 'asset_current'})
line_1 = self.create_line_for_reconciliation(200, 200, self.company_currency, '2016-01-01', current_assets_account)
line_2 = self.create_line_for_reconciliation(200, 200, self.company_currency, '2016-01-01', current_assets_account)
# Test the opening of the wizard without input values
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=(line_1 + line_2).ids,
).new()
self.assertRecordValues(wizard, [{'is_write_off_required': True, 'amount': 400, 'amount_currency': 400}])
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_values = [
{'account_id': current_assets_account.id, 'name': 'Write-Off Test Label',
'balance': -400.0, 'amount_currency': -400.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 400.0, 'amount_currency': 400.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values)
def test_reconcile_foreign_currency_same_side_not_recpay(self):
"""
Test the reconciliation with two lines on the same side (debit/credit), one foreign currency and not on a receivable/payable account
"""
current_assets_account = self.company_data['default_account_assets'].copy({'name': 'Current Assets', 'account_type': 'asset_current'})
line_1 = self.create_line_for_reconciliation(200, 300, self.foreign_currency, '2016-01-01', current_assets_account)
line_2 = self.create_line_for_reconciliation(200, 200, self.company_currency, '2016-01-01', current_assets_account)
# Test the opening of the wizard without input values
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=(line_1 + line_2).ids,
).new()
self.assertRecordValues(wizard, [{'is_write_off_required': True, 'amount': 400, 'amount_currency': 400}])
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
expected_values = [
{'account_id': current_assets_account.id, 'name': 'Write-Off Test Label',
'balance': -400.0, 'amount_currency': -400.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 400.0, 'amount_currency': 400.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values)
def test_reconcile_same_side_exch_diff(self):
"""
Test the reconciliation with two lines on the same side (debit/credit), one exchange diff in foreign currency,
one regular aml in company currency
"""
exchange_gain_account = self.company_data['company'].income_currency_exchange_account_id
line_1 = self.create_line_for_reconciliation(150.0, 150.0, self.company_currency, '2016-01-01')
line_2 = self.create_line_for_reconciliation(100.0, 0.0, self.foreign_currency, '2016-01-01', account_1=exchange_gain_account)
wizard_input_values = {
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'allow_partials': False,
'date': self.test_date,
}
# Note the transfer will always be in the currency of the line transferred
expected_transfer_values = [
{'account_id': exchange_gain_account.id, 'name': f'Transfer to {self.receivable_account.display_name}',
'balance': -100.0, 'amount_currency': 0.0, 'currency_id': self.foreign_currency.id},
{'account_id': self.receivable_account.id, 'name': f'Transfer from {exchange_gain_account.display_name}',
'balance': 100.0, 'amount_currency': 0.0, 'currency_id': self.foreign_currency.id},
]
expected_values = [
{'account_id': self.receivable_account.id, 'name': 'Write-Off Test Label',
'balance': -250.0, 'amount_currency': -250.0, 'currency_id': self.company_currency.id},
{'account_id': self.write_off_account.id, 'name': 'Write-Off Test Label',
'balance': 250.0, 'amount_currency': 250.0, 'currency_id': self.company_currency.id},
]
self.assertWizardReconcileValues(line_1 + line_2, wizard_input_values, expected_values, expected_transfer_values=expected_transfer_values)
def test_reconcile_transfer_with_different_partners(self):
""" When balance is 0, and we need a transfer, we do the transfer+reconcile silently. """
partner_a = self.env['res.partner'].create({'name': 'Test Partner A'})
partner_b = self.env['res.partner'].create({'name': 'Test Partner B'})
partner_c = self.env['res.partner'].create({'name': 'Test Partner C'})
# when reconciling journal items on 2 different accounts from 2 different partners that balance themselves,
# all journal items should be fully reconciled together
line_a1 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01', account_1=self.receivable_account, partner=partner_a)
line_b1 = self.create_line_for_reconciliation(-1000.0, -1000.0, self.company_currency, '2016-01-01', account_1=self.payable_account, partner=partner_b)
lines = line_a1 + line_b1
lines.action_reconcile()
transfer_lines = lines.full_reconcile_id.reconciled_line_ids.filtered(lambda line: line.id not in lines.ids)
self.assertRecordValues(transfer_lines, [
{'balance': -1000.0, 'account_id': self.receivable_account.id, 'partner_id': partner_a.id},
{'balance': 1000.0, 'account_id': self.payable_account.id, 'partner_id': partner_b.id},
])
# even if the journal items on one of the accounts are for several different partners,
# the journal items should be fully reconciled together
line_a2 = self.create_line_for_reconciliation(1000.0, 1000.0, self.company_currency, '2016-01-01', account_1=self.receivable_account, partner=partner_a)
line_b2 = self.create_line_for_reconciliation(-600.0, -600.0, self.company_currency, '2016-01-01', account_1=self.payable_account, partner=partner_b)
line_c2 = self.create_line_for_reconciliation(-400.0, -400.0, self.company_currency, '2016-01-01', account_1=self.payable_account, partner=partner_c)
lines = line_a2 + line_b2 + line_c2
lines.action_reconcile()
transfer_lines = lines.full_reconcile_id.reconciled_line_ids.filtered(lambda line: line.id not in lines.ids)
self.assertRecordValues(transfer_lines, [
{'balance': -1000.0, 'account_id': self.receivable_account.id, 'partner_id': partner_a.id},
{'balance': 600.0, 'account_id': self.payable_account.id, 'partner_id': partner_b.id},
{'balance': 400.0, 'account_id': self.payable_account.id, 'partner_id': partner_c.id},
])
def test_reconciliation_currency_depending_on_account(self):
company_currency, foreign_currency = self.company_currency, self.foreign_currency
for (
index, account_reconcile, use_foreign_currency, amounts_currency_match, balances_match, opens_wizard, reco_currency) in (
(1, True, False, None, True, False, company_currency),
(2, True, False, None, False, True, company_currency),
(3, True, True, True, True, False, foreign_currency),
(4, True, True, True, False, False, foreign_currency),
(5, True, True, False, True, True, foreign_currency),
(6, True, True, False, False, True, foreign_currency),
(7, False, False, None, True, False, company_currency),
(8, False, False, None, False, True, company_currency),
(9, False, True, True, True, False, company_currency),
(10, False, True, True, False, True, company_currency),
(11, False, True, False, True, False, company_currency),
(12, False, True, False, False, True, company_currency),
):
with self.subTest(index=index):
account = self.env['account.account'].create({
'name': 'Reconciliation Currency Account',
'account_type': 'liability_current',
'code': f'RECOCUR{index}.TEST',
'reconcile': account_reconcile,
})
currency = foreign_currency if use_foreign_currency else company_currency
balance_1 = 1000
balance_2 = -1000.0 if balances_match else -900.0
if use_foreign_currency: # the rate of the foreign currency is 3.0 at that date
amount_currency_1 = 3000.0
amount_currency_2 = -3000.0 if amounts_currency_match else -2700.0
else:
amount_currency_1, amount_currency_2 = balance_1, balance_2
line_1 = self.create_line_for_reconciliation(balance_1, amount_currency_1, currency, self.test_date, account_1=account)
line_2 = self.create_line_for_reconciliation(balance_2, amount_currency_2, currency, self.test_date, account_1=account)
lines = line_1 + line_2
result = lines.action_reconcile()
if opens_wizard: # a write-off is needed, fill the wizard with arbitrary values and reconcile from it
self.assertEqual(result.get('res_model'), 'account.reconcile.wizard')
wizard = self.env['account.reconcile.wizard'].with_context(
active_model='account.move.line',
active_ids=lines.ids,
).new({
'journal_id': self.misc_journal.id,
'account_id': self.write_off_account.id,
'label': 'Write-Off Test Label',
'date': self.test_date,
})
write_off_line = wizard.reconcile() - lines
# the write-off is expressed in the currency used for the reconciliation
self.assertRecordValues(write_off_line, [{
'account_id': account.id,
'currency_id': reco_currency.id,
}])
else: # the items have been reconciled silently, without any write-off
self.assertFalse(isinstance(result, dict))
partials = lines.matched_debit_ids | lines.matched_credit_ids
if reco_currency == company_currency:
self.assertFalse(partials.exchange_move_id)
self.assertRecordValues(partials, [{
'amount': 1000.0,
'debit_amount_currency': amount_currency_1,
'credit_amount_currency': -amount_currency_2,
}])
else:
self.assertEqual(sum(partials.mapped('debit_amount_currency')), amount_currency_1)
self.assertEqual(sum(partials.mapped('credit_amount_currency')), -amount_currency_2)
self.assertEqual(bool(partials.exchange_move_id), not balances_match)

View File

@@ -0,0 +1,200 @@
from datetime import timedelta
from contextlib import closing
from odoo import fields
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo.addons.account_accountant.wizard.account_change_lock_date import SOFT_LOCK_DATE_FIELDS
from odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.tools import frozendict
@tagged('post_install', '-at_install')
class TestChangeLockDateWizard(AccountTestInvoicingCommon):
_test_user_groups = None # FIXME list needed groups
def test_exception_generation(self):
"""
Test the exception generation from the wizard.
Note that exceptions for 'everyone' and 'forever' are not tested here.
They do not create an exception (no 'account.lock_exception' object), but just change the lock date.
(See `test_everyone_forever_exception`.)
"""
self.env['account.lock_exception'].search([]).sudo().unlink()
for lock_date_field in SOFT_LOCK_DATE_FIELDS:
with self.subTest(lock_date_field=lock_date_field), closing(self.cr.savepoint()):
# We can set the lock date if there is none.
self.env['account.change.lock.date'].create({lock_date_field: '2010-01-01'}).change_lock_date()
self.assertEqual(self.env.company[lock_date_field], fields.Date.from_string('2010-01-01'))
# We can increase the lock date if there is one.
self.env['account.change.lock.date'].create({lock_date_field: '2011-01-01'}).change_lock_date()
self.assertEqual(self.env.company[lock_date_field], fields.Date.from_string('2011-01-01'))
# We cannot remove the lock date; but we can create an exception
wizard = self.env['account.change.lock.date'].create({
lock_date_field: False,
'exception_applies_to': 'everyone',
'exception_duration': '1h',
'exception_reason': ':TestChangeLockDateWizard.test_exception_generation; remove',
})
wizard.change_lock_date()
self.assertEqual(self.env['account.lock_exception'].search_count([]), 1)
exception = self.env['account.lock_exception'].search([])
self.assertEqual(len(exception), 1)
self.assertRecordValues(exception, [{
lock_date_field: False,
'company_id': self.env.company.id,
'user_id': False,
'create_uid': self.env.user.id,
'end_datetime': self.env.cr.now() + timedelta(hours=1),
'reason': ':TestChangeLockDateWizard.test_exception_generation; remove',
}])
exception.sudo().unlink()
# Ensure we have not created any exceptions yet
self.assertEqual(self.env['account.lock_exception'].search_count([]), 0)
# We cannot decrease the lock date; but we can create an exception
self.env['account.change.lock.date'].create({lock_date_field: '2009-01-01'}).change_lock_date()
self.assertEqual(self.env.company[lock_date_field], fields.Date.from_string('2011-01-01'))
exception = self.env['account.lock_exception'].search([])
self.assertEqual(len(exception), 1)
# Check lock date and default values on exception
self.assertRecordValues(exception, [{
lock_date_field: fields.Date.from_string('2009-01-01'),
'company_id': self.env.company.id,
'user_id': self.env.user.id,
'create_uid': self.env.user.id,
'end_datetime': self.env.cr.now() + timedelta(minutes=5),
'reason': False,
}])
def test_exception_generation_multiple(self):
"""
Test the exception generation from the wizard.
Here we test the case that we create multiple exceptions at once.
This should create an exception object for every changed lock date.
"""
self.env['account.lock_exception'].search([]).sudo().unlink()
wizard = self.env['account.change.lock.date'].create({
'fiscalyear_lock_date': '2010-01-01',
'tax_lock_date': '2010-01-01',
'sale_lock_date': '2010-01-01',
'purchase_lock_date': '2010-01-01',
})
wizard.change_lock_date()
self.assertRecordValues(self.env.company, [{
'fiscalyear_lock_date': fields.Date.from_string('2010-01-01'),
'tax_lock_date': fields.Date.from_string('2010-01-01'),
'sale_lock_date': fields.Date.from_string('2010-01-01'),
'purchase_lock_date': fields.Date.from_string('2010-01-01'),
}])
wizard = self.env['account.change.lock.date'].create({
'fiscalyear_lock_date': '2009-01-01',
'tax_lock_date': '2009-01-01',
'sale_lock_date': '2009-01-01',
'purchase_lock_date': '2009-01-01',
'exception_applies_to': 'everyone',
'exception_duration': '1h',
'exception_reason': ':TestChangeLockDateWizard.test_exception_generation; remove',
})
wizard.change_lock_date()
exceptions = self.env['account.lock_exception'].search([])
self.assertEqual(len(exceptions), 4)
expected_exceptions = {
frozendict({
'lock_date_field': 'fiscalyear_lock_date',
'lock_date': fields.Date.from_string('2009-01-01'),
}),
frozendict({
'lock_date_field': 'tax_lock_date',
'lock_date': fields.Date.from_string('2009-01-01'),
}),
frozendict({
'lock_date_field': 'sale_lock_date',
'lock_date': fields.Date.from_string('2009-01-01'),
}),
frozendict({
'lock_date_field': 'purchase_lock_date',
'lock_date': fields.Date.from_string('2009-01-01'),
}),
}
created_exceptions = {
frozendict({
'lock_date_field': exception.lock_date_field,
'lock_date': exception.lock_date,
})
for exception in exceptions
}
self.assertSetEqual(created_exceptions, expected_exceptions)
def test_hard_lock_date(self):
self.env['account.lock_exception'].search([]).sudo().unlink()
# We can set the hard lock date if there is none.
self.env['account.change.lock.date'].create({'hard_lock_date': '2010-01-01'}).change_lock_date()
self.assertEqual(self.env.company.hard_lock_date, fields.Date.from_string('2010-01-01'))
# We can increase the hard lock date if there is one.
self.env['account.change.lock.date'].create({'hard_lock_date': '2011-01-01'}).change_lock_date()
self.assertEqual(self.env.company.hard_lock_date, fields.Date.from_string('2011-01-01'))
# We cannot decrease the hard lock date; not even with an exception.
wizard = self.env['account.change.lock.date'].create({
'hard_lock_date': '2009-01-01',
'exception_applies_to': 'everyone',
'exception_duration': '1h',
'exception_reason': ':TestChangeLockDateWizard.test_hard_lock_date',
})
with self.assertRaises(UserError):
wizard.change_lock_date()
self.assertEqual(self.env.company.hard_lock_date, fields.Date.from_string('2011-01-01'))
# We cannot remove the hard lock date; not even with an exception.
wizard = self.env['account.change.lock.date'].create({
'hard_lock_date': False,
'exception_applies_to': 'everyone',
'exception_duration': '1h',
'exception_reason': ':TestChangeLockDateWizard.test_hard_lock_date',
})
with self.assertRaises(UserError):
wizard.change_lock_date()
self.assertEqual(self.env.company.hard_lock_date, fields.Date.from_string('2011-01-01'))
self.assertEqual(self.env['account.lock_exception'].search_count([]), 0)
def test_everyone_forever_exception(self):
self.env['account.lock_exception'].search([]).sudo().unlink()
for lock_date_field in SOFT_LOCK_DATE_FIELDS:
with self.subTest(lock_date_field=lock_date_field), closing(self.cr.savepoint()):
self.env['account.change.lock.date'].create({lock_date_field: '2010-01-01'}).change_lock_date()
self.assertEqual(self.env.company[lock_date_field], fields.Date.from_string('2010-01-01'))
# We can decrease the lock date with a 'forever' / 'everyone' exception.
self.env['account.change.lock.date'].create({
lock_date_field: '2009-01-01',
'exception_applies_to': 'everyone',
'exception_duration': 'forever',
'exception_reason': ':TestChangeLockDateWizard.test_everyone_forever_exception; remove',
}).change_lock_date()
self.assertEqual(self.env.company[lock_date_field], fields.Date.from_string('2009-01-01'))
# We can remove the lock date with a 'forever' / 'everyone' exception.
self.env['account.change.lock.date'].create({
lock_date_field: False,
'exception_applies_to': 'everyone',
'exception_duration': 'forever',
'exception_reason': ':TestChangeLockDateWizard.test_everyone_forever_exception; remove',
}).change_lock_date()
self.assertEqual(self.env.company[lock_date_field], False)
# Ensure we have not created any exceptions
self.assertEqual(self.env['account.lock_exception'].search_count([]), 0)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,234 @@
from contextlib import contextmanager
from odoo import Command
from odoo.tests import Form, tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged('post_install', '-at_install')
class TestJournalItemSplit(AccountTestInvoicingCommon):
_test_user_groups = None # FIXME list needed groups
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.bill = cls._create_invoice(
move_type='in_invoice',
invoice_line_ids=[
cls._prepare_invoice_line(product_id=cls.product_a, quantity=5, price_unit=800.0),
cls._prepare_invoice_line(product_id=cls.product_b, price_unit=160.0),
],
)
@contextmanager
def _split_lines(self, lines):
wizard_form = Form(self.env['account.split.journal.item.wizard'].with_context(
default_line_ids=[Command.set(lines.ids)],
))
try:
yield wizard_form
finally:
wizard = wizard_form.save()
total_before = self.bill.amount_total
wizard.split()
self.assertEqual(total_before, self.bill.amount_total)
def test_split_by_line_quantity(self):
line = self.bill.invoice_line_ids[0]
with self._split_lines(line) as wizard:
self.assertTrue(wizard.show_simple_wizard, f"Should only show simple wizard for line quantities != 2. line quantity: {line.quantity}")
self.assertEqual(wizard.quantity, 5, "Wizard quantity should equal the line quantity.")
self.assertInvoiceValues(
self.bill,
[
*(5 * [{'product_id': self.product_a.id, 'balance': 800.0}]),
{'product_id': self.product_b.id, 'balance': 160.0},
{'product_id': False, 'balance': 624.0},
{'product_id': False, 'balance': 24.0},
{'product_id': False, 'balance': -4808.0},
],
{},
)
def test_split_by_quanity(self):
line = self.bill.invoice_line_ids[0]
with self._split_lines(line) as wizard:
wizard.quantity = 4
self.assertTrue(wizard.show_simple_wizard)
self.assertRecordValues(
self.bill.invoice_line_ids,
[
{'product_id': self.product_a.id, 'balance': 1000.0, 'quantity': 1.25},
{'product_id': self.product_b.id, 'balance': 160.0, 'quantity': 1.0},
{'product_id': self.product_a.id, 'balance': 1000.0, 'quantity': 1.25},
{'product_id': self.product_a.id, 'balance': 1000.0, 'quantity': 1.25},
{'product_id': self.product_a.id, 'balance': 1000.0, 'quantity': 1.25},
],
)
def test_split_by_amount(self):
line = self.bill.invoice_line_ids[1]
with self._split_lines(line) as wizard:
wizard.quantity = 2
self.assertEqual(wizard.amount, line.balance / 2)
wizard.amount = 100.0
self.assertRecordValues(
self.bill.invoice_line_ids,
[
{'product_id': self.product_a.id, 'balance': 4000.0, 'quantity': 5.0},
{'product_id': self.product_b.id, 'balance': 60.0, 'quantity': 1.0},
{'product_id': self.product_b.id, 'balance': 100.0, 'quantity': 1.0},
],
)
def test_split_by_account(self):
line = self.bill.invoice_line_ids[0]
accounts = [line.account_id.id for line in self.bill.invoice_line_ids]
new_expense_account = self.bill.line_ids[0].account_id.copy({'name': "Expense 2"})
with self._split_lines(line) as wizard:
wizard.quantity = 2
self.assertFalse(wizard.show_simple_wizard)
wizard.account_id = new_expense_account
self.assertNotEqual(line.account_id, wizard.account_id)
self.assertRecordValues(
self.bill.invoice_line_ids,
[
{'product_id': self.product_a.id, 'balance': 2000.0, 'account_id': accounts[0]},
{'product_id': self.product_b.id, 'balance': 160.0, 'account_id': accounts[1]},
{'product_id': self.product_a.id, 'balance': 2000.0, 'account_id': new_expense_account.id},
],
)
def test_split_multiple_lines(self):
with self._split_lines(self.bill.invoice_line_ids) as wizard:
self.assertTrue(wizard.show_simple_wizard)
self.assertEqual(wizard.quantity, 2)
wizard.quantity = 4
self.assertRecordValues(
self.bill.invoice_line_ids,
[
{'product_id': self.product_a.id, 'balance': 1000.0},
{'product_id': self.product_b.id, 'balance': 40.0},
{'product_id': self.product_a.id, 'balance': 1000.0},
{'product_id': self.product_a.id, 'balance': 1000.0},
{'product_id': self.product_a.id, 'balance': 1000.0},
{'product_id': self.product_b.id, 'balance': 40.0},
{'product_id': self.product_b.id, 'balance': 40.0},
{'product_id': self.product_b.id, 'balance': 40.0},
],
)
def test_split_complex(self):
line = self.bill.invoice_line_ids[0]
accounts = [line.account_id.id for line in self.bill.invoice_line_ids]
new_expense_account = self.bill.line_ids[0].account_id.copy({'name': "Expense 2"})
with self._split_lines(line) as wizard:
wizard.quantity = 2
self.assertFalse(wizard.show_simple_wizard)
wizard.amount = 3000
wizard.account_id = new_expense_account
self.assertRecordValues(
self.bill.invoice_line_ids,
[
{'product_id': self.product_a.id, 'balance': 1000.0, 'account_id': accounts[0]},
{'product_id': self.product_b.id, 'balance': 160.0, 'account_id': accounts[1]},
{'product_id': self.product_a.id, 'balance': 3000.0, 'account_id': new_expense_account.id},
],
)
def test_split_without_product(self):
expense_account_id = self.company_data['default_account_expense'].id
revenue_account_id = self.company_data['default_account_revenue'].id
entry = self._create_invoice(
move_type='entry',
invoice_line_ids=[
Command.create({'debit': 100.0, 'account_id': expense_account_id}),
Command.create({'credit': 100.0, 'account_id': revenue_account_id}),
],
)
line = entry.line_ids.filtered(lambda l: l.debit)
with self._split_lines(line) as wizard:
self.assertEqual(wizard.quantity, 2)
self.assertFalse(wizard.show_simple_wizard)
self.assertRecordValues(
entry.line_ids,
[
{'balance': 50.0, 'account_id': expense_account_id},
{'balance': -100.0, 'account_id': revenue_account_id},
{'balance': 50.0, 'account_id': expense_account_id},
],
)
def test_split_with_discount(self):
invoice = self._create_invoice_one_line(
product_id=self.product_a,
quantity=3.0,
tax_ids=self.tax_sale_a,
discount=20.0,
)
line = invoice.invoice_line_ids[0]
with self._split_lines(line) as wizard:
self.assertEqual(wizard.quantity, 3)
self.assertTrue(wizard.show_simple_wizard)
self.assertRecordValues(
invoice.invoice_line_ids,
[
{'product_id': self.product_a.id, 'balance': -800.0},
{'product_id': self.product_a.id, 'balance': -800.0},
{'product_id': self.product_a.id, 'balance': -800.0},
],
)
def test_split_rounding_tax_included(self):
tax_included = self.env['account.tax'].create({
'name': 'Tax 20% Included',
'amount_type': 'percent',
'amount': 20.0,
'price_include': True,
})
invoice = self._create_invoice_one_line(
product_id=self.product_a,
quantity=1.0,
price_unit=10.0,
tax_ids=tax_included,
)
line = invoice.invoice_line_ids[0]
with self._split_lines(line) as wizard:
wizard.quantity = 3
self.assertTrue(wizard.show_simple_wizard)
self.assertRecordValues(
invoice.line_ids,
[
{'product_id': self.product_a.id, 'balance': -3.3},
{'product_id': False, 'balance': -2.0},
{'product_id': False, 'balance': 12.0},
{'product_id': self.product_a.id, 'balance': -3.4},
{'product_id': self.product_a.id, 'balance': -3.3},
],
)

View File

@@ -0,0 +1,259 @@
# -*- encoding: utf-8 -*-
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
from odoo import fields, Command
from odoo.tests import Form, tagged
@tagged('post_install', '-at_install')
class TestBillsPrediction(AccountTestInvoicingCommon):
_test_user_groups = None # FIXME list needed groups
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.test_partners = cls.env['res.partner'].create([{'name': 'test partner %s' % i} for i in range(7)])
accounts_data = [{
'code': 'test%s' % i,
'name': name,
'account_type': 'expense',
} for i, name in enumerate((
"Test Maintenance and Repair",
"Test Purchase of services, studies and preparatory work",
"Test Various Contributions",
"Test Rental Charges",
"Test Purchase of commodity",
))]
cls.test_accounts = cls.env['account.account'].create(accounts_data)
cls.frozen_today = fields.Date.today()
def _create_bill(self, vendor, line_name, expected_account, account_to_set=None, post=True):
''' Create a new vendor bill to test the prediction.
:param vendor: The vendor to set on the invoice.
:param line_name: The name of the invoice line that will be used to predict.
:param expected_account: The expected predicted account.
:param account_to_set: The optional account to set as a correction of the predicted account.
:return: The newly created vendor bill.
'''
invoice_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
invoice_form.partner_id = vendor
invoice_form.invoice_date = self.frozen_today
with invoice_form.invoice_line_ids.new() as invoice_line_form:
# Set the default account to avoid "account_id is a required field" in case of bad configuration.
invoice_line_form.account_id = self.company_data['default_journal_purchase'].default_account_id
invoice_line_form.quantity = 1.0
invoice_line_form.price_unit = 42.0
invoice_line_form.name = line_name
invoice = invoice_form.save()
invoice_line = invoice.invoice_line_ids
self.assertEqual(
invoice_line.account_id,
expected_account,
"Account '%s' should have been predicted instead of '%s'" % (
expected_account.display_name,
invoice_line.account_id.display_name,
),
)
if account_to_set:
invoice_line.account_id = account_to_set
if post:
invoice.action_post()
return invoice
def test_account_prediction_flow(self):
default_account = self.company_data['default_journal_purchase'].default_account_id
self._create_bill(self.test_partners[0], "Maintenance and repair", default_account, account_to_set=self.test_accounts[0])
self._create_bill(self.test_partners[5], "Subsidies obtained", default_account, account_to_set=self.test_accounts[1])
self._create_bill(self.test_partners[6], "Prepare subsidies file", default_account, account_to_set=self.test_accounts[1])
self._create_bill(self.test_partners[6], "Prepare subsidies file", self.test_accounts[1])
self._create_bill(self.test_partners[1], "Contributions January", default_account, account_to_set=self.test_accounts[2])
self._create_bill(self.test_partners[2], "Coca-cola", default_account, account_to_set=self.test_accounts[4])
self._create_bill(self.test_partners[1], "Contribution February", self.test_accounts[2])
self._create_bill(self.test_partners[3], "Electricity Bruxelles", default_account, account_to_set=self.test_accounts[3])
self._create_bill(self.test_partners[3], "Electricity Grand-Rosière", self.test_accounts[3])
self._create_bill(self.test_partners[2], "Purchase of coca-cola", self.test_accounts[4])
self._create_bill(self.test_partners[4], "Crate of coca-cola", default_account, account_to_set=self.test_accounts[4])
self._create_bill(self.test_partners[4], "Crate of coca-cola", self.test_accounts[4])
self._create_bill(self.test_partners[1], "March", self.test_accounts[2])
def test_account_prediction_from_label_expected_behavior(self):
"""Prevent the prediction from being annoying."""
default_account = self.company_data['default_journal_purchase'].default_account_id
payable_account = self.company_data['default_account_payable'].copy()
payable_account.write({'name': f'Account payable - {self.test_accounts[0].name}'})
# There is no prior result, we take the default account, but we don't post
self._create_bill(self.test_partners[0], self.test_partners[0].name, default_account, post=False)
# There is no prior result, we take the default account
self._create_bill(self.test_partners[0], "Drinks", default_account, account_to_set=self.test_accounts[0])
# There is only one prior account for the partner, we take that one
self._create_bill(self.test_partners[0], "Dessert", self.test_accounts[0], account_to_set=self.test_accounts[1])
# We find something close enough, take that one
self._create_bill(self.test_partners[0], "Drinks too", self.test_accounts[0])
# There is no clear preference for any account (both previous accounts have the same rank)
# don't make any prediction and let the default behavior fill the account
invoice = self._create_bill(self.test_partners[0], "Main course", self.test_accounts[0], post=False)
with Form(invoice) as move_form:
with move_form.invoice_line_ids.edit(0) as line_form:
# We changed the account before in the same form, do not override it
line_form.account_id = self.test_accounts[2]
line_form.name = "Second dessert"
self.assertEqual(line_form.account_id, self.test_accounts[2])
with Form(invoice) as move_form:
with move_form.invoice_line_ids.edit(0) as line_form:
# We didn't change the account before in the same form, override it
line_form.name = "Third dessert"
self.assertEqual(line_form.account_id, self.test_accounts[1])
def test_account_prediction_with_product(self):
product = self.env['product.product'].create({
'name': 'product_a',
'lst_price': 1000.0,
'standard_price': 800.0,
'property_account_income_id': self.company_data['default_account_revenue'].id,
'property_account_expense_id': self.company_data['default_account_expense'].id,
})
invoice_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
invoice_form.partner_id = self.test_partners[0]
invoice_form.invoice_date = self.frozen_today
with invoice_form.invoice_line_ids.new() as invoice_line_form:
invoice_line_form.product_id = product
invoice_line_form.name = "Maintenance and repair"
invoice = invoice_form.save()
self.assertRecordValues(invoice.invoice_line_ids, [{
'name': "Maintenance and repair",
'product_id': product.id,
'account_id': self.company_data['default_account_expense'].id,
}])
def test_product_prediction_price_subtotal_computation(self):
invoice_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
invoice_form.partner_id = self.test_partners[0]
invoice_form.invoice_date = self.frozen_today
with invoice_form.invoice_line_ids.new() as invoice_line_form:
invoice_line_form.product_id = self.product_a
invoice = invoice_form.save()
invoice.action_post()
# In case a unit price is already set we do not update the unit price
invoice_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
invoice_form.partner_id = self.test_partners[0]
invoice_form.invoice_date = self.frozen_today
with invoice_form.invoice_line_ids.new() as invoice_line_form:
invoice_line_form.price_unit = 42.0
invoice_line_form.name = 'product_a'
invoice = invoice_form.save()
self.assertRecordValues(invoice.invoice_line_ids, [{
'quantity': 1.0,
'price_unit': 42.0,
'price_subtotal': 42.0,
'balance': 42.0,
'tax_ids': self.tax_purchase_a.ids,
}])
# In case a tax is already set we do not update the taxes
invoice = self.env['account.move'].create({
'move_type': 'in_invoice',
'partner_id': self.test_partners[0].id,
'line_ids': [Command.create({'name': 'something else'})]
})
invoice_form = Form(invoice)
invoice_form.partner_id = self.test_partners[0]
invoice_form.invoice_date = self.frozen_today
with invoice_form.invoice_line_ids.edit(0) as invoice_line_form:
invoice_line_form.tax_ids = self.tax_purchase_b
invoice_line_form.name = 'product_a'
invoice = invoice_form.save()
self.assertRecordValues(invoice.invoice_line_ids, [{
'quantity': 1.0,
'price_unit': 800.0,
'price_subtotal': 800.0,
'balance': 800.0,
'tax_ids': self.tax_purchase_b.ids,
}])
def test_deductible_percentage_prediction(self):
default_account = self.company_data['default_journal_purchase'].default_account_id
bill_1 = self.env['account.move'].create({
'move_type': 'in_invoice',
'invoice_date': fields.Date.today(),
'partner_id': self.test_partners[0].id,
'line_ids': [
Command.create({'name': "Laptop", 'deductible_percentage': 0.8, 'account_id': default_account.id, 'quantity': 1, 'price_unit': 100.0}),
Command.create({'name': "T-shirt", 'deductible_percentage': 0.5, 'account_id': default_account.id, 'quantity': 1, 'price_unit': 100.0}),
Command.create({'name': "T-shirt", 'deductible_percentage': 0.6, 'account_id': default_account.id, 'quantity': 1, 'price_unit': 100.0}),
],
})
bill_1.action_post()
bill_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
bill_form.partner_id = self.test_partners[0]
labels = ['Laptop', 'Laptops', 'Laptopp', 'T-shirt', 'Mobile']
for label in labels:
with bill_form.invoice_line_ids.new() as invoice_line_form:
invoice_line_form.name = label
bill_2 = bill_form.save()
self.assertRecordValues(bill_2.invoice_line_ids, [
{'name': 'Laptop', 'deductible_percentage': 0.8},
{'name': 'Laptops', 'deductible_percentage': 0.8},
{'name': 'Laptopp', 'deductible_percentage': 0.6},
{'name': 'T-shirt', 'deductible_percentage': 0.6},
{'name': 'Mobile', 'deductible_percentage': 0.6},
])
# Don't predict if the user is not having group `account.group_partial_purchase_deductibility`
self.env.user.group_ids -= self.env.ref('account.group_partial_purchase_deductibility')
bill_form = Form(self.env['account.move'].with_context(default_move_type='in_invoice'))
bill_form.partner_id = self.test_partners[0]
labels = ['Laptop', 'Laptops']
for label in labels:
with bill_form.invoice_line_ids.new() as invoice_line_form:
invoice_line_form.name = label
bill_3 = bill_form.save()
self.assertRecordValues(bill_3.invoice_line_ids, [
{'name': 'Laptop', 'deductible_percentage': 1.0},
{'name': 'Laptops', 'deductible_percentage': 1.0},
])
def test_onchange_account_conflict(self):
self.test_accounts[4].tax_ids = self.tax_purchase_a
bill_1 = self.env['account.move'].create({
'move_type': 'in_invoice',
'invoice_date': fields.Date.today(),
'partner_id': self.test_partners[0].id,
'line_ids': [
Command.create({
'name': "Electricity january",
'account_id': self.test_accounts[4].id,
'tax_ids': self.tax_purchase_b.ids,
}),
],
})
bill_1.action_post()
with Form(self.env['account.move'].with_context(default_move_type='in_invoice')) as invoice_form:
invoice_form.partner_id = self.test_partners[0]
invoice_form.invoice_date = self.frozen_today
with invoice_form.invoice_line_ids.new() as invoice_line_form:
invoice_line_form.name = "electricity february"
bill = invoice_form.save()
self.assertEqual(bill.line_ids.tax_ids, self.tax_purchase_b)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,88 @@
from odoo import Command
from odoo.tools import BinaryBytes
from odoo.tests import tagged
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
@tagged('post_install', '-at_install')
class TestInvoiceSignature(AccountTestInvoicingCommon):
_test_user_groups = None # FIXME list needed groups
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.ensure_installed('sign')
cls.env.company.sign_invoice = True
cls.signature_fake_1 = BinaryBytes(b"fake_signature_1")
cls.signature_fake_2 = BinaryBytes(b"fake_signature_2")
cls.user.sign_signature = cls.signature_fake_1
cls.another_user = cls.env['res.users'].create({
'name': 'another accountant',
'login': 'another_accountant',
'password': 'another_accountant',
'group_ids': [
Command.set(cls.env.ref('account.group_account_user').ids),
],
'sign_signature': cls.signature_fake_2,
})
cls.invoice = cls.env['account.move'].create({
'move_type': 'out_invoice',
'partner_id': cls.partner_a.id,
'journal_id': cls.company_data['default_journal_sale'].id,
'invoice_line_ids': [
Command.create({
'product_id': cls.product_a.id,
'quantity': 1,
'price_unit': 1,
})
]
})
def test_draft_invoice_shouldnt_have_signature(self):
self.assertEqual(self.invoice.state, 'draft')
self.assertFalse(self.invoice.show_signature_area, "the signature area shouldn't appear on a draft invoice")
def test_posted_invoice_should_have_signature(self):
self.invoice.action_post()
self.assertTrue(self.invoice.show_signature_area,
"the signature area should appear on posted invoice when the `sign_invoice` settings is True")
def test_invoice_from_company_without_signature_settings_shouldnt_have_signature(self):
self.env.company.sign_invoice = False
self.invoice.action_post()
self.assertFalse(self.invoice.show_signature_area,
"the signature area shouldn't appear when the `sign_invoice` settings is False")
def test_invoice_signing_user_should_be_the_user_that_posted_it(self):
self.assertFalse(self.invoice.signing_user,
"invoice that weren't created by automated action shouldn't have a signing user")
self.assertFalse(self.invoice.signature, "There shouldn't be any signature if there isn't a signing user")
self.invoice.action_post()
self.assertEqual(self.invoice.signing_user, self.user, "The signing user should be the user that posted the invoice")
self.assertEqual(self.invoice.signature.content, self.signature_fake_1.content, "The signature should be from `self.user`")
self.invoice.button_draft()
self.invoice.with_user(self.another_user).action_post()
self.assertEqual(self.invoice.signing_user, self.another_user,
"The signing user should be the user that posted the invoice")
self.assertEqual(self.invoice.signature.content, self.signature_fake_2.content, "The signature should be from `self.another_user`")
def test_invoice_signing_user_should_be_reprensative_user_if_there_is_one(self):
self.env.company.signing_user = self.user # set the representative user of the company
invoice = self.invoice.with_user(self.another_user)
invoice.action_post()
self.assertEqual(invoice.signing_user, self.user, "The signing user should be the representative person set in the settings")
self.assertEqual(invoice.signature.content, self.signature_fake_1.content, "The signature should be from `self.another_user`, the representative user")
def test_setting_representative_user_shouldnt_change_signer_of_already_posted_invoice(self):
# Note: Changing this behavior might not be a good idea as having all account.move updated at once
# would be very costly
self.invoice.action_post()
self.env.company.signing_user = self.another_user # set the representative user of the company
self.assertEqual(self.invoice.signing_user, self.user,
"The signing user should be the one that posted the invoice even if a representative has been added later on")
self.assertEqual(self.invoice.signature.content, self.signature_fake_1.content, "The signature should be from `self.user`")

View File

@@ -0,0 +1,81 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import Command, fields
from odoo.addons.account.tests.common import AccountTestMockOnlineSyncCommon
import odoo.tests
_logger = logging.getLogger(__name__)
@odoo.tests.tagged('-at_install', 'post_install')
class TestUi(AccountTestMockOnlineSyncCommon):
def test_accountant_tour(self):
# Reset country and fiscal country, so that fields added by localizations are
# hidden and non-required, and don't make the tour crash.
# Also remove default taxes from the company and its accounts, to avoid inconsistencies
# with empty fiscal country.
self.env.company.write({
'country_id': None, # Also resets account_fiscal_country_id
'account_sale_tax_id': None,
'account_purchase_tax_id': None,
})
# An unconfigured bank journal is required for the connect bank step
self.env['account.journal'].create({
'type': 'bank',
'name': 'Empty Bank',
'code': 'EBJ',
})
account_with_taxes = self.env['account.account'].search([('tax_ids', '!=', False), ('company_ids', '=', self.env.company.id)])
account_with_taxes.write({
'tax_ids': [Command.clear()],
})
# This tour doesn't work with demo data on runbot
all_moves = self.env['account.move'].search([('company_id', '=', self.env.company.id), ('move_type', '!=', 'entry')])
all_moves.filtered(lambda m: not m.inalterable_hash and not m.deferred_move_ids and m.state != 'draft').button_draft()
all_moves.with_context(force_delete=True).unlink()
# We need at least two bank statement lines to reconcile for the tour.
bnk = self.env['account.account'].create({
'code': 'X1014',
'name': 'Bank Current Account - (test)',
'account_type': 'asset_cash',
})
journal = self.env['account.journal'].create({
'name': 'Bank - Test',
'code': 'TBNK',
'type': 'bank',
'default_account_id': bnk.id,
})
self.env['account.bank.statement.line'].create([{
'journal_id': journal.id,
'amount': 100,
'date': fields.Date.today(),
'payment_ref': 'stl_0001',
}, {
'journal_id': journal.id,
'amount': 200,
'date': fields.Date.today(),
'payment_ref': 'stl_0002',
}])
# The tour sends an email at some point which requires an email set on the user
self.env.ref('base.user_admin').write({
'email': 'mitchell.admin@example.com'
})
# Disable all onboarding tours
self.env['web_tour.tour'].search([]).unlink()
# Mark the base module as having demo data so the "try our sample" button appears
self.env['ir.module.module'].sudo().search([('name', '=', 'base')]).write({'demo': True})
# action_create_vendor_bill requires base.res_partner_2 (a demo data record)
if not self.env.ref('base.res_partner_2', raise_if_not_found=False):
demo_partner = self.env['res.partner'].create({'name': 'Acme Corporation'})
self.env['ir.model.data']._update_xmlids([{
'xml_id': "base.res_partner_2",
'record': demo_partner,
'noupdate': False,
}])
self.start_tour("/odoo", 'account_accountant_tour', login="admin")