From 50063806134bc53b993722aef38f55cf0888d2de Mon Sep 17 00:00:00 2001 From: davidpalanca Date: Wed, 21 Aug 2024 12:42:02 +0200 Subject: [PATCH] [15.0][ADD] purchase_input_barcode_gs1 --- purchase_input_barcode_gs1/README.rst | 112 +++++ purchase_input_barcode_gs1/__init__.py | 1 + purchase_input_barcode_gs1/__manifest__.py | 20 + .../i18n/purchase_input_barcode_gs1.pot | 27 + purchase_input_barcode_gs1/models/__init__.py | 1 + .../models/product_barcode_line_mixin.py | 59 +++ .../readme/CONFIGURE.rst | 10 + .../readme/CONTRIBUTORS.rst | 15 + .../readme/DESCRIPTION.rst | 1 + .../static/description/index.html | 464 ++++++++++++++++++ purchase_input_barcode_gs1/tests/__init__.py | 1 + .../tests/test_purchase_input_barcode_gs1.py | 21 + .../odoo/addons/purchase_input_barcode_gs1 | 1 + setup/purchase_input_barcode_gs1/setup.py | 6 + 14 files changed, 739 insertions(+) create mode 100644 purchase_input_barcode_gs1/README.rst create mode 100644 purchase_input_barcode_gs1/__init__.py create mode 100644 purchase_input_barcode_gs1/__manifest__.py create mode 100644 purchase_input_barcode_gs1/i18n/purchase_input_barcode_gs1.pot create mode 100644 purchase_input_barcode_gs1/models/__init__.py create mode 100644 purchase_input_barcode_gs1/models/product_barcode_line_mixin.py create mode 100644 purchase_input_barcode_gs1/readme/CONFIGURE.rst create mode 100644 purchase_input_barcode_gs1/readme/CONTRIBUTORS.rst create mode 100644 purchase_input_barcode_gs1/readme/DESCRIPTION.rst create mode 100644 purchase_input_barcode_gs1/static/description/index.html create mode 100644 purchase_input_barcode_gs1/tests/__init__.py create mode 100644 purchase_input_barcode_gs1/tests/test_purchase_input_barcode_gs1.py create mode 120000 setup/purchase_input_barcode_gs1/odoo/addons/purchase_input_barcode_gs1 create mode 100644 setup/purchase_input_barcode_gs1/setup.py diff --git a/purchase_input_barcode_gs1/README.rst b/purchase_input_barcode_gs1/README.rst new file mode 100644 index 000000000000..10b27741c88c --- /dev/null +++ b/purchase_input_barcode_gs1/README.rst @@ -0,0 +1,112 @@ +========================== +Purchase Input Barcode GS1 +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:a2db01a7c2dc581865fc5ba7454d1077dc5e2f4670f88601f22f34b95ef147e0 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--barcode-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-barcode/tree/15.0/purchase_input_barcode_gs1 + :alt: OCA/stock-logistics-barcode +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-barcode-15-0/stock-logistics-barcode-15-0-purchase_input_barcode_gs1 + :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/stock-logistics-barcode&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module builds on purchase_input_barcode, making use of the full barcode information given by a barcode/datamatrix device. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +Optionnaly you may prevent to create unknown lot if you add this code in your custom code. + + +.. code-block:: python + + class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + def _create_unknown_lot(self, barcode): + return False + +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 +~~~~~~~ + +* Grupo Isonor + +Contributors +~~~~~~~~~~~~ + +* Akretion + + - David BEAL + +* PyTech SRL : + + - Alessandro Uffreduzzi + +* Ooops404 : + + - Francesco Foresti + +* Grupo Isonor + + - David Palanca + +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. + +.. |maintainer-neitherkx| image:: https://github.com/neitherkx.png?size=40px + :target: https://github.com/neitherkx + :alt: neitherkx + +Current `maintainer `__: + +|maintainer-neitherkx| + +This module is part of the `OCA/stock-logistics-barcode `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_input_barcode_gs1/__init__.py b/purchase_input_barcode_gs1/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/purchase_input_barcode_gs1/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_input_barcode_gs1/__manifest__.py b/purchase_input_barcode_gs1/__manifest__.py new file mode 100644 index 000000000000..5eea75da8522 --- /dev/null +++ b/purchase_input_barcode_gs1/__manifest__.py @@ -0,0 +1,20 @@ +# Copyright (C) 2022 Akretion +# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). + +{ + "name": "Purchase Input Barcode GS1", + "version": "15.0.1.0.0", + "category": "Tools", + "website": "https://github.com/OCA/stock-logistics-barcode", + "author": "Grupo Isonor, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "summary": "Add Purchase line with barcode using GS1 barcodes", + "maintainers": ["neitherkx"], + "depends": [ + "base_gs1_barcode", + "purchase_input_barcode", + ], + "data": [], + "demo": [], +} diff --git a/purchase_input_barcode_gs1/i18n/purchase_input_barcode_gs1.pot b/purchase_input_barcode_gs1/i18n/purchase_input_barcode_gs1.pot new file mode 100644 index 000000000000..adecfb0d7aa7 --- /dev/null +++ b/purchase_input_barcode_gs1/i18n/purchase_input_barcode_gs1.pot @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_input_barcode_gs1 +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 15.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-08-21 10:25+0000\n" +"PO-Revision-Date: 2024-08-21 10:25+0000\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: purchase_input_barcode_gs1 +#: code:addons/purchase_input_barcode_gs1/models/product_barcode_line_mixin.py:0 +#, python-format +msgid "Decoded barcode %s doesn't include a valid segment for GTIN" +msgstr "" + +#. module: purchase_input_barcode_gs1 +#: model:ir.model,name:purchase_input_barcode_gs1.model_product_barcode_line_mixin +msgid "Utilities for any model to deal with product_id field" +msgstr "" diff --git a/purchase_input_barcode_gs1/models/__init__.py b/purchase_input_barcode_gs1/models/__init__.py new file mode 100644 index 000000000000..8f1649defb85 --- /dev/null +++ b/purchase_input_barcode_gs1/models/__init__.py @@ -0,0 +1 @@ +from . import product_barcode_line_mixin diff --git a/purchase_input_barcode_gs1/models/product_barcode_line_mixin.py b/purchase_input_barcode_gs1/models/product_barcode_line_mixin.py new file mode 100644 index 000000000000..335755175ab4 --- /dev/null +++ b/purchase_input_barcode_gs1/models/product_barcode_line_mixin.py @@ -0,0 +1,59 @@ +# copyright 2022 David BEAL @ Akretion +# copyright 2024 David Palanca @ Grupo Isonor +from odoo import _, api, models +from odoo.exceptions import UserError + + +class ProductLineMixin(models.AbstractModel): + _inherit = "product.barcode.line.mixin" + + @api.model + def _decode_barcode(self, raw_barcode): + """ + res => + { + "01": "03400933816759", # GTIN + "17": "2014-05-31", # expiry date + "10": "B04059A", # lot number + "310": 0.06385, # weight + "15": "2014-05-01", # purchase date + } + """ + raw_barcode, barcode_dict = super()._decode_barcode(raw_barcode) + barcode_dict = self.env["gs1_barcode"].decode(raw_barcode) + if not barcode_dict.get("01"): + raise UserError( + _( + "Decoded barcode %s doesn't include a valid segment for GTIN" + ) % barcode_dict + ) + return barcode_dict["01"], barcode_dict + + def _populate_vals(self, product, barcode_dict): + vals = super()._populate_vals(product, barcode_dict) + if barcode_dict.get("10") and "lot_id" in self._fields: + lot = self.env["stock.production.lot"].search( + [("name", "=", barcode_dict["10"]), ("product_id", "=", product.id)] + ) + if not lot: + lot = self._create_unknown_lot(barcode_dict, product) + if lot: + # _create_unknown_lot may be overriden to not return lot + vals["lot_id"] = lot.id + return vals + + def _create_unknown_lot(self, barcode_dict, product): + """Inherit to implement your own scenario creation + i.e. + raise UserError(_("No lot found matching this barcode %s" % barcode)) + or + return False + """ + company_id = self.env.context.get("company_id") or self.env.company.id + lot_vals = { + "name": barcode_dict["10"], + "expiry_date": barcode_dict["17"], + "product_id": product.id, + "company_id": company_id, + } + return self.env["stock.production.lot"].create(lot_vals) diff --git a/purchase_input_barcode_gs1/readme/CONFIGURE.rst b/purchase_input_barcode_gs1/readme/CONFIGURE.rst new file mode 100644 index 000000000000..f5798c344bd5 --- /dev/null +++ b/purchase_input_barcode_gs1/readme/CONFIGURE.rst @@ -0,0 +1,10 @@ +Optionnaly you may prevent to create unknown lot if you add this code in your custom code. + + +.. code-block:: python + + class PurchaseOrderLine(models.Model): + _inherit = "purchase.order.line" + + def _create_unknown_lot(self, barcode): + return False diff --git a/purchase_input_barcode_gs1/readme/CONTRIBUTORS.rst b/purchase_input_barcode_gs1/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..5e42ffe2c8f1 --- /dev/null +++ b/purchase_input_barcode_gs1/readme/CONTRIBUTORS.rst @@ -0,0 +1,15 @@ +* Akretion + + - David BEAL + +* PyTech SRL : + + - Alessandro Uffreduzzi + +* Ooops404 : + + - Francesco Foresti + +* Grupo Isonor + + - David Palanca diff --git a/purchase_input_barcode_gs1/readme/DESCRIPTION.rst b/purchase_input_barcode_gs1/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..3ffdc870b267 --- /dev/null +++ b/purchase_input_barcode_gs1/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +This module builds on purchase_input_barcode, making use of the full barcode information given by a barcode/datamatrix device. diff --git a/purchase_input_barcode_gs1/static/description/index.html b/purchase_input_barcode_gs1/static/description/index.html new file mode 100644 index 000000000000..d83e69cc9e2a --- /dev/null +++ b/purchase_input_barcode_gs1/static/description/index.html @@ -0,0 +1,464 @@ + + + + + +Purchase Input Barcode GS1 + + + +
+

