-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
101 additions
and
0 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 |
---|---|---|
@@ -0,0 +1 @@ | ||
auto |
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 models |
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,14 @@ | ||
{ | ||
"name": "Base Tools", | ||
"summary": "Utilities that can be used in projects", | ||
"version": "16.0.1.0.0", | ||
"category": "Tools", | ||
"website": "https://github.com/akretion/ak-odoo-incubator", | ||
"author": " Akretion", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"product", | ||
], | ||
"data": [], | ||
"installable": True, | ||
} |
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 base |
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,41 @@ | ||
import logging | ||
|
||
from odoo import models | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Base(models.AbstractModel): | ||
_inherit = "base" | ||
|
||
def _unknown_data_in_field(self, model, field, data_list, company_id=None): | ||
"""Compare a data list with matching db data as specified model / field | ||
Example: | ||
model is "product.product" | ||
field is "default_code" | ||
data_list is ["FURN_7777", "ANY", "E-COM07", "E-COM08", "MISS-TEAK"] | ||
return missing data is ["ANY", "MISS-TEAK"] | ||
""" | ||
|
||
def unique(my_list): | ||
return sorted(set(my_list)) | ||
|
||
domain = [(field, "in", data_list)] | ||
if company_id: | ||
domain += [("company_id", "=", company_id)] | ||
data_list = unique(data_list) | ||
known_data = [x[field] for x in self.env[model].search(domain)] | ||
|
||
known_data = unique(known_data) | ||
unknown_data = [x for x in data_list if x not in known_data] | ||
if unknown_data: | ||
logger.info( | ||
f" >>> These data are not in this field {field} " | ||
f"in model {model} in db '{self.env.cr.dbname}'." | ||
) | ||
else: | ||
logger.info( | ||
f"Great! all provided data are present db {self.env.cr.dbname}." | ||
) | ||
return unknown_data |
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 @@ | ||
This contains misc utilities tool scripts that can be used in your projects. |
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_module |
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,34 @@ | ||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class Test(TransactionCase): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
cls.user_model = cls.env["res.users"].with_context(no_reset_password=True) | ||
|
||
def test_no_missing_data_in_default_code(self): | ||
data_list = ["E-COM07", "FURN_7777", "FURN_6666"] | ||
unknown_data = self.unknown_data_in_default_code(data_list) | ||
assert not unknown_data | ||
|
||
def test_missing_data_in_default_code(self): | ||
data_list = ["FURN_7777", "ANY", "E-COM07", "E-COM08", "MISS-TEAK"] | ||
unknown_data = self.unknown_data_in_default_code(data_list) | ||
assert unknown_data == ["ANY", "MISS-TEAK"] | ||
|
||
def test_missing_data_in_default_code_with_company(self): | ||
data_list = ["FURN_7777", "ANY", "MISS-TEAK"] | ||
self.env["product.product"].create( | ||
{"default_code": "ANY", "name": "ANY", "company_id": 1} | ||
) | ||
unknown_data = self.env["base"]._unknown_data_in_field( | ||
"product.product", "default_code", data_list, company_id=1 | ||
) | ||
assert unknown_data == ["ANY", "MISS-TEAK"] | ||
|
||
def unknown_data_in_default_code(self, data_list): | ||
return self.env["base"]._unknown_data_in_field( | ||
"product.product", "default_code", data_list | ||
) |
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 @@ | ||
../../../../base_tool |
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, | ||
) |