2017-10-13 17:27:59 +02:00
|
|
|
# Copyright 2015 Pedro M. Baeza
|
|
|
|
# Copyright 2017 Tecnativa - Vicent Cubells
|
2015-08-07 18:05:03 +02:00
|
|
|
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
|
2020-11-26 15:23:56 +01:00
|
|
|
from datetime import datetime
|
|
|
|
|
2019-03-19 23:12:50 +01:00
|
|
|
import odoo.tests.common as common
|
2015-08-07 18:05:03 +02:00
|
|
|
|
|
|
|
|
2017-10-13 17:27:59 +02:00
|
|
|
class TestAccountNetting(common.SavepointCase):
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestAccountNetting, cls).setUpClass()
|
2020-03-19 09:13:15 +01:00
|
|
|
res_users_account_manager = cls.env.ref("account.group_account_manager")
|
|
|
|
partner_manager = cls.env.ref("base.group_partner_manager")
|
|
|
|
cls.env.user.write(
|
2020-03-19 09:13:16 +01:00
|
|
|
{"groups_id": [(6, 0, [res_users_account_manager.id, partner_manager.id])]}
|
2020-03-19 09:13:15 +01:00
|
|
|
)
|
2020-11-26 15:23:56 +01:00
|
|
|
company = cls.env.ref("base.main_company")
|
2017-10-13 17:27:59 +02:00
|
|
|
# only adviser can create an account
|
2020-03-19 09:13:15 +01:00
|
|
|
cls.account_receivable = cls.env["account.account"].create(
|
|
|
|
{
|
|
|
|
"code": "cust_acc",
|
|
|
|
"name": "customer account",
|
|
|
|
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
|
|
|
|
"reconcile": True,
|
2020-11-26 15:23:56 +01:00
|
|
|
"company_id": company.id,
|
2020-03-19 09:13:15 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
cls.account_payable = cls.env["account.account"].create(
|
|
|
|
{
|
|
|
|
"code": "supp_acc",
|
|
|
|
"name": "supplier account",
|
|
|
|
"user_type_id": cls.env.ref("account.data_account_type_payable").id,
|
|
|
|
"reconcile": True,
|
2020-11-26 15:23:56 +01:00
|
|
|
"company_id": company.id,
|
2020-03-19 09:13:15 +01:00
|
|
|
}
|
|
|
|
)
|
|
|
|
cls.account_revenue = cls.env["account.account"].search(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"user_type_id",
|
|
|
|
"=",
|
|
|
|
cls.env.ref("account.data_account_type_revenue").id,
|
2020-11-26 15:23:56 +01:00
|
|
|
),
|
|
|
|
("company_id", "=", company.id),
|
2020-03-19 09:13:15 +01:00
|
|
|
],
|
|
|
|
limit=1,
|
|
|
|
)
|
|
|
|
cls.account_expense = cls.env["account.account"].search(
|
|
|
|
[
|
|
|
|
(
|
|
|
|
"user_type_id",
|
|
|
|
"=",
|
|
|
|
cls.env.ref("account.data_account_type_expenses").id,
|
2020-11-26 15:23:56 +01:00
|
|
|
),
|
|
|
|
("company_id", "=", company.id),
|
2020-03-19 09:13:15 +01:00
|
|
|
],
|
|
|
|
limit=1,
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.partner = cls.env["res.partner"].create(
|
|
|
|
{
|
|
|
|
"name": "Supplier/Customer",
|
|
|
|
"property_account_receivable_id": cls.account_receivable.id,
|
|
|
|
"property_account_payable_id": cls.account_payable.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
cls.partner1 = cls.env["res.partner"].create(
|
|
|
|
{
|
|
|
|
"name": "Supplier/Customer 1",
|
|
|
|
"property_account_receivable_id": cls.account_receivable.id,
|
|
|
|
"property_account_payable_id": cls.account_payable.id,
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 09:13:15 +01:00
|
|
|
cls.journal = cls.env["account.journal"].create(
|
2020-11-26 15:23:56 +01:00
|
|
|
{
|
|
|
|
"name": "Test sale journal",
|
|
|
|
"type": "sale",
|
|
|
|
"code": "TEST",
|
|
|
|
"company_id": company.id,
|
|
|
|
}
|
2020-03-19 09:13:15 +01:00
|
|
|
)
|
|
|
|
cls.expenses_journal = cls.env["account.journal"].create(
|
2020-11-26 15:23:56 +01:00
|
|
|
{
|
|
|
|
"name": "Test expense journal",
|
|
|
|
"type": "purchase",
|
|
|
|
"code": "EXP",
|
|
|
|
"company_id": company.id,
|
|
|
|
}
|
2020-03-19 09:13:15 +01:00
|
|
|
)
|
|
|
|
cls.miscellaneous_journal = cls.env["account.journal"].create(
|
2020-11-26 15:23:56 +01:00
|
|
|
{
|
|
|
|
"name": "Miscellaneus journal",
|
|
|
|
"type": "general",
|
|
|
|
"code": "OTHER",
|
|
|
|
"company_id": company.id,
|
|
|
|
}
|
2020-03-19 09:13:15 +01:00
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.customer_invoice = cls.env["account.move"].create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"journal_id": cls.journal.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"move_type": "out_invoice",
|
2020-03-19 09:13:15 +01:00
|
|
|
"partner_id": cls.partner.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"company_id": company.id,
|
2020-03-19 09:13:15 +01:00
|
|
|
"invoice_line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"name": "Test",
|
|
|
|
"price_unit": 100.0,
|
|
|
|
"account_id": cls.account_revenue.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.customer_invoice.action_post()
|
|
|
|
customer_move = cls.customer_invoice
|
2017-10-13 17:27:59 +02:00
|
|
|
cls.move_line_1 = customer_move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == cls.account_receivable
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice = cls.env["account.move"].create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"journal_id": cls.expenses_journal.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"move_type": "in_invoice",
|
2020-03-19 09:13:15 +01:00
|
|
|
"partner_id": cls.partner.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"company_id": company.id,
|
|
|
|
"invoice_date": datetime.now(),
|
2020-03-19 09:13:15 +01:00
|
|
|
"invoice_line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"name": "Test",
|
|
|
|
"price_unit": 1200.0,
|
|
|
|
"account_id": cls.account_expense.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice.action_post()
|
|
|
|
supplier_move = cls.supplier_invoice
|
2017-10-13 17:27:59 +02:00
|
|
|
cls.move_line_2 = supplier_move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == cls.account_payable
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
cls.move_line_3 = supplier_move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == cls.account_expense
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice = cls.env["account.move"].create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"journal_id": cls.expenses_journal.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"move_type": "in_invoice",
|
2020-03-19 09:13:15 +01:00
|
|
|
"partner_id": cls.partner1.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"company_id": company.id,
|
|
|
|
"invoice_date": datetime.now(),
|
2020-03-19 09:13:15 +01:00
|
|
|
"invoice_line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"name": "Test",
|
|
|
|
"price_unit": 200.0,
|
|
|
|
"account_id": cls.account_expense.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice.action_post()
|
|
|
|
supplier_move = cls.supplier_invoice
|
2018-01-25 14:11:48 +01:00
|
|
|
cls.move_line_4 = supplier_move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == cls.account_payable
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice = cls.env["account.move"].create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"journal_id": cls.expenses_journal.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"move_type": "in_refund",
|
2020-03-19 09:13:15 +01:00
|
|
|
"partner_id": cls.partner1.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"company_id": company.id,
|
|
|
|
"invoice_date": datetime.now(),
|
2020-03-19 09:13:15 +01:00
|
|
|
"invoice_line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"name": "Test",
|
|
|
|
"price_unit": 200.0,
|
|
|
|
"account_id": cls.account_expense.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice.action_post()
|
|
|
|
supplier_move = cls.supplier_invoice
|
2018-01-25 14:11:48 +01:00
|
|
|
cls.move_line_5 = supplier_move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == cls.account_payable
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice = cls.env["account.move"].create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"journal_id": cls.expenses_journal.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"move_type": "in_refund",
|
2020-03-19 09:13:15 +01:00
|
|
|
"partner_id": cls.partner1.id,
|
2020-11-26 15:23:56 +01:00
|
|
|
"company_id": company.id,
|
|
|
|
"invoice_date": datetime.now(),
|
2020-03-19 09:13:15 +01:00
|
|
|
"invoice_line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"name": "Test",
|
|
|
|
"price_unit": 200.0,
|
|
|
|
"account_id": cls.account_expense.id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
}
|
|
|
|
)
|
2020-03-19 09:13:16 +01:00
|
|
|
cls.supplier_invoice.action_post()
|
|
|
|
supplier_move = cls.supplier_invoice
|
2018-01-25 14:11:48 +01:00
|
|
|
cls.move_line_6 = supplier_move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == cls.account_payable
|
|
|
|
)
|
2015-08-07 18:05:03 +02:00
|
|
|
|
|
|
|
def test_compensation(self):
|
2018-01-25 14:11:48 +01:00
|
|
|
# Test exception line 33 from account_move_make_netting
|
2020-03-19 09:13:15 +01:00
|
|
|
obj = self.env["account.move.make.netting"].with_context(
|
|
|
|
active_ids=[self.move_line_1.id]
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
with self.assertRaises(Exception):
|
|
|
|
wizard = obj.create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"move_line_ids": [(6, 0, [self.move_line_1.id])],
|
|
|
|
"journal_id": self.miscellaneous_journal.id,
|
|
|
|
}
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
# Test exception line 39 from account_move_make_netting
|
2020-03-19 09:13:15 +01:00
|
|
|
obj = self.env["account.move.make.netting"].with_context(
|
|
|
|
active_ids=[self.move_line_1.id, self.move_line_3.id]
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
with self.assertRaises(Exception):
|
|
|
|
wizard = obj.create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"move_line_ids": [
|
|
|
|
(6, 0, [self.move_line_1.id, self.move_line_3.id])
|
|
|
|
],
|
|
|
|
"journal_id": self.miscellaneous_journal.id,
|
|
|
|
}
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
# Test exception line 45 from account_move_make_netting
|
2020-03-19 09:13:15 +01:00
|
|
|
obj = self.env["account.move.make.netting"].with_context(
|
|
|
|
active_ids=[self.move_line_4.id, self.move_line_5.id]
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
with self.assertRaises(Exception):
|
|
|
|
wizard = obj.create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"move_line_ids": [
|
|
|
|
(6, 0, [self.move_line_4.id, self.move_line_5.id])
|
|
|
|
],
|
|
|
|
"journal_id": self.miscellaneous_journal.id,
|
|
|
|
}
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
# Test exception line 42 from account_move_make_netting
|
2020-03-19 09:13:15 +01:00
|
|
|
moves = self.env["account.move.line"].browse(
|
|
|
|
[self.move_line_4.id, self.move_line_5.id]
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
moves.reconcile()
|
2020-03-19 09:13:15 +01:00
|
|
|
obj = self.env["account.move.make.netting"].with_context(
|
|
|
|
active_ids=[self.move_line_4.id, self.move_line_5.id]
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
with self.assertRaises(Exception):
|
|
|
|
wizard = obj.create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"move_line_ids": [
|
|
|
|
(6, 0, [self.move_line_4.id, self.move_line_5.id])
|
|
|
|
],
|
|
|
|
"journal_id": self.miscellaneous_journal.id,
|
|
|
|
}
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
# Test exception line 52 from account_move_make_netting
|
2020-03-19 09:13:15 +01:00
|
|
|
obj = self.env["account.move.make.netting"].with_context(
|
|
|
|
active_ids=[self.move_line_1.id, self.move_line_6.id]
|
|
|
|
)
|
2018-01-25 14:11:48 +01:00
|
|
|
with self.assertRaises(Exception):
|
|
|
|
wizard = obj.create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"move_line_ids": [
|
|
|
|
(6, 0, [self.move_line_1.id, self.move_line_6.id])
|
|
|
|
],
|
|
|
|
"journal_id": self.miscellaneous_journal.id,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
obj = self.env["account.move.make.netting"].with_context(
|
|
|
|
active_ids=[self.move_line_1.id, self.move_line_2.id]
|
|
|
|
)
|
2015-08-07 18:05:03 +02:00
|
|
|
wizard = obj.create(
|
2020-03-19 09:13:15 +01:00
|
|
|
{
|
|
|
|
"move_line_ids": [(6, 0, [self.move_line_1.id, self.move_line_2.id])],
|
|
|
|
"journal_id": self.miscellaneous_journal.id,
|
|
|
|
}
|
|
|
|
)
|
2015-08-07 18:05:03 +02:00
|
|
|
res = wizard.button_compensate()
|
2020-03-19 09:13:15 +01:00
|
|
|
move = self.env["account.move"].browse(res["res_id"])
|
2015-08-07 18:05:03 +02:00
|
|
|
self.assertEqual(
|
2020-03-19 09:13:15 +01:00
|
|
|
len(move.line_ids), 2, "AR/AP netting move has an incorrect line number"
|
|
|
|
)
|
2017-10-13 17:27:59 +02:00
|
|
|
move_line_receivable = move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == self.account_receivable
|
|
|
|
)
|
2015-08-07 18:05:03 +02:00
|
|
|
self.assertEqual(
|
2020-03-19 09:13:15 +01:00
|
|
|
move_line_receivable.credit,
|
|
|
|
100,
|
|
|
|
"Incorrect credit amount for receivable move line",
|
|
|
|
)
|
2015-08-07 18:05:03 +02:00
|
|
|
self.assertTrue(
|
2020-03-19 09:13:15 +01:00
|
|
|
move_line_receivable.reconciled and move_line_receivable.full_reconcile_id,
|
|
|
|
"Receivable move line should be totally reconciled",
|
|
|
|
)
|
2017-10-13 17:27:59 +02:00
|
|
|
move_line_payable = move.line_ids.filtered(
|
2020-03-19 09:13:15 +01:00
|
|
|
lambda x: x.account_id == self.account_payable
|
|
|
|
)
|
2015-08-07 18:05:03 +02:00
|
|
|
self.assertEqual(
|
2020-03-19 09:13:15 +01:00
|
|
|
move_line_payable.debit, 100, "Incorrect debit amount for payable move line"
|
|
|
|
)
|
2015-08-07 18:05:03 +02:00
|
|
|
self.assertTrue(
|
2020-03-19 09:13:15 +01:00
|
|
|
move_line_payable.reconciled and not move_line_payable.full_reconcile_id,
|
|
|
|
"Receivable move line should be partially reconciled",
|
|
|
|
)
|