[MIG] account_move_template: Migration to 15.0

This commit is contained in:
Andy Quijada [Vauxoo]
2022-06-02 19:15:16 -04:00
committed by Abraham Anes
parent 2c088bcfde
commit af14d2afb6
6 changed files with 152 additions and 58 deletions

View File

@@ -1,6 +1,7 @@
# Copyright 2020 Ecosoft (http://ecosoft.co.th)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo.exceptions import ValidationError
from odoo import Command
from odoo.exceptions import UserError, ValidationError
from odoo.tests.common import Form, TransactionCase
@@ -69,9 +70,9 @@ class TestAccountMoveTemplateEnhanced(TransactionCase):
"name": "Test Template",
"journal_id": self.journal.id,
"line_ids": [
(0, 0, ar_line),
(0, 0, income_line1),
(0, 0, income_line2),
Command.create(ar_line),
Command.create(income_line1),
Command.create(income_line2),
],
}
)
@@ -143,7 +144,8 @@ class TestAccountMoveTemplateEnhanced(TransactionCase):
}
)
template_run = f.save()
with self.assertRaises(ValidationError):
msg_error = "overwrite are .'partner_id', 'amount', 'name', 'date_maturity'"
with self.assertRaisesRegex(ValidationError, msg_error):
template_run.load_lines()
# Assign only on valid fields, and load_lines again
with Form(self.env["account.move.template.run"]) as f:
@@ -159,7 +161,7 @@ class TestAccountMoveTemplateEnhanced(TransactionCase):
res = template_run.load_lines()
self.assertEqual(template_run.line_ids[0].partner_id, self.partners[0])
self.assertEqual(template_run.line_ids[0].amount, 3000)
res = template_run.with_context(res["context"]).generate_move()
res = template_run.with_context(**res["context"]).generate_move()
move = self.Move.browse(res["res_id"])
self.assertRecordValues(
move.line_ids.sorted("credit"),
@@ -184,3 +186,86 @@ class TestAccountMoveTemplateEnhanced(TransactionCase):
},
],
)
def test_move_copy(self):
template_copy = self.move_template.copy()
self.assertEqual(template_copy.name, "Test Template (copy)")
def test_move_generate_from_action_button(self):
# `Generate Journal Entry` action button
res = self.move_template.generate_journal_entry()
self.assertEqual(res["name"], "Create Entry from Template")
self.assertEqual(res["res_model"], "account.move.template.run")
def test_move_template_exceptions(self):
msg_error = "Python Code must be set for computed line with sequence 1."
with self.assertRaisesRegex(ValidationError, msg_error):
self.move_template.line_ids[1].python_code = ""
self.move_template.line_ids[1].python_code = "P0*1/3"
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
template_run = f.save()
template_run.load_lines()
msg_error = "really exists and have a lower sequence than the current line."
with self.assertRaisesRegex(UserError, msg_error):
template_run.generate_move()
self.move_template.line_ids[1].python_code = "L0*"
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
template_run = f.save()
template_run.load_lines()
msg_error = "the syntax of the formula is wrong."
with self.assertRaisesRegex(UserError, msg_error):
template_run.generate_move()
self.move_template.line_ids[1].python_code = "L0*1/3"
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
template_run = f.save()
template_run.load_lines()
template_run.line_ids[0].amount = 0
msg_error = "Debit and credit of all lines are null."
with self.assertRaisesRegex(UserError, msg_error):
template_run.generate_move()
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
f.overwrite = []
template_run = f.save()
msg_error = "Overwrite value must be a valid python dict"
with self.assertRaisesRegex(ValidationError, msg_error):
template_run.load_lines()
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
f.overwrite = str({"P0": {"amount": 100}})
template_run = f.save()
msg_error = "Keys must be line sequence, i..e, L1, L2, ..."
with self.assertRaisesRegex(ValidationError, msg_error):
template_run.load_lines()
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
f.overwrite = str({"L0": []})
template_run = f.save()
msg_error = "Invalid dictionary: 'list' object has no attribute 'keys'"
with self.assertRaisesRegex(ValidationError, msg_error):
template_run.load_lines()
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
f.overwrite = str({"L0": {"test": 100}})
template_run = f.save()
msg_error = "overwrite are .'partner_id', 'amount', 'name', 'date_maturity'"
with self.assertRaisesRegex(ValidationError, msg_error):
template_run.load_lines()
with Form(self.env["account.move.template.run"]) as f:
f.template_id = self.move_template
template_run = f.save()
template_run.line_ids.unlink()
msg_error = "You deleted a line in the wizard. This is not allowed:"
with self.assertRaisesRegex(UserError, msg_error):
template_run.generate_move()