diff --git a/scrap_location_filter/README.rst b/scrap_location_filter/README.rst new file mode 100644 index 000000000..2166f207b --- /dev/null +++ b/scrap_location_filter/README.rst @@ -0,0 +1,98 @@ +===================== +Scrap Location Filter +===================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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/14.0/scrap_location_filter + :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-14-0/stock-logistics-warehouse-14-0-scrap_location_filter + :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/14.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +It will filter the location based on the quantity of that product on hand when scrap is created for a certain product. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- Go to Inventory > Operations > Scrap +- Create a scrap order and select Location. +- It will only show locations that have stock on hand. + +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 +~~~~~~~ + +* Open Source Integrators +* + +Contributors +~~~~~~~~~~~~ + +* Freni Patel +* Open Source Integrators +* Serpent Consulting Services Pvt. Ltd. + +Other credits +~~~~~~~~~~~~~ + +The development of this module has been financially supported by: + +* Open Source Integrators + +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-opensourceintegrators| image:: https://github.com/opensourceintegrators.png?size=40px + :target: https://github.com/opensourceintegrators + :alt: opensourceintegrators + +Current `maintainer `__: + +|maintainer-opensourceintegrators| + +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/scrap_location_filter/__init__.py b/scrap_location_filter/__init__.py new file mode 100644 index 000000000..6a0c77273 --- /dev/null +++ b/scrap_location_filter/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/scrap_location_filter/__manifest__.py b/scrap_location_filter/__manifest__.py new file mode 100644 index 000000000..5776f8134 --- /dev/null +++ b/scrap_location_filter/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Scrap Location Filter", + "version": "14.0.1.0.0", + "category": "Warehouse Management", + "license": "AGPL-3", + "depends": ["stock"], + "summary": "Filters scrap location", + "author": "Open Source Integrators, , Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "data": ["views/stock_views.xml"], + "maintainers": ["opensourceintegrators"], + "installable": True, + "application": False, +} diff --git a/scrap_location_filter/models/__init__.py b/scrap_location_filter/models/__init__.py new file mode 100644 index 000000000..bc2a72fdc --- /dev/null +++ b/scrap_location_filter/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright (C) 2021 Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import stock_location +from . import stock_scrap diff --git a/scrap_location_filter/models/stock_location.py b/scrap_location_filter/models/stock_location.py new file mode 100644 index 000000000..3846e688d --- /dev/null +++ b/scrap_location_filter/models/stock_location.py @@ -0,0 +1,38 @@ +# Copyright (C) 2021 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class StockLocation(models.Model): + _inherit = "stock.location" + + @api.model + def _search( + self, + args, + offset=0, + limit=None, + order=None, + count=False, + access_rights_uid=None, + ): + context = self.env.context + if context.get("product_id") or context.get("lot_id"): + quants = self.env["stock.quant"].search( + [ + ("product_id", "=", context.get("product_id")), + ("lot_id", "=", context.get("lot_id")), + ] + ) + locations = quants.mapped("location_id") + if not locations: + company_id = context.get("default_company_id") or self.env.company.id + warehouse = self.env["stock.warehouse"].search( + [("company_id", "=", company_id)], limit=1 + ) + locations = warehouse.lot_stock_id + args += [("id", "in", locations.ids)] + return super(StockLocation, self)._search( + args, offset, limit, order, count=count, access_rights_uid=access_rights_uid + ) diff --git a/scrap_location_filter/models/stock_scrap.py b/scrap_location_filter/models/stock_scrap.py new file mode 100644 index 000000000..c2aa4e423 --- /dev/null +++ b/scrap_location_filter/models/stock_scrap.py @@ -0,0 +1,18 @@ +# Copyright (C) 2021 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class StockScrap(models.Model): + _inherit = "stock.scrap" + + @api.onchange("product_id") + def _onchange_product_id(self): + self.location_id = False + self.lot_id = False + return super()._onchange_product_id() + + @api.onchange("lot_id") + def _onchange_lot_id(self): + self.location_id = False diff --git a/scrap_location_filter/readme/CONTRIBUTORS.rst b/scrap_location_filter/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..d9a9331fe --- /dev/null +++ b/scrap_location_filter/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* Freni Patel +* Open Source Integrators +* Serpent Consulting Services Pvt. Ltd. diff --git a/scrap_location_filter/readme/CREDITS.rst b/scrap_location_filter/readme/CREDITS.rst new file mode 100644 index 000000000..8209266d9 --- /dev/null +++ b/scrap_location_filter/readme/CREDITS.rst @@ -0,0 +1,3 @@ +The development of this module has been financially supported by: + +* Open Source Integrators diff --git a/scrap_location_filter/readme/DESCRIPTION.rst b/scrap_location_filter/readme/DESCRIPTION.rst new file mode 100644 index 000000000..7fa787420 --- /dev/null +++ b/scrap_location_filter/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +It will filter the location based on the quantity of that product on hand when scrap is created for a certain product. diff --git a/scrap_location_filter/readme/USAGE.rst b/scrap_location_filter/readme/USAGE.rst new file mode 100644 index 000000000..213ced4b9 --- /dev/null +++ b/scrap_location_filter/readme/USAGE.rst @@ -0,0 +1,3 @@ +- Go to Inventory > Operations > Scrap +- Create a scrap order and select Location. +- It will only show locations that have stock on hand. diff --git a/scrap_location_filter/static/description/icon.png b/scrap_location_filter/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/scrap_location_filter/static/description/icon.png differ diff --git a/scrap_location_filter/static/description/index.html b/scrap_location_filter/static/description/index.html new file mode 100644 index 000000000..95684dc02 --- /dev/null +++ b/scrap_location_filter/static/description/index.html @@ -0,0 +1,441 @@ + + + + + + +Scrap Location Filter + + + +
+

