diff --git a/sequence_check_digit/README.rst b/sequence_check_digit/README.rst new file mode 100644 index 0000000000..d3bc5bb1b3 --- /dev/null +++ b/sequence_check_digit/README.rst @@ -0,0 +1,101 @@ +======================== +Check Digit on Sequences +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e86db4afe0793461a9926db33ec5b1088191754ed9cde91f4fa2990f25c5f202 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png + :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html + :alt: License: LGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github + :target: https://github.com/OCA/server-ux/tree/18.0/sequence_check_digit + :alt: OCA/server-ux +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-ux-18-0/server-ux-18-0-sequence_check_digit + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/server-ux&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module was written to configure check digits on sequences added on +the end. It is useful as a control of the number on visual validation. + +It is useful when some manual checks are required or on integrations. +The implemented codes can avoid modification of one character and flip +of two consecutive characters. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Access sequences and configurate the model to use. + +- The model will check if the format of prefix, suffix and number is + valid + +- Implemented algorithms + + - Luhn: [0-9]\* + - Damm: [0-9]\* + - Verhoeff: [0-9]\* + - ISO 7064 Mod 11, 2: [0-9]\* + - ISO 7064 Mod 11, 10: [0-9]\* + - ISO 7064 Mod 37, 2: [0-9A-Z]\* + - ISO 7064 Mod 37, 36: [0-9A-Z]\* + - ISO 7064 Mod 97, 10: [0-9A-Z]\* + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Creu Blanca + +Contributors +------------ + +- Enric Tobella +- Sunanda Chhatbar + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/server-ux `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sequence_check_digit/__init__.py b/sequence_check_digit/__init__.py new file mode 100644 index 0000000000..75d7924518 --- /dev/null +++ b/sequence_check_digit/__init__.py @@ -0,0 +1,3 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import models diff --git a/sequence_check_digit/__manifest__.py b/sequence_check_digit/__manifest__.py new file mode 100644 index 0000000000..67a80ad972 --- /dev/null +++ b/sequence_check_digit/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2017 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Check Digit on Sequences", + "version": "18.0.1.0.0", + "category": "Reporting", + "website": "https://github.com/OCA/server-ux", + "author": "Creu Blanca, Odoo Community Association (OCA)", + "license": "LGPL-3", + "installable": True, + "application": False, + "summary": "Adds a check digit on sequences", + "depends": ["base"], + "data": ["views/sequence_views.xml"], +} diff --git a/sequence_check_digit/i18n/es.po b/sequence_check_digit/i18n/es.po new file mode 100644 index 0000000000..da65ec01e4 --- /dev/null +++ b/sequence_check_digit/i18n/es.po @@ -0,0 +1,104 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_check_digit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-09-28 10:14+0000\n" +"PO-Revision-Date: 2018-07-13 08:48+0000\n" +"Last-Translator: Enric Tobella \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 3.0.1\n" + +#. module: sequence_check_digit +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#, python-format +msgid "%s is not an implemented function" +msgstr "%s no es una función implementada" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence__check_digit_formula +msgid "Check Digit Formula" +msgstr "Fórmula del Dígito de control" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__damm +msgid "Damm" +msgstr "Damm" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence__display_name +msgid "Display Name" +msgstr "" + +#. module: sequence_check_digit +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#, python-format +msgid "Format is not accepted" +msgstr "El formato no está aceptado" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence__id +msgid "ID" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_11_10 +msgid "ISO 7064 Mod 11, 10" +msgstr "ISO 7064 Mod 11, 10" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_11_2 +msgid "ISO 7064 Mod 11, 2" +msgstr "ISO 7064 Mod 11, 2" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_37_2 +msgid "ISO 7064 Mod 37, 2" +msgstr "ISO 7064 Mod 37, 2" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_37_36 +msgid "ISO 7064 Mod 37, 36" +msgstr "ISO 7064 Mod 37, 36" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_97_10 +msgid "ISO 7064 Mod 97, 10" +msgstr "ISO 7064 Mod 97, 10" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence____last_update +msgid "Last Modified on" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__luhn +msgid "Luhn" +msgstr "Luhn" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__none +msgid "None" +msgstr "Ninguno" + +#. module: sequence_check_digit +#: model:ir.model,name:sequence_check_digit.model_ir_sequence +#, fuzzy +msgid "Sequence" +msgstr "ir.sequence" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__verhoeff +msgid "Verhoeff" +msgstr "Verhoeff" + +#~ msgid "Function not found" +#~ msgstr "Función no encontrada" diff --git a/sequence_check_digit/i18n/it.po b/sequence_check_digit/i18n/it.po new file mode 100644 index 0000000000..2029580e50 --- /dev/null +++ b/sequence_check_digit/i18n/it.po @@ -0,0 +1,98 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_check_digit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: sequence_check_digit +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#, python-format +msgid "%s is not an implemented function" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence__check_digit_formula +msgid "Check Digit Formula" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__damm +msgid "Damm" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence__display_name +msgid "Display Name" +msgstr "" + +#. module: sequence_check_digit +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#, python-format +msgid "Format is not accepted" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence__id +msgid "ID" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_11_10 +msgid "ISO 7064 Mod 11, 10" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_11_2 +msgid "ISO 7064 Mod 11, 2" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_37_2 +msgid "ISO 7064 Mod 37, 2" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_37_36 +msgid "ISO 7064 Mod 37, 36" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_97_10 +msgid "ISO 7064 Mod 97, 10" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence____last_update +msgid "Last Modified on" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__luhn +msgid "Luhn" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__none +msgid "None" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model,name:sequence_check_digit.model_ir_sequence +msgid "Sequence" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__verhoeff +msgid "Verhoeff" +msgstr "" diff --git a/sequence_check_digit/i18n/sequence_check_digit.pot b/sequence_check_digit/i18n/sequence_check_digit.pot new file mode 100644 index 0000000000..525031f8b9 --- /dev/null +++ b/sequence_check_digit/i18n/sequence_check_digit.pot @@ -0,0 +1,84 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * sequence_check_digit +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: sequence_check_digit +#. odoo-python +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#, python-format +msgid "%s is not an implemented function" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields,field_description:sequence_check_digit.field_ir_sequence__check_digit_formula +msgid "Check Digit Formula" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__damm +msgid "Damm" +msgstr "" + +#. module: sequence_check_digit +#. odoo-python +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#: code:addons/sequence_check_digit/models/ir_sequence.py:0 +#, python-format +msgid "Format is not accepted" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_11_10 +msgid "ISO 7064 Mod 11, 10" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_11_2 +msgid "ISO 7064 Mod 11, 2" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_37_2 +msgid "ISO 7064 Mod 37, 2" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_37_36 +msgid "ISO 7064 Mod 37, 36" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__iso7064_97_10 +msgid "ISO 7064 Mod 97, 10" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__luhn +msgid "Luhn" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__none +msgid "None" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model,name:sequence_check_digit.model_ir_sequence +msgid "Sequence" +msgstr "" + +#. module: sequence_check_digit +#: model:ir.model.fields.selection,name:sequence_check_digit.selection__ir_sequence__check_digit_formula__verhoeff +msgid "Verhoeff" +msgstr "" diff --git a/sequence_check_digit/models/__init__.py b/sequence_check_digit/models/__init__.py new file mode 100644 index 0000000000..a0d2ff5a33 --- /dev/null +++ b/sequence_check_digit/models/__init__.py @@ -0,0 +1,3 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import ir_sequence diff --git a/sequence_check_digit/models/ir_sequence.py b/sequence_check_digit/models/ir_sequence.py new file mode 100644 index 0000000000..793c47c40c --- /dev/null +++ b/sequence_check_digit/models/ir_sequence.py @@ -0,0 +1,69 @@ +# Copyright (C) 2017 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +import logging + +from odoo import api, fields, models +from odoo.exceptions import ValidationError + +_logger = logging.getLogger(__name__) +try: + from stdnum import damm, luhn, verhoeff + from stdnum.iso7064 import mod_11_2, mod_11_10, mod_37_2, mod_37_36, mod_97_10 +except (OSError, ImportError) as err: + _logger.debug(err) + + +class IrSequence(models.Model): + _inherit = "ir.sequence" + + check_digit_formula = fields.Selection( + selection=[ + ("none", "None"), + ("luhn", "Luhn"), + ("damm", "Damm"), + ("verhoeff", "Verhoeff"), + ("ISO7064_11_2", "ISO 7064 Mod 11, 2"), + ("ISO7064_11_10", "ISO 7064 Mod 11, 10"), + ("ISO7064_37_2", "ISO 7064 Mod 37, 2"), + ("ISO7064_37_36", "ISO 7064 Mod 37, 36"), + ("ISO7064_97_10", "ISO 7064 Mod 97, 10"), + ], + default="none", + ) + + @api.constrains("check_digit_formula", "prefix", "suffix") + def check_check_digit_formula(self): + try: + self.get_next_char(0) + except Exception as err: + raise ValidationError(self.env._("Format is not accepted")) from err + + def get_check_digit(self, code): + try: + return self.get_formula_map()[self.check_digit_formula](code) + except KeyError as err: + raise ValidationError( + self.env._(f"{self.check_digit_formula} is not an implemented function") + ) from err + except Exception as err: + raise ValidationError(self.env._("Format is not accepted")) from err + + def get_formula_map(self): + return { + "none": lambda _: "", + "luhn": luhn.calc_check_digit, + "damm": damm.calc_check_digit, + "verhoeff": verhoeff.calc_check_digit, + "ISO7064_11_2": mod_11_2.calc_check_digit, + "ISO7064_11_10": mod_11_10.calc_check_digit, + "ISO7064_37_2": mod_37_2.calc_check_digit, + "ISO7064_37_36": mod_37_36.calc_check_digit, + "ISO7064_97_10": mod_97_10.calc_check_digits, + } + + def get_next_char(self, number_next): + code = super().get_next_char(number_next) + if not self.check_digit_formula: + return code + return f"{code}{self.get_check_digit(code)}" diff --git a/sequence_check_digit/pyproject.toml b/sequence_check_digit/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/sequence_check_digit/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/sequence_check_digit/readme/CONTRIBUTORS.md b/sequence_check_digit/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..ff028173c6 --- /dev/null +++ b/sequence_check_digit/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- Enric Tobella \<\> +- Sunanda Chhatbar \<\> diff --git a/sequence_check_digit/readme/DESCRIPTION.md b/sequence_check_digit/readme/DESCRIPTION.md new file mode 100644 index 0000000000..4ead5b69ec --- /dev/null +++ b/sequence_check_digit/readme/DESCRIPTION.md @@ -0,0 +1,6 @@ +This module was written to configure check digits on sequences added on +the end. It is useful as a control of the number on visual validation. + +It is useful when some manual checks are required or on integrations. +The implemented codes can avoid modification of one character and flip +of two consecutive characters. diff --git a/sequence_check_digit/readme/USAGE.md b/sequence_check_digit/readme/USAGE.md new file mode 100644 index 0000000000..4ab4b2a104 --- /dev/null +++ b/sequence_check_digit/readme/USAGE.md @@ -0,0 +1,14 @@ +- Access sequences and configurate the model to use. + +- The model will check if the format of prefix, suffix and number is + valid + +- Implemented algorithms + - Luhn: \[0-9\]\* + - Damm: \[0-9\]\* + - Verhoeff: \[0-9\]\* + - ISO 7064 Mod 11, 2: \[0-9\]\* + - ISO 7064 Mod 11, 10: \[0-9\]\* + - ISO 7064 Mod 37, 2: \[0-9A-Z\]\* + - ISO 7064 Mod 37, 36: \[0-9A-Z\]\* + - ISO 7064 Mod 97, 10: \[0-9A-Z\]\* diff --git a/sequence_check_digit/static/description/icon.png b/sequence_check_digit/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/sequence_check_digit/static/description/icon.png differ diff --git a/sequence_check_digit/static/description/index.html b/sequence_check_digit/static/description/index.html new file mode 100644 index 0000000000..7d65941159 --- /dev/null +++ b/sequence_check_digit/static/description/index.html @@ -0,0 +1,448 @@ + + + + + +Check Digit on Sequences + + + +
+

