2019-04-25 16:57:45 +02:00
|
|
|
# Copyright 2019 Tecnativa - Ernesto Tejeda
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
|
|
|
|
import odoo.tests.common as common
|
2020-01-30 18:23:55 +01:00
|
|
|
from odoo import fields
|
2019-04-25 16:57:45 +02:00
|
|
|
|
|
|
|
|
2022-10-11 15:26:40 +02:00
|
|
|
class TestAccountMoveLineTaxEditable(common.TransactionCase):
|
2019-04-25 16:57:45 +02:00
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2022-10-11 15:26:40 +02:00
|
|
|
super().setUpClass()
|
2019-04-25 16:57:45 +02:00
|
|
|
|
2020-01-30 18:23:55 +01:00
|
|
|
acc_obj = cls.env["account.account"]
|
|
|
|
account100 = acc_obj.create(
|
|
|
|
{
|
|
|
|
"code": "100",
|
|
|
|
"name": "Account 100",
|
|
|
|
"user_type_id": cls.env.ref("account.data_account_type_receivable").id,
|
|
|
|
"reconcile": True,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
account300 = acc_obj.create(
|
|
|
|
{
|
|
|
|
"code": "300",
|
|
|
|
"name": "Account 300",
|
|
|
|
"user_type_id": cls.env.ref(
|
|
|
|
"account.data_account_type_other_income"
|
|
|
|
).id,
|
|
|
|
}
|
|
|
|
)
|
2019-04-25 16:57:45 +02:00
|
|
|
|
2020-01-30 18:23:55 +01:00
|
|
|
journal = cls.env["account.journal"].create(
|
|
|
|
{"name": "Test journal", "type": "sale", "code": "TEST"}
|
|
|
|
)
|
2019-04-25 16:57:45 +02:00
|
|
|
move_vals = {
|
2020-01-30 18:23:55 +01:00
|
|
|
"journal_id": journal.id,
|
|
|
|
"name": "move test",
|
|
|
|
"date": fields.Date.today(),
|
|
|
|
"line_ids": [
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
2022-03-01 09:01:56 +01:00
|
|
|
"name": "move test line 1",
|
2020-01-30 18:23:55 +01:00
|
|
|
"debit": 0.0,
|
|
|
|
"credit": 1000.0,
|
|
|
|
"account_id": account300.id,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
2022-03-01 09:01:56 +01:00
|
|
|
"name": "move test line 2",
|
2020-01-30 18:23:55 +01:00
|
|
|
"debit": 1000.0,
|
|
|
|
"credit": 0.0,
|
|
|
|
"account_id": account100.id,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
cls.move = cls.env["account.move"].create(move_vals)
|
2022-03-01 09:01:56 +01:00
|
|
|
cls.tax15 = cls.env["account.tax"].create(
|
|
|
|
{
|
|
|
|
"name": "Test tax 15",
|
|
|
|
"amount": 15,
|
|
|
|
}
|
|
|
|
)
|
2019-04-25 16:57:45 +02:00
|
|
|
|
|
|
|
def test_compute_is_tax_editable(self):
|
2020-01-30 18:23:55 +01:00
|
|
|
self.assertEqual(self.move.line_ids.mapped("is_tax_editable"), [True, True])
|
2021-03-09 17:29:52 +01:00
|
|
|
self.move.action_post()
|
2020-01-30 18:23:55 +01:00
|
|
|
self.assertEqual(self.move.line_ids.mapped("is_tax_editable"), [False, False])
|
2022-03-01 09:01:56 +01:00
|
|
|
|
|
|
|
def test_tax_edited(self):
|
|
|
|
line1 = self.move.line_ids[0]
|
|
|
|
line1.tax_line_id = self.tax15.id
|
|
|
|
line2 = self.move.line_ids[1]
|
|
|
|
self.move.action_post()
|
|
|
|
self.assertEqual(line1.tax_line_id.id, self.tax15.id)
|
|
|
|
self.assertEqual(line2.tax_line_id.id, False)
|
|
|
|
self.assertEqual(line1.tax_repartition_line_id.tax_id.id, self.tax15.id)
|
|
|
|
|
|
|
|
def test_tax_not_edited(self):
|
|
|
|
"""In this case we set the tax_repartition_line_id field, simulating that the
|
|
|
|
move came from an invoice with tax applied. Thus, tax_line_id should be computed"""
|
|
|
|
line1 = self.move.line_ids[1]
|
|
|
|
line1.tax_repartition_line_id = self.tax15.invoice_repartition_line_ids[1]
|
|
|
|
self.assertEqual(line1.tax_line_id.id, self.tax15.id)
|