Scrap Location Filter

+ + +

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

+

It will filter the location based on the quantity of that product on hand when scrap is created for a certain product.

+

Table of contents

+ +
+

Usage

+
    +
  • Go to Inventory > Operations > Scrap
  • +
  • Create a scrap order and select Location.
  • +
  • It will only show locations that have stock on hand.
  • +
+
+
+

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

+
    +
  • Open Source Integrators
  • +
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The development of this module has been financially supported by:

+
    +
  • Open Source Integrators
  • +
+
+
+

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:

+

opensourceintegrators

+

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/scrap_location_filter/tests/__init__.py b/scrap_location_filter/tests/__init__.py new file mode 100644 index 000000000..7bed3e109 --- /dev/null +++ b/scrap_location_filter/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright (C) 2021 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_scrap_location_filter diff --git a/scrap_location_filter/tests/test_scrap_location_filter.py b/scrap_location_filter/tests/test_scrap_location_filter.py new file mode 100644 index 000000000..83aa32b90 --- /dev/null +++ b/scrap_location_filter/tests/test_scrap_location_filter.py @@ -0,0 +1,60 @@ +# Copyright (C) 2021 - TODAY, Open Source Integrators +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import SavepointCase + + +class StockScrapLocation(SavepointCase): + @classmethod + def setUpClass(cls): + super(StockScrapLocation, cls).setUpClass() + + cls.stock_location = cls.env.ref("stock.stock_location_stock") + cls.ProductObj = cls.env["product.product"] + cls.LotObj = cls.env["stock.production.lot"] + cls.productA = cls.ProductObj.create({"name": "Product A", "type": "product"}) + cls.productB = cls.ProductObj.create({"name": "Product B", "type": "product"}) + cls.lot_productA = cls.LotObj.create( + { + "name": "A Lot 1", + "product_id": cls.productA.id, + "company_id": cls.env.company.id, + } + ) + + def test_scrap_location(self): + self.env["stock.quant"].create( + { + "product_id": self.productA.id, + "lot_id": self.lot_productA.id, + "location_id": self.stock_location.id, + "inventory_quantity": 100, + } + ) + self.env["stock.location"].with_context( + {"product_id": self.productA.id, "lot_id": self.lot_productA.id} + ).search([]) + + def test_scrap_location2(self): + self.env["stock.quant"].create( + { + "product_id": self.productB.id, + "lot_id": self.lot_productA.id, + "location_id": self.stock_location.id, + "inventory_quantity": 100, + } + ) + self.env["stock.location"].with_context( + {"product_id": self.productA.id, "lot_id": self.lot_productA.id} + ).search([]) + scrap = self.env["stock.scrap"].create( + { + "product_id": self.productA.id, + "product_uom_id": self.productA.uom_id.id, + "scrap_qty": 5, + # "picking_id": picking.id, + # "reason_code_id": self.reason_code.id, + } + ) + scrap._onchange_product_id() + scrap._onchange_lot_id() diff --git a/scrap_location_filter/views/stock_views.xml b/scrap_location_filter/views/stock_views.xml new file mode 100644 index 000000000..fb964493e --- /dev/null +++ b/scrap_location_filter/views/stock_views.xml @@ -0,0 +1,30 @@ + + + + + stock.scrap.form.inherit + stock.scrap + + + + {'product_id': product_id, 'lot_id': lot_id} + + + + + stock.scrap.form.inherit.wiz + stock.scrap + + + + {'product_id': product_id, 'lot_id': lot_id} + + + + + diff --git a/setup/scrap_location_filter/odoo/addons/scrap_location_filter b/setup/scrap_location_filter/odoo/addons/scrap_location_filter new file mode 120000 index 000000000..e36f71599 --- /dev/null +++ b/setup/scrap_location_filter/odoo/addons/scrap_location_filter @@ -0,0 +1 @@ +../../../../scrap_location_filter \ No newline at end of file diff --git a/setup/scrap_location_filter/setup.py b/setup/scrap_location_filter/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/scrap_location_filter/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)