mirror of
https://github.com/OCA/account-reconcile.git
synced 2025-01-20 12:27:39 +02:00
114 lines
4.9 KiB
Python
114 lines
4.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
#
|
|
# Authors: Laurent Mignon
|
|
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
|
# All Rights Reserved
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
#
|
|
from openerp import fields, tools
|
|
from openerp.modules import get_module_resource
|
|
from openerp.tests import common
|
|
from collections import namedtuple
|
|
|
|
name_completion_case = namedtuple(
|
|
"name_completion_case", ["partner_name", "line_label", "should_match"])
|
|
NAMES_COMPLETION_CASES = [
|
|
name_completion_case("Acsone", "Line for Acsone SA", True),
|
|
name_completion_case("Acsone", "Line for Acsone", True),
|
|
name_completion_case("Acsone", "Acsone for line", True),
|
|
name_completion_case("acsone", "Acsone for line", True),
|
|
name_completion_case("Acsone SA", "Line for Acsone SA test", True),
|
|
name_completion_case("Ac..ne", "Acsone for line", False),
|
|
name_completion_case("é@|r{}", "Acsone é@|r{} for line", True),
|
|
name_completion_case("Acsone", "A..one for line", False),
|
|
name_completion_case("A.one SA", "A.one SA for line", True),
|
|
name_completion_case(
|
|
"Acsone SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA test", False),
|
|
name_completion_case(
|
|
"Acsone ([^a-zA-Z0-9 -]) SA", "Line for Acsone ([^a-zA-Z0-9 -]) SA "
|
|
"test", True),
|
|
name_completion_case(
|
|
r"Acsone (.^$*+?()[{\| -]\) SA", r"Line for Acsone (.^$*+?()[{\| -]\) "
|
|
r"SA test", True),
|
|
name_completion_case("Acšone SA", "Line for Acšone SA test", True),
|
|
]
|
|
|
|
|
|
class base_completion(common.TransactionCase):
|
|
|
|
def setUp(self):
|
|
super(base_completion, self).setUp()
|
|
tools.convert_file(self.cr, 'account',
|
|
get_module_resource('account', 'test',
|
|
'account_minimal_test.xml'),
|
|
{}, 'init', False, 'test')
|
|
self.account_move_obj = self.env["account.move"]
|
|
self.account_move_line_obj = \
|
|
self.env["account.move.line"]
|
|
self.company_a = self.browse_ref('base.main_company')
|
|
self.journal = self.browse_ref("account.bank_journal")
|
|
self.partner = self.browse_ref("base.res_partner_12")
|
|
self.account_id = self.ref("account.a_recv")
|
|
|
|
def test_name_completion(self):
|
|
"""Test complete partner_id from statement line label
|
|
Test the automatic completion of the partner_id based if the name of
|
|
the partner appears in the statement line label
|
|
"""
|
|
self.completion_rule_id = self.ref(
|
|
'account_statement_base_import.bank_statement_completion_rule_3')
|
|
# Create the profile
|
|
self.journal.write({
|
|
'used_for_import': True,
|
|
'partner_id': self.partner.id,
|
|
'commission_account_id': self.account_id,
|
|
'receivable_account_id': self.account_id,
|
|
'rule_ids': [(6, 0, [self.completion_rule_id])]
|
|
})
|
|
# Create a bank statement
|
|
self.move = self.account_move_obj.create({
|
|
"date": fields.Date.today(),
|
|
"journal_id": self.journal.id
|
|
})
|
|
|
|
for case in NAMES_COMPLETION_CASES:
|
|
self.partner.write({'name': case.partner_name})
|
|
self.move_line = self.account_move_line_obj.with_context(
|
|
check_move_validity=False
|
|
).create({
|
|
'account_id': self.account_id,
|
|
'credit': 1000.0,
|
|
'name': case.line_label,
|
|
'move_id': self.move.id,
|
|
})
|
|
self.assertFalse(
|
|
self.move_line.partner_id,
|
|
"Partner_id must be blank before completion")
|
|
self.move.button_auto_completion()
|
|
if case.should_match:
|
|
self.assertEquals(
|
|
self.partner, self.move_line.partner_id,
|
|
"Missing expected partner id after completion "
|
|
"(partner_name: %s, line_name: %s)" %
|
|
(case.partner_name, case.line_label))
|
|
else:
|
|
self.assertNotEquals(
|
|
self.partner, self.move_line.partner_id,
|
|
"Partner id should be empty after completion "
|
|
"(partner_name: %s, line_name: %s)"
|
|
% (case.partner_name, case.line_label))
|