This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #274 from OpenSPP/273-unique-id-on-area-and-servic…
…e-point [UPD] add unique_id to service point and area
- Loading branch information
Showing
14 changed files
with
277 additions
and
109 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
from . import res_partner | ||
from . import spp_area | ||
from . import spp_service_point |
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,12 @@ | ||
from odoo import models | ||
|
||
|
||
class SppArea(models.Model): | ||
_name = "spp.area" | ||
_inherit = ["spp.area", "spp.unique.id"] | ||
|
||
def _get_spp_id_prefix(self): | ||
return "LOC" | ||
|
||
def _get_match_spp_id_pattern(self): | ||
return r"^LOC_[0-9A-Z]{8}$" |
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,12 @@ | ||
from odoo import models | ||
|
||
|
||
class SppServicePoint(models.Model): | ||
_name = "spp.service.point" | ||
_inherit = ["spp.service.point", "spp.unique.id"] | ||
|
||
def _get_spp_id_prefix(self): | ||
return "SVP" | ||
|
||
def _get_match_spp_id_pattern(self): | ||
return r"^SVP_[0-9A-Z]{8}$" |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
from . import test_area | ||
from . import test_registrant | ||
from . import test_service_point |
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,58 @@ | ||
from psycopg2.errors import UniqueViolation | ||
|
||
from odoo.exceptions import ValidationError | ||
from odoo.tests import TransactionCase | ||
from odoo.tools import mute_logger | ||
|
||
EXCLUDED_CHARACTERS = ["0", "O", "1", "I"] | ||
|
||
|
||
class TestArea(TransactionCase): | ||
def setUp(self): | ||
super().setUp() | ||
self.area_1, self.area_2 = self.env["spp.area"].create( | ||
[ | ||
{"draft_name": "Area 1"}, | ||
{"draft_name": "Area 2"}, | ||
] | ||
) | ||
|
||
def test_01_compute_spp_id_uniq(self): | ||
self.assertNotEqual(self.area_1.spp_id, self.area_2.spp_id) | ||
|
||
def test_02_compute_spp_id(self): | ||
for area in [self.area_1, self.area_2]: | ||
self.assertRegex( | ||
area.spp_id, | ||
r"^LOC_[a-zA-Z0-9]{8}$", | ||
"Area should have unique id start with " | ||
"`LOC_` and following by 8 characters.", | ||
) | ||
for char in EXCLUDED_CHARACTERS: | ||
self.assertNotIn( | ||
char, | ||
area.spp_id.split("_")[-1], | ||
"Excluded characters should not be exist in spp_id", | ||
) | ||
|
||
@mute_logger("odoo.sql_db") | ||
def test_03_spp_id_unique_violation(self): | ||
with self.assertRaises(UniqueViolation): | ||
self.area_1.write( | ||
{ | ||
"spp_id": self.area_2.spp_id, | ||
} | ||
) | ||
|
||
@mute_logger("py.warnings") | ||
def test_04_check_spp_id(self): | ||
with self.assertRaisesRegex( | ||
ValidationError, "^.*not following correct format.{1}$" | ||
): | ||
# 7 characters spp_id | ||
self.area_1.write({"spp_id": "LOC_AaAaAa2"}) | ||
with self.assertRaisesRegex( | ||
ValidationError, "^.*not following correct format.{1}$" | ||
): | ||
# '1' in spp_id | ||
self.area_2.write({"spp_id": "LOC_AaAaAa21"}) |
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
Oops, something went wrong.