Purchase Input Barcode GS1

+ + +

Beta License: AGPL-3 OCA/stock-logistics-barcode Translate me on Weblate Try me on Runboat

+

This module builds on purchase_input_barcode, making use of the full barcode information given by a barcode/datamatrix device.

+

Table of contents

+ +
+

Configuration

+

Optionnaly you may prevent to create unknown lot if you add this code in your custom code.

+
+class PurchaseOrderLine(models.Model):
+    _inherit = "purchase.order.line"
+
+    def _create_unknown_lot(self, barcode):
+        return False
+
+
+
+

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

+
    +
  • Grupo Isonor
  • +
+
+
+

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.

+

Current maintainer:

+

neitherkx

+

This module is part of the OCA/stock-logistics-barcode project on GitHub.

+

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

+
+
+
+ + diff --git a/purchase_input_barcode_gs1/tests/__init__.py b/purchase_input_barcode_gs1/tests/__init__.py new file mode 100644 index 000000000000..d08cf854ef04 --- /dev/null +++ b/purchase_input_barcode_gs1/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_input_barcode_gs1 diff --git a/purchase_input_barcode_gs1/tests/test_purchase_input_barcode_gs1.py b/purchase_input_barcode_gs1/tests/test_purchase_input_barcode_gs1.py new file mode 100644 index 000000000000..22e32cb36523 --- /dev/null +++ b/purchase_input_barcode_gs1/tests/test_purchase_input_barcode_gs1.py @@ -0,0 +1,21 @@ +# © 2022 David BEAL @ Akretion +# © 2024 David Palanca @ Grupo Isonor +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests import TransactionCase + + +class Test(TransactionCase): + + def test_input_line(self): + self.env = self.env(context=dict(self.env.context, tracking_disable=True)) + barcode = "01034009338167591714050010B04059A\x1d310500638515140501" + product = self.env["product.product"].create( + { + "name": "barcode test", + "barcode": barcode[2:16], + } + ) + purchase = self.env.ref("purchase.purchase_order_3") + purchase.action_purchase_line_barcode(barcode) + self.assertIn(product, purchase.order_line.mapped("product_id")) diff --git a/setup/purchase_input_barcode_gs1/odoo/addons/purchase_input_barcode_gs1 b/setup/purchase_input_barcode_gs1/odoo/addons/purchase_input_barcode_gs1 new file mode 120000 index 000000000000..1376340bb7be --- /dev/null +++ b/setup/purchase_input_barcode_gs1/odoo/addons/purchase_input_barcode_gs1 @@ -0,0 +1 @@ +../../../../purchase_input_barcode_gs1 \ No newline at end of file diff --git a/setup/purchase_input_barcode_gs1/setup.py b/setup/purchase_input_barcode_gs1/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/purchase_input_barcode_gs1/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)