-
-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] crm_required_field_by_stage: Migration
- Loading branch information
Tiago Amaral
committed
Sep 30, 2024
1 parent
765d9e0
commit 2a8adec
Showing
8 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_crm_required_field_by_stage |
56 changes: 56 additions & 0 deletions
56
crm_required_field_by_stage/tests/test_crm_required_field_by_stage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 KMEE | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import ast | ||
|
||
from odoo.exceptions import UserError | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestCrmRequiredFieldByStage(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
|
||
self.crm_stage_model = self.env["crm.stage"] | ||
self.crm_lead_model = self.env["crm.lead"] | ||
self.crm_stage_1 = self.crm_stage_model.create( | ||
{ | ||
"name": "CRM Stage 1", | ||
"required_field_ids": [ | ||
(4, self.env.ref("crm.field_crm_lead__phone").id) | ||
], | ||
} | ||
) | ||
self.crm_lead_1 = self.crm_lead_model.create( | ||
{ | ||
"name": "CRM Lead 1", | ||
} | ||
) | ||
|
||
def test_locking(self): | ||
with self.assertRaises(UserError): | ||
self.crm_lead_1.write( | ||
{ | ||
"stage_id": self.crm_stage_1.id, | ||
} | ||
) | ||
self.assertTrue(self.crm_lead_1.stage_id) | ||
self.crm_lead_1.write( | ||
{ | ||
"phone": "(00) 0000-0000", | ||
} | ||
) | ||
self.crm_lead_1.write( | ||
{ | ||
"stage_id": self.crm_stage_1.id, | ||
} | ||
) | ||
self.assertEqual(self.crm_lead_1.stage_id.id, self.crm_stage_1.id) | ||
|
||
def test_get_view_required_fields(self): | ||
arch, view = self.crm_lead_1._get_view(view_type="form") | ||
node = arch.xpath("//field[@name='phone']") | ||
self.assertTrue(node) | ||
attrs = ast.literal_eval(node[0].attrib.get("attrs", "{}")) | ||
self.assertIn("required", attrs) | ||
self.assertIn(self.crm_stage_1.id, attrs["required"][0][2]) |
1 change: 1 addition & 0 deletions
1
setup/crm_required_field_by_stage/odoo/addons/crm_required_field_by_stage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../crm_required_field_by_stage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |