Skip to content

Commit

Permalink
fix typo and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scigghia committed May 21, 2022
1 parent 3dbbe5f commit c391626
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contract_sequence/models/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ContractContract(models.Model):
tracking=True,
help="Set to '/' and save if you want a new internal reference "
"to be proposed.",
copy="False",
copy=False,
)

def get_default_sequence(self):
Expand Down
4 changes: 4 additions & 0 deletions contract_sequence/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2022 Andrea Cometa - Apulia Software (www.apuliasoftware.it)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import test_contract_sequence
90 changes: 90 additions & 0 deletions contract_sequence/tests/test_contract_sequence.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright 2022 Andrea Cometa - Apulia Software (www.apuliasoftware.it)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase, tagged

from ..hooks import pre_init_hook


@tagged("post_install", "-at_install")
class TestContractSequence(TransactionCase):
"""Tests for creating Contract with and without Sequence"""

def setUp(self):
super(TestContractSequence, self).setUp()
self.contract_contract = self.env["contract.contract"]
self.contract_template = self.env["contract.template"].create(
{
"name": "Test Contract template",
}
)
self.pricelist = self.env["product.pricelist"].create(
{
"name": "pricelist for contract test",
}
)
self.partner = self.env["res.partner"].create(
{
"name": "partner test contract",
"property_product_pricelist": self.pricelist.id,
"email": "[email protected]",
}
)

def test_contract_create_with_manual_code(self):
contract = self.contract_contract.create(
{
"name": "C/22/0001",
"code": "Contract with manual code",
"partner_id": self.partner.id,
}
)
self.assertEqual(contract.name, "C/22/0001")
contract_new = self.contract_contract.create(
{
"code": "Contract with template",
"partner_id": self.partner.id,
"contract_template_id": self.contract_template.id,
}
)
self.assertTrue(contract_new.name)

def test_contract_create_without_code(self):
contract_1 = self.contract_contract.create(
{
"code": "Contract nr 1",
"name": "/",
"partner_id": self.partner.id,
}
)
self.assertRegex(str(contract_1.name), r"CON/*")

def test_contract_copy(self):
contract_2 = self.contract_contract.create(
{
"code": "Contract nr 2",
"name": "CON/22/0002",
"partner_id": self.partner.id,
}
)
contract_2.flush()
copy_contract_2 = contract_2.copy()
self.assertTrue(copy_contract_2.name[:11] != contract_2.name)

def test_pre_init_hook(self):
contract_3 = self.contract_contract.create(
{
"code": "Contract nr 3",
"name": "CON/22/0003",
"partner_id": self.partner.id,
}
)
self.cr.execute(
"update contract_contract set name='/' where id=%s",
(tuple(contract_3.ids),),
)
contract_3.invalidate_cache()
self.assertEqual(contract_3.name, "/")
pre_init_hook(self.cr)
contract_3.invalidate_cache()
self.assertEqual(contract_3.name, "!!mig!!{}".format(contract_3.id))

0 comments on commit c391626

Please sign in to comment.