diff --git a/setup/stock_move_packaging_qty/odoo/addons/stock_move_packaging_qty b/setup/stock_move_packaging_qty/odoo/addons/stock_move_packaging_qty new file mode 120000 index 000000000..36962e5e5 --- /dev/null +++ b/setup/stock_move_packaging_qty/odoo/addons/stock_move_packaging_qty @@ -0,0 +1 @@ +../../../../stock_move_packaging_qty \ No newline at end of file diff --git a/setup/stock_move_packaging_qty/setup.py b/setup/stock_move_packaging_qty/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_move_packaging_qty/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_move_packaging_qty/README.rst b/stock_move_packaging_qty/README.rst new file mode 100644 index 000000000..e4db41a6d --- /dev/null +++ b/stock_move_packaging_qty/README.rst @@ -0,0 +1,74 @@ +=================== +Stock Packaging Qty +=================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fstock--logistics--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_move_packaging_qty + :alt: OCA/stock-logistics-warehouse +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_move_packaging_qty + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/153/13.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Add packaging fields in the stock moves + +**Table of contents** + +.. contents:: + :local: + +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 smashing it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* Mateu Griful +* Lois Rilo + +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/stock-logistics-warehouse `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/stock_move_packaging_qty/__init__.py b/stock_move_packaging_qty/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_move_packaging_qty/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_move_packaging_qty/__manifest__.py b/stock_move_packaging_qty/__manifest__.py new file mode 100644 index 000000000..723ef8051 --- /dev/null +++ b/stock_move_packaging_qty/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +{ + "name": "Stock Packaging Qty", + "summary": "Add packaging fields in the stock moves", + "version": "16.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse", + "depends": ["stock"], + "data": ["views/stock_picking_form_view.xml", "views/stock_move_tree_view.xml"], + "license": "LGPL-3", + "installable": True, + "maintainers": ["yajo"], +} diff --git a/stock_move_packaging_qty/i18n/stock_move_packaging_qty.pot b/stock_move_packaging_qty/i18n/stock_move_packaging_qty.pot new file mode 100644 index 000000000..467e817b6 --- /dev/null +++ b/stock_move_packaging_qty/i18n/stock_move_packaging_qty.pot @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * stock_move_packaging_qty +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.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: stock_move_packaging_qty +#: model:ir.model.fields,field_description:stock_move_packaging_qty.field_stock_move__product_packaging +msgid "Package" +msgstr "" + +#. module: stock_move_packaging_qty +#: model:ir.model.fields,field_description:stock_move_packaging_qty.field_stock_move__product_packaging_qty +msgid "Package quantity" +msgstr "" + +#. module: stock_move_packaging_qty +#: code:addons/stock_move_packaging_qty/models/stock_move.py:0 +#, python-format +msgid "Please select a packaging with a quantity bigger than 0" +msgstr "" + +#. module: stock_move_packaging_qty +#: model:ir.model,name:stock_move_packaging_qty.model_stock_move +msgid "Stock Move" +msgstr "" + +#. module: stock_move_packaging_qty +#: code:addons/stock_move_packaging_qty/models/stock_move.py:0 +#, python-format +msgid "This product is packaged by %.2f %s. You should use %.2f %s." +msgstr "" + +#. module: stock_move_packaging_qty +#: code:addons/stock_move_packaging_qty/models/stock_move.py:0 +#, python-format +msgid "Warning" +msgstr "" + +#. module: stock_move_packaging_qty +#: code:addons/stock_move_packaging_qty/models/stock_move.py:0 +#, python-format +msgid "You must define a package before setting a quantity of said package." +msgstr "" diff --git a/stock_move_packaging_qty/migrations/15.0.0/pre-migrate.py b/stock_move_packaging_qty/migrations/15.0.0/pre-migrate.py new file mode 100644 index 000000000..dda7c83db --- /dev/null +++ b/stock_move_packaging_qty/migrations/15.0.0/pre-migrate.py @@ -0,0 +1,20 @@ +# Copyright 2023 Moduon Team S.L. +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). +from openupgradelib import openupgrade + + +def migrate(cr, version): + """Use upstream column. + + In https://github.com/odoo/odoo/pull/68654, upstream added product_packaging_id. + That feature is removed from this module and migrated there. + """ + if openupgrade.column_exists(cr, "stock_move", "product_packaging"): + openupgrade.rename_columns( + cr, + { + "stock_move": [ + ("product_packaging", "product_packaging_id"), + ], + }, + ) diff --git a/stock_move_packaging_qty/models/__init__.py b/stock_move_packaging_qty/models/__init__.py new file mode 100644 index 000000000..6bda2d242 --- /dev/null +++ b/stock_move_packaging_qty/models/__init__.py @@ -0,0 +1 @@ +from . import stock_move diff --git a/stock_move_packaging_qty/models/stock_move.py b/stock_move_packaging_qty/models/stock_move.py new file mode 100644 index 000000000..e2490b2e9 --- /dev/null +++ b/stock_move_packaging_qty/models/stock_move.py @@ -0,0 +1,64 @@ +# Copyright 2020 Camptocamp SA +# Copyright 2021 ForgeFlow, S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl) +from odoo import api, fields, models + + +class StockPicking(models.Model): + _inherit = "stock.move" + + product_packaging_qty = fields.Float( + string="Package quantity", + compute="_compute_product_packaging_qty", + inverse="_inverse_product_packaging_qty", + help="Amount of packages demanded.", + ) + + @api.depends( + "product_qty", "product_uom", "product_packaging_id", "product_packaging_id.qty" + ) + def _compute_product_packaging_qty(self): + for move in self: + if ( + not move.product_packaging_id + or move.product_qty == 0 + or move.product_packaging_id.qty == 0 + ): + move.product_packaging_qty = 0 + continue + # Consider uom + move.product_packaging_qty = ( + move.product_uom_qty / move._get_single_package_uom_qty() + ) + + @api.onchange("product_packaging_qty") + def _inverse_product_packaging_qty(self): + """Store the quantity in the product's UoM. + + This inverse is also an onchange because otherwise changes are not + reflected live. + """ + for move in self: + if move.product_packaging_id and move.product_packaging_qty: + uom_factor = move._get_single_package_uom_qty() + move.product_uom_qty = move.product_packaging_qty * uom_factor + + @api.onchange("product_packaging_id") + def _onchange_product_packaging(self): + """Add a default qty if the packaging has an invalid value.""" + if not self.product_packaging_id: + self.product_packaging_qty = 0 + return + self.product_uom_qty = ( + self.product_packaging_id._check_qty(self.product_uom_qty, self.product_uom) + or self._get_single_package_uom_qty() + ) + + def _get_single_package_uom_qty(self): + """Return the quantity of a single package in the move's UoM.""" + self.ensure_one() + if not self.product_packaging_id: + return 0 + return self.product_packaging_id.product_uom_id._compute_quantity( + self.product_packaging_id.qty, self.product_uom + ) diff --git a/stock_move_packaging_qty/readme/CONTRIBUTORS.rst b/stock_move_packaging_qty/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..430ace9f1 --- /dev/null +++ b/stock_move_packaging_qty/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Mateu Griful +* Lois Rilo +* Jairo Llopis (`Moduon `__) diff --git a/stock_move_packaging_qty/readme/DESCRIPTION.rst b/stock_move_packaging_qty/readme/DESCRIPTION.rst new file mode 100644 index 000000000..6de170dfd --- /dev/null +++ b/stock_move_packaging_qty/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Add packaging fields in the stock moves diff --git a/stock_move_packaging_qty/static/description/icon.png b/stock_move_packaging_qty/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_move_packaging_qty/static/description/icon.png differ diff --git a/stock_move_packaging_qty/static/description/index.html b/stock_move_packaging_qty/static/description/index.html new file mode 100644 index 000000000..17eb89a1a --- /dev/null +++ b/stock_move_packaging_qty/static/description/index.html @@ -0,0 +1,420 @@ + + + + + + +Stock Packaging Qty + + + +
+

Stock Packaging Qty

+ + +

Beta License: LGPL-3 OCA/stock-logistics-warehouse Translate me on Weblate Try me on Runbot

+

Add packaging fields in the stock moves

+

Table of contents

+ +
+

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 smashing it by providing a detailed and welcomed +feedback.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ForgeFlow
  • +
+
+ +
+

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/stock-logistics-warehouse project on GitHub.

+

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

+
+
+
+ + diff --git a/stock_move_packaging_qty/tests/__init__.py b/stock_move_packaging_qty/tests/__init__.py new file mode 100644 index 000000000..7872eae71 --- /dev/null +++ b/stock_move_packaging_qty/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_move_packaging_qty diff --git a/stock_move_packaging_qty/tests/test_stock_move_packaging_qty.py b/stock_move_packaging_qty/tests/test_stock_move_packaging_qty.py new file mode 100644 index 000000000..ca6ccff1e --- /dev/null +++ b/stock_move_packaging_qty/tests/test_stock_move_packaging_qty.py @@ -0,0 +1,61 @@ +# Copyright 2021 ForgeFlow S.L. (https://www.forgeflow.com) +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). + +from odoo.tests import Form, TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestStockMovePackagingQty(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.env.user.groups_id |= cls.env.ref("product.group_stock_packaging") + cls.partner = cls.env.ref("base.res_partner_12") + cls.product = cls.env.ref("product.product_product_9") + cls.packaging = cls.env["product.packaging"].create( + {"name": "Test packaging", "product_id": cls.product.id, "qty": 5.0} + ) + cls.wh = cls.env["stock.warehouse"].create( + {"name": "Base Warehouse", "code": "TESTWH"} + ) + cls.categ_unit = cls.env.ref("uom.product_uom_categ_unit") + cls.uom_unit = cls.env["uom.uom"].search( + [("category_id", "=", cls.categ_unit.id), ("uom_type", "=", "reference")], + limit=1, + ) + cls.customer_location = cls.env.ref("stock.stock_location_customers") + cls.supplier_location = cls.env.ref("stock.stock_location_suppliers") + + def test_product_packaging_qty(self): + move = self.env["stock.move"].create( + { + "name": "Move", + "location_id": self.supplier_location.id, + "location_dest_id": self.wh.lot_stock_id.id, + "partner_id": self.partner.id, + "product_id": self.product.id, + "product_uom": self.product.uom_id.id, + "product_uom_qty": 3.0, + "price_unit": 10.0, + } + ) + move.write({"product_packaging_id": self.packaging.id}) + move._onchange_product_packaging() + self.assertEqual(move.product_uom_qty, 5.0) + self.assertEqual(move.product_packaging_qty, 1.0) + move.write({"product_packaging_qty": 3.0}) + self.assertEqual(move.product_uom_qty, 15.0) + + def test_product_uom_qty_change(self): + picking_f = Form(self.env["stock.picking"]) + picking_f.partner_id = self.partner + picking_f.picking_type_id = self.env.ref("stock.picking_type_out") + with picking_f.move_ids_without_package.new() as move_f: + move_f.product_id = self.product + self.assertEqual(move_f.product_uom_qty, 1) + self.assertEqual(move_f.product_packaging_qty, 0) + self.assertFalse(move_f.product_packaging_id) + move_f.product_packaging_id = self.packaging + self.assertEqual(move_f.product_uom_qty, 5) + self.assertEqual(move_f.product_packaging_qty, 1) diff --git a/stock_move_packaging_qty/views/stock_move_tree_view.xml b/stock_move_packaging_qty/views/stock_move_tree_view.xml new file mode 100644 index 000000000..fdee6314e --- /dev/null +++ b/stock_move_packaging_qty/views/stock_move_tree_view.xml @@ -0,0 +1,24 @@ + + + + view.move.extra.tree + stock.move + + + + + + + + + diff --git a/stock_move_packaging_qty/views/stock_picking_form_view.xml b/stock_move_packaging_qty/views/stock_picking_form_view.xml new file mode 100644 index 000000000..d6fd0b4c3 --- /dev/null +++ b/stock_move_packaging_qty/views/stock_picking_form_view.xml @@ -0,0 +1,29 @@ + + + + stock.picking.form + stock.picking + + + + + + + +