Check Digit on Sequences

+ + +

Beta License: LGPL-3 OCA/server-ux Translate me on Weblate Try me on Runboat

+

This module was written to configure check digits on sequences added on +the end. It is useful as a control of the number on visual validation.

+

It is useful when some manual checks are required or on integrations. +The implemented codes can avoid modification of one character and flip +of two consecutive characters.

+

Table of contents

+ +
+

Usage

+
    +
  • Access sequences and configurate the model to use.
  • +
  • The model will check if the format of prefix, suffix and number is +valid
  • +
  • Implemented algorithms
      +
    • Luhn: [0-9]*
    • +
    • Damm: [0-9]*
    • +
    • Verhoeff: [0-9]*
    • +
    • ISO 7064 Mod 11, 2: [0-9]*
    • +
    • ISO 7064 Mod 11, 10: [0-9]*
    • +
    • ISO 7064 Mod 37, 2: [0-9A-Z]*
    • +
    • ISO 7064 Mod 37, 36: [0-9A-Z]*
    • +
    • ISO 7064 Mod 97, 10: [0-9A-Z]*
    • +
    +
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Creu Blanca
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/server-ux project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sequence_check_digit/tests/__init__.py b/sequence_check_digit/tests/__init__.py new file mode 100644 index 0000000000..d810180f3e --- /dev/null +++ b/sequence_check_digit/tests/__init__.py @@ -0,0 +1,3 @@ +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +from . import test_check_digit diff --git a/sequence_check_digit/tests/test_check_digit.py b/sequence_check_digit/tests/test_check_digit.py new file mode 100644 index 0000000000..9d0d0c9de2 --- /dev/null +++ b/sequence_check_digit/tests/test_check_digit.py @@ -0,0 +1,79 @@ +# Copyright 2017 Creu Blanca +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + + +import logging + +from odoo.exceptions import ValidationError +from odoo.tests import common + +_logger = logging.getLogger(__name__) +try: + from stdnum import damm, luhn, verhoeff + from stdnum.iso7064 import mod_11_2, mod_11_10, mod_37_2, mod_37_36, mod_97_10 +except (OSError, ImportError) as err: + _logger.debug(err) + + +class TestSequenceCheckDigit(common.TransactionCase): + def get_sequence(self, method): + return self.env["ir.sequence"].create( + { + "name": "Test sequence", + "implementation": "standard", + "check_digit_formula": method, + "padding": "5", + } + ) + + def test_none(self): + sequence = self.get_sequence("none") + self.assertEqual("00001", sequence.next_by_id()) + + def test_null(self): + sequence = self.get_sequence(None) + self.assertEqual("00001", sequence.next_by_id()) + + def test_luhn(self): + sequence = self.get_sequence("luhn") + self.assertTrue(luhn.validate(sequence.next_by_id())) + + def test_damm(self): + sequence = self.get_sequence("damm") + self.assertTrue(damm.validate(sequence.next_by_id())) + + def test_verhoeff(self): + sequence = self.get_sequence("verhoeff") + self.assertTrue(verhoeff.validate(sequence.next_by_id())) + + def test_mod_11_2(self): + sequence = self.get_sequence("ISO7064_11_2") + self.assertTrue(mod_11_2.validate(sequence.next_by_id())) + + def test_mod11_10(self): + sequence = self.get_sequence("ISO7064_11_10") + self.assertTrue(mod_11_10.validate(sequence.next_by_id())) + + def test_validation(self): + sequence = self.get_sequence("ISO7064_11_10") + with self.assertRaises(ValidationError): + sequence.prefix = "A" + sequence.prefix = "" + + def test_mod37_2(self): + sequence = self.get_sequence("ISO7064_37_2") + sequence.prefix = "A" + self.assertTrue(mod_37_2.validate(sequence.next_by_id())) + + def test_mod37_36(self): + sequence = self.get_sequence("ISO7064_37_36") + self.assertTrue(mod_37_36.validate(sequence.next_by_id())) + + def test_mod97_10(self): + sequence = self.get_sequence("ISO7064_97_10") + self.assertTrue(mod_97_10.validate(sequence.next_by_id())) + + def test_no_mode_imported(self): + sequence = self.get_sequence(None) + with self.assertRaises(ValidationError): + sequence.get_check_digit("ABC") diff --git a/sequence_check_digit/views/sequence_views.xml b/sequence_check_digit/views/sequence_views.xml new file mode 100644 index 0000000000..a27bcf481d --- /dev/null +++ b/sequence_check_digit/views/sequence_views.xml @@ -0,0 +1,12 @@ + + + + ir.sequence + + + + + + + +