[MIG] stock_picking_comment_template: Migration to 14.0

This commit is contained in:
Alfredo Zamora
2021-05-31 12:58:20 +02:00
parent 8b855e6d02
commit fd006d845a
16 changed files with 113 additions and 163 deletions

View File

@@ -1,4 +1,3 @@
# Copyright 2019 C2i Change 2 improve - Eduardo Magdalena <emagdalena@c2i.es>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_stock_picking_report

View File

@@ -5,15 +5,20 @@ from odoo.tests.common import TransactionCase
class TestStockPickingReport(TransactionCase):
at_install = False
post_install = True
def setUp(self):
super(TestStockPickingReport, self).setUp()
super().setUp()
self.company = self.env.ref("base.main_company")
self.base_comment_model = self.env["base.comment.template"]
self.before_comment = self._create_comment("before_lines")
self.after_comment = self._create_comment("after_lines")
# Create comment related to sale model
self.picking_obj = self.env.ref("stock.model_stock_picking")
self.before_comment = self._create_comment(self.picking_obj, "before_lines")
self.after_comment = self._create_comment(self.picking_obj, "after_lines")
# Create partner
self.partner = self.env["res.partner"].create({"name": "Partner Test"})
self.partner.base_comment_template_ids = [
(4, self.before_comment.id),
(4, self.after_comment.id),
]
self.picking_model = self.env["stock.picking"]
self.picking = self.picking_model.create(
{
@@ -21,41 +26,34 @@ class TestStockPickingReport(TransactionCase):
"location_id": self.ref("stock.stock_location_stock"),
"location_dest_id": self.ref("stock.stock_location_customers"),
"picking_type_id": self.ref("stock.picking_type_out"),
"comment_template1_id": self.before_comment.id,
"comment_template2_id": self.after_comment.id,
}
)
self.picking._set_note1()
self.picking._set_note2()
def _create_comment(self, position):
def _create_comment(self, model, position):
return self.base_comment_model.create(
{
"name": "Comment " + position,
"company_id": self.company.id,
"position": position,
"text": "Text " + position,
"model_ids": [(6, 0, model.ids)],
}
)
def test_comments_in_picking(self):
def test_comments_in_deliveryslip(self):
res = (
self.env["ir.actions.report"]
._get_report_from_name("stock.report_deliveryslip")
._render_qweb_html(self.picking.ids)
)
self.assertRegex(str(res[0]), self.before_comment.text)
self.assertRegex(str(res[0]), self.after_comment.text)
def test_comments_in_report_picking(self):
res = (
self.env["ir.actions.report"]
._get_report_from_name("stock.report_picking")
.render_qweb_html(self.picking.ids)
._render_qweb_html(self.picking.ids)
)
self.assertRegexpMatches(str(res[0]), self.before_comment.text)
self.assertRegexpMatches(str(res[0]), self.after_comment.text)
def test_onchange_partner_id(self):
self.partner.comment_template_id = self.after_comment.id
new_picking = self.env["stock.picking"].new(
{
"partner_id": self.partner.id,
}
)
new_picking._onchange_partner_id()
self.assertEqual(new_picking.comment_template2_id, self.after_comment)
self.partner.comment_template_id = self.before_comment.id
new_picking._onchange_partner_id()
self.assertEqual(new_picking.comment_template1_id, self.before_comment)
self.assertRegex(str(res[0]), self.before_comment.text)
self.assertRegex(str(res[0]), self.after_comment.text)