Skip to content

Commit

Permalink
[18.0][MIG] partner_stage: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
BertVGroenendael committed Oct 22, 2024
1 parent 06fb1b2 commit 891b29f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 7 deletions.
2 changes: 2 additions & 0 deletions partner_stage/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Contributors

- Maksym Yankin [email protected]

- Bert Van Groenendael <[email protected]>

Maintainers
-----------

Expand Down
2 changes: 2 additions & 0 deletions partner_stage/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
* `Camptocamp <https://www.camptocamp.com>`__:

* Maksym Yankin <[email protected]>

- Bert Van Groenendael \<<[email protected]>\>
2 changes: 1 addition & 1 deletion partner_stage/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink"
"access_partner_stage_edit","access_partner_stage_edit","model_res_partner_stage","base.group_system",1,1,1,1
"access_partner_stage_read","access_partner_stage_read","model_res_partner_stage",,1,0,0,0
"access_partner_stage_read","access_partner_stage_read","model_res_partner_stage","base.group_user",1,0,0,0
1 change: 1 addition & 0 deletions partner_stage/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Maksym Yankin <a class="reference external" href="mailto:maksym.yankin&#64;camptocamp.com">maksym.yankin&#64;camptocamp.com</a></li>
</ul>
</li>
<li>Bert Van Groenendael &lt;<a class="reference external" href="mailto:bert.vangroenendael&#64;dynapps.eu">bert.vangroenendael&#64;dynapps.eu</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
60 changes: 57 additions & 3 deletions partner_stage/tests/test_partner_stage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright 2021 Open Source Integrators
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.exceptions import ValidationError
from odoo.tests.common import TransactionCase

from .. import post_init_hook


class TestPartnerStage(TransactionCase):
@classmethod
Expand All @@ -12,13 +13,66 @@ def setUpClass(cls):
cls.Stage = cls.env["res.partner.stage"]
cls.Partner = cls.env["res.partner"]

def test_01_partner_stage(self):
# Create some test partners without a stage
cls.partner_1 = cls.env["res.partner"].create(
{
"name": "Partner 1",
"stage_id": False,
}
)
cls.partner_2 = cls.env["res.partner"].create(
{
"name": "Partner 2",
"stage_id": False,
}
)

def test_01_post_init_hook(self):
"""Test post_init_hook sets the default stage on partners without stage_id"""

# Ensure partners initially have no stage
self.assertFalse(self.partner_1.stage_id)
self.assertFalse(self.partner_2.stage_id)

post_init_hook(self.env)

# Reload the partners from the database to get the updated values
self.partner_1.invalidate_recordset()
self.partner_2.invalidate_recordset()

# Check if partners' stages have been updated
self.assertEqual(
self.partner_1.stage_id, self.env.ref("partner_stage.partner_stage_active")
)
self.assertEqual(
self.partner_2.stage_id, self.env.ref("partner_stage.partner_stage_active")
)
self.assertEqual(self.partner_1.stage_id.state, "confirmed")
self.assertEqual(self.partner_2.stage_id.state, "confirmed")

post_init_hook(self.env)

# Reload the partners from the database to get the updated values
self.partner_1.invalidate_recordset()
self.partner_2.invalidate_recordset()

# Check if partners' stages have been updated
self.assertEqual(
self.partner_1.stage_id, self.env.ref("partner_stage.partner_stage_active")
)
self.assertEqual(
self.partner_2.stage_id, self.env.ref("partner_stage.partner_stage_active")
)
self.assertEqual(self.partner_1.stage_id.state, "confirmed")
self.assertEqual(self.partner_2.stage_id.state, "confirmed")

def test_02_partner_stage(self):
default_stage = self.env.ref("partner_stage.partner_stage_active")
new_partner = self.Partner.create({"name": "A Partner"})
self.assertTrue(new_partner.stage_id, default_stage)
states = new_partner._read_group_stage_id(self.Stage, [], None)
self.assertTrue(states.ids, [1, 2, 3])

def test_02_stage_default_constraint(self):
def test_03_stage_default_constraint(self):
with self.assertRaises(ValidationError):
self.Stage.create({"name": "Another Default Stage", "is_default": True})
6 changes: 3 additions & 3 deletions partner_stage/views/res_partner_stage_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@
<record id="view_partner_stage_tree" model="ir.ui.view">
<field name="model">res.partner.stage</field>
<field name="arch" type="xml">
<tree>
<list>
<field name="sequence" widget="handle" />
<field name="name" />
<field name="state" />
<field name="code" />
<field name="description" />
</tree>
</list>
</field>
</record>

<record model="ir.actions.act_window" id="action_partner_stage">
<field name="name">Stage</field>
<field name="res_model">res.partner.stage</field>
<field name="view_mode">tree,form</field>
<field name="view_mode">list,form</field>
</record>

<record model="ir.ui.menu" id="menu_partner_stage">
Expand Down

0 comments on commit 891b29f

Please sign in to comment.