diff --git a/product_quantity_update_force_inventory/README.rst b/product_quantity_update_force_inventory/README.rst new file mode 100644 index 000000000000..a80198c89349 --- /dev/null +++ b/product_quantity_update_force_inventory/README.rst @@ -0,0 +1,80 @@ +======================================= +Product Quantity Update Force Inventory +======================================= + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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-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--warehouse-lightgray.png?logo=github + :target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/product_quantity_update_force_inventory + :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-product_quantity_update_force_inventory + :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| + +With this module, when a user goes to a product and presses the button 'Update Quantity' they will be directed to a new +Inventory Adjustment for this product, instead of driving the user to update the quantities in the +stock quants. + +By doing this users will be able to have full traceability on the inventory adjustment activities. + +Consider using this module together with the module 'stock_change_qty_reason' +(https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_change_qty_reason). + +**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 +~~~~~~~~~~~~ + +* Héctor Villarreal + +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/product_quantity_update_force_inventory/__init__.py b/product_quantity_update_force_inventory/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/product_quantity_update_force_inventory/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_quantity_update_force_inventory/__manifest__.py b/product_quantity_update_force_inventory/__manifest__.py new file mode 100644 index 000000000000..0de7a540278c --- /dev/null +++ b/product_quantity_update_force_inventory/__manifest__.py @@ -0,0 +1,15 @@ +# © 2016-2020 ForgeFlow S.L. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + "name": "Product Quantity Update Force Inventory", + "version": "13.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse", + "depends": ["stock"], + "license": "AGPL-3", + "data": ["views/product_views.xml"], + "installable": True, + "application": False, +} diff --git a/product_quantity_update_force_inventory/models/__init__.py b/product_quantity_update_force_inventory/models/__init__.py new file mode 100644 index 000000000000..b5839e0955a3 --- /dev/null +++ b/product_quantity_update_force_inventory/models/__init__.py @@ -0,0 +1,2 @@ +from . import product +from . import stock_quant diff --git a/product_quantity_update_force_inventory/models/product.py b/product_quantity_update_force_inventory/models/product.py new file mode 100644 index 000000000000..1f8b5b232ac1 --- /dev/null +++ b/product_quantity_update_force_inventory/models/product.py @@ -0,0 +1,47 @@ +# Copyright 2018-20 ForgeFlow + +from odoo import _, models + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def action_update_quantity_on_inventory_adjustment(self): + """ Create an Inventory Adjustment instead of edit directly on quants + """ + self.ensure_one() + view_form_id = self.env.ref("stock.view_inventory_form").id + action = self.env.ref("stock.action_inventory_form").read()[0] + action.update( + { + "views": [(view_form_id, "form")], + "view_mode": "form", + "context": { + "default_product_ids": [(6, 0, self.product_variant_ids.ids)], + "default_name": _("%s: Inventory Adjustment") % self.display_name, + }, + } + ) + return action + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def action_update_quantity_on_inventory_adjustment(self): + """ Create an Inventory Adjustment instead of edit directly on quants + """ + self.ensure_one() + view_form_id = self.env.ref("stock.view_inventory_form").id + action = self.env.ref("stock.action_inventory_form").read()[0] + action.update( + { + "views": [(view_form_id, "form")], + "view_mode": "form", + "context": { + "default_product_ids": [(6, 0, [self.id])], + "default_name": _("%s: Inventory Adjustment") % self.display_name, + }, + } + ) + return action diff --git a/product_quantity_update_force_inventory/models/stock_quant.py b/product_quantity_update_force_inventory/models/stock_quant.py new file mode 100644 index 000000000000..c035490080f4 --- /dev/null +++ b/product_quantity_update_force_inventory/models/stock_quant.py @@ -0,0 +1,23 @@ +# Copyright 2018-20 ForgeFlow + +from odoo import api, models + + +class StockQuant(models.Model): + _inherit = "stock.quant" + + @api.model + def _get_quants_action(self, domain=None, extend=False): + action = super()._get_quants_action(domain=domain, extend=extend) + action["view_id"] = self.env.ref("stock.view_stock_quant_tree").id + # Enables form view in readonly list + action.update( + { + "view_mode": "tree,form", + "views": [ + (action["view_id"], "list"), + (self.env.ref("stock.view_stock_quant_form").id, "form"), + ], + } + ) + return action diff --git a/product_quantity_update_force_inventory/readme/CONTRIBUTORS.rst b/product_quantity_update_force_inventory/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000000..70f45e48779d --- /dev/null +++ b/product_quantity_update_force_inventory/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Héctor Villarreal diff --git a/product_quantity_update_force_inventory/readme/DESCRIPTION.rst b/product_quantity_update_force_inventory/readme/DESCRIPTION.rst new file mode 100644 index 000000000000..e8478a2b5251 --- /dev/null +++ b/product_quantity_update_force_inventory/readme/DESCRIPTION.rst @@ -0,0 +1,8 @@ +With this module, when a user goes to a product and presses the button 'Update Quantity' they will be directed to a new +Inventory Adjustment for this product, instead of driving the user to update the quantities in the +stock quants. + +By doing this users will be able to have full traceability on the inventory adjustment activities. + +Consider using this module together with the module 'stock_change_qty_reason' +(https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_change_qty_reason). diff --git a/product_quantity_update_force_inventory/static/description/index.html b/product_quantity_update_force_inventory/static/description/index.html new file mode 100644 index 000000000000..1f99c246729e --- /dev/null +++ b/product_quantity_update_force_inventory/static/description/index.html @@ -0,0 +1,424 @@ + + + + + + +Product Quantity Update Force Inventory + + + +
+

Product Quantity Update Force Inventory

+ + +

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

+

With this module, when a user goes to a product and presses the button ‘Update Quantity’ they will be directed to a new +Inventory Adjustment for this product, instead of driving the user to update the quantities in the +stock quants.

+

By doing this users will be able to have full traceability on the inventory adjustment activities.

+

Consider using this module together with the module ‘stock_change_qty_reason’ +(https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_change_qty_reason).

+

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
  • +
+
+
+

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/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/product_quantity_update_force_inventory/tests/__init__.py b/product_quantity_update_force_inventory/tests/__init__.py new file mode 100644 index 000000000000..3908d49256ed --- /dev/null +++ b/product_quantity_update_force_inventory/tests/__init__.py @@ -0,0 +1 @@ +from . import test_stock_quant_editable_view_block diff --git a/product_quantity_update_force_inventory/tests/test_stock_quant_editable_view_block.py b/product_quantity_update_force_inventory/tests/test_stock_quant_editable_view_block.py new file mode 100644 index 000000000000..8b319b285f01 --- /dev/null +++ b/product_quantity_update_force_inventory/tests/test_stock_quant_editable_view_block.py @@ -0,0 +1,71 @@ +# Copyright 2020 Forgeflow, S.L. +# (http://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import TransactionCase + + +class TestStockQuantEditableViewBlock(TransactionCase): + def setUp(self): + super(TestStockQuantEditableViewBlock, self).setUp() + self.inventory_model = self.env["stock.inventory"] + self.res_users_model = self.env["res.users"] + self.company = self.env.ref("base.main_company") + self.grp_stock_manager = self.env.ref("stock.group_stock_manager") + + self.user = self.res_users_model.create( + { + "name": "Test Account User", + "login": "user_1", + "email": "example@yourcompany.com", + "password": "password", + "company_id": self.company.id, + "company_ids": [(4, self.company.id)], + "groups_id": [(6, 0, [self.grp_stock_manager.id])], + } + ) + self.product_product = self.env.ref("product.product_product_4") + self.product_template = self.product_product.product_tmpl_id + + self.stock_quant_editable_tree_view = self.env.ref( + "stock.view_stock_quant_tree_editable" + ) + + def test_stock_quant_editable_view_block(self): + """Check if clicking On hand Smart Button on Product Card + does not send user to editable stock quant view""" + action_pp = self.product_product.with_user(self.user).action_open_quants() + self.assertNotEqual( + self.stock_quant_editable_tree_view.id, + action_pp["view_id"], + "Editable Stock Quant View is still prompting on Product Product", + ) + + action_pt = self.product_template.with_user(self.user).action_open_quants() + self.assertNotEqual( + self.stock_quant_editable_tree_view.id, + action_pt["view_id"], + "Editable Stock Quant View is still prompting on Product Template", + ) + + def test_update_quantity_triggers_inventory_adjustment(self): + action_pp = self.product_product.with_user( + self.user + ).action_update_quantity_on_inventory_adjustment() + self.assertIn( + self.product_product.display_name, action_pp["context"]["default_name"] + ) + self.assertEquals( + action_pp["context"]["default_product_ids"], + [(6, 0, self.product_product.ids)], + ) + action_pt = self.product_template.with_user( + self.user + ).action_update_quantity_on_inventory_adjustment() + self.assertIn( + self.product_template.display_name, action_pt["context"]["default_name"] + ) + self.assertEquals( + action_pt["context"]["default_product_ids"], + [(6, 0, self.product_template.product_variant_ids.ids)], + ) diff --git a/product_quantity_update_force_inventory/views/product_views.xml b/product_quantity_update_force_inventory/views/product_views.xml new file mode 100644 index 000000000000..86432e381625 --- /dev/null +++ b/product_quantity_update_force_inventory/views/product_views.xml @@ -0,0 +1,46 @@ + + + + product.template_procurement + product.template + + + + + + + product.product.procurement + product.product + + + + + + + + product.product.view.form.easy.inherit.stock + product.product + + + + + + diff --git a/setup/product_quantity_update_force_inventory/odoo/addons/product_quantity_update_force_inventory b/setup/product_quantity_update_force_inventory/odoo/addons/product_quantity_update_force_inventory new file mode 120000 index 000000000000..3648e7386461 --- /dev/null +++ b/setup/product_quantity_update_force_inventory/odoo/addons/product_quantity_update_force_inventory @@ -0,0 +1 @@ +../../../../product_quantity_update_force_inventory \ No newline at end of file diff --git a/setup/product_quantity_update_force_inventory/setup.py b/setup/product_quantity_update_force_inventory/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/product_quantity_update_force_inventory/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)