-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] product_multi_barcode_constraint_per_company
Fix test
- Loading branch information
1 parent
973bc59
commit 51df296
Showing
4 changed files
with
54 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
from . import models | ||
|
||
from odoo.addons.product_barcode_constraint_per_company.tests.test_module import ( | ||
TestModule, | ||
) | ||
import unittest | ||
|
||
|
||
@unittest.skip | ||
def void(self): | ||
return | ||
|
||
|
||
TestModule.test_create_same_company = void | ||
TestModule.test_create_different_company = void |
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
39 changes: 37 additions & 2 deletions
39
product_multi_barcode_constraint_per_company/tests/test_product_barcode_constraint.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 |
---|---|---|
@@ -1,20 +1,55 @@ | ||
# Copyright 2023 Cetmix OÜ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
|
||
import types | ||
|
||
from psycopg2 import IntegrityError | ||
|
||
from odoo import _ | ||
from odoo.exceptions import UserError | ||
from odoo.tools.misc import mute_logger | ||
|
||
from odoo.addons.product_barcode_constraint_per_company.tests.test_module import ( | ||
TestModule, | ||
) | ||
|
||
from .. import void | ||
|
||
|
||
class TestProductBarcodeConstraint(TestModule): | ||
def test_void(self): | ||
self.assertIsInstance( | ||
void(None), types.FunctionType, msg="Type must be Function" | ||
) | ||
|
||
def test_create_same_company(self): | ||
product_1 = self._create_product("Product 11", self.company_1) | ||
self.assertEqual(product_1.company_id, self.company_1) | ||
self.assertEqual(product_1.product_tmpl_id.company_id, self.company_1) | ||
|
||
msg = _( | ||
'The Barcode "%(barcode_name)s" already exists for ' | ||
'product "%(product_name)s" in the company %(company_name)s' | ||
) % dict( | ||
barcode_name=product_1.barcode, | ||
product_name=product_1.name, | ||
company_name=product_1.product_tmpl_id.company_id.name, | ||
) | ||
|
||
product_2 = self.ProductProduct.create( | ||
{ | ||
"name": product_1.name, | ||
"company_id": self.company_1.id, | ||
} | ||
) | ||
|
||
with self.assertRaises(UserError, msg=msg): | ||
product_2.barcode = "978020137962" | ||
|
||
with self.assertRaises(IntegrityError), mute_logger("odoo.sql_db"): | ||
product2 = self._create_product("Product 2", self.company_1) | ||
product2.flush() | ||
self._create_product("Product 2", self.company_1) | ||
|
||
def test_create_different_company(self): | ||
self._create_product("Product 1", self.company_1) | ||
self._create_product("Product 2", self.company_2) |