Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][MIG] sequence_check_digit: Migration to 15.0 #697

Merged
merged 20 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions sequence_check_digit/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
========================
Check Digit on Sequences
========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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/14.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-14-0/server-ux-14-0-sequence_check_digit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/250/14.0
:alt: Try me on Runbot

|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 <https://github.com/OCA/server-ux/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20sequence_check_digit%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Creu Blanca

Contributors
~~~~~~~~~~~~

* Enric Tobella <[email protected]>
* Sunanda Chhatbar <[email protected]>

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 <https://github.com/OCA/server-ux/tree/14.0/sequence_check_digit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions sequence_check_digit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from . import models
16 changes: 16 additions & 0 deletions sequence_check_digit/__manifest__.py
Original file line number Diff line number Diff line change
@@ -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": "15.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"],
}
91 changes: 91 additions & 0 deletions sequence_check_digit/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 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 <[email protected]>\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:45
#, 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
#: selection:ir.sequence,check_digit_formula:0
msgid "Damm"
msgstr "Damm"

#. module: sequence_check_digit
#: code:addons/sequence_check_digit/models/ir_sequence.py:39
#: code:addons/sequence_check_digit/models/ir_sequence.py:48
#, python-format
msgid "Format is not accepted"
msgstr "El formato no está aceptado"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "ISO 7064 Mod 11, 10"
msgstr "ISO 7064 Mod 11, 10"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "ISO 7064 Mod 11, 2"
msgstr "ISO 7064 Mod 11, 2"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "ISO 7064 Mod 37, 2"
msgstr "ISO 7064 Mod 37, 2"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "ISO 7064 Mod 37, 36"
msgstr "ISO 7064 Mod 37, 36"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "ISO 7064 Mod 97, 10"
msgstr "ISO 7064 Mod 97, 10"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "Luhn"
msgstr "Luhn"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "None"
msgstr "Ninguno"

#. module: sequence_check_digit
#: model:ir.model,name:sequence_check_digit.model_ir_sequence
#, fuzzy
#| msgid "ir.sequence"
msgid "Sequence"
msgstr "ir.sequence"

#. module: sequence_check_digit
#: selection:ir.sequence,check_digit_formula:0
msgid "Verhoeff"
msgstr "Verhoeff"

#~ msgid "Function not found"
#~ msgstr "Función no encontrada"
97 changes: 97 additions & 0 deletions sequence_check_digit/i18n/sequence_check_digit.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# 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: \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
#: 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 ""
3 changes: 3 additions & 0 deletions sequence_check_digit/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).

from . import ir_sequence
69 changes: 69 additions & 0 deletions sequence_check_digit/models/ir_sequence.py
Original file line number Diff line number Diff line change
@@ -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 (ImportError, IOError) as err:
_logger.debug(err)

Check warning on line 14 in sequence_check_digit/models/ir_sequence.py

View check run for this annotation

Codecov / codecov/patch

sequence_check_digit/models/ir_sequence.py#L13-L14

Added lines #L13 - L14 were not covered by tests


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:
raise ValidationError(_("Format is not accepted")) from None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add the from None?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the suggestion made by the pre-commit


def get_check_digit(self, code):
try:
return self.get_formula_map()[self.check_digit_formula](code)
except KeyError:
raise ValidationError(

Check warning on line 46 in sequence_check_digit/models/ir_sequence.py

View check run for this annotation

Codecov / codecov/patch

sequence_check_digit/models/ir_sequence.py#L46

Added line #L46 was not covered by tests
_("%s is not an implemented function") % self.check_digit_formula
) from None
except Exception:
raise ValidationError(_("Format is not accepted")) from None

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(IrSequence, self).get_next_char(number_next)
if not self.check_digit_formula:
return code
return "{}{}".format(code, self.get_check_digit(code))
2 changes: 2 additions & 0 deletions sequence_check_digit/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Enric Tobella <[email protected]>
* Sunanda Chhatbar <[email protected]>
6 changes: 6 additions & 0 deletions sequence_check_digit/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -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.
Loading
Loading