diff --git a/setup/stock_scrap_location_default/odoo/addons/stock_scrap_location_default b/setup/stock_scrap_location_default/odoo/addons/stock_scrap_location_default new file mode 120000 index 000000000..bda1c99a9 --- /dev/null +++ b/setup/stock_scrap_location_default/odoo/addons/stock_scrap_location_default @@ -0,0 +1 @@ +../../../../stock_scrap_location_default \ No newline at end of file diff --git a/setup/stock_scrap_location_default/setup.py b/setup/stock_scrap_location_default/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/stock_scrap_location_default/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/stock_scrap_location_default/README.rst b/stock_scrap_location_default/README.rst new file mode 100644 index 000000000..de986e8e3 --- /dev/null +++ b/stock_scrap_location_default/README.rst @@ -0,0 +1,99 @@ +============================ +Stock Scrap Location Default +============================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:1e13718cfd46ccd36f0efd4ae96f2d52be2df280f22ddef25dbb1e7655cec243 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/16.0/stock_scrap_location_default + :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-16-0/stock-logistics-warehouse-16-0-stock_scrap_location_default + :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-warehouse&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to define a default scrap location when creating a scrap. + +By default, Odoo searches for the first location that is a scrap one. This +changes from the standard behavior. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +#. Go to Inventory > Settings > Warehouse +#. Check the box 'Storage Locations' if not yet activated. +#. Define a scrap location that will be used as default when doing scrap + +Known issues / Roadmap +====================== + +This module should be enhanced in order to support multi-company/mutli-warehouse. + +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 +~~~~~~~ + +* ACSONE SA/NV + +Contributors +~~~~~~~~~~~~ + +* Denis Roussel + +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-rousseldenis| image:: https://github.com/rousseldenis.png?size=40px + :target: https://github.com/rousseldenis + :alt: rousseldenis + +Current `maintainer `__: + +|maintainer-rousseldenis| + +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_scrap_location_default/__init__.py b/stock_scrap_location_default/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/stock_scrap_location_default/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/stock_scrap_location_default/__manifest__.py b/stock_scrap_location_default/__manifest__.py new file mode 100644 index 000000000..4c4dc37cd --- /dev/null +++ b/stock_scrap_location_default/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Stock Scrap Location Default", + "summary": """ + Allows to define a setting at company level that reference a default scrap location""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "maintainers": ["rousseldenis"], + "website": "https://github.com/OCA/stock-logistics-warehouse", + "depends": ["stock"], + "data": [ + "views/res_config_settings.xml", + ], +} diff --git a/stock_scrap_location_default/models/__init__.py b/stock_scrap_location_default/models/__init__.py new file mode 100644 index 000000000..572e9ded3 --- /dev/null +++ b/stock_scrap_location_default/models/__init__.py @@ -0,0 +1 @@ +from . import res_company, res_config_settings, stock_scrap diff --git a/stock_scrap_location_default/models/res_company.py b/stock_scrap_location_default/models/res_company.py new file mode 100644 index 000000000..65b6c8ad4 --- /dev/null +++ b/stock_scrap_location_default/models/res_company.py @@ -0,0 +1,15 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + + _inherit = "res.company" + + scrap_default_location_id = fields.Many2one( + comodel_name="stock.location", + domain="[('scrap_location', '=', True), ('company_id', 'in', [company_id, False])]", + check_company=True, + ) diff --git a/stock_scrap_location_default/models/res_config_settings.py b/stock_scrap_location_default/models/res_config_settings.py new file mode 100644 index 000000000..c0c657f5a --- /dev/null +++ b/stock_scrap_location_default/models/res_config_settings.py @@ -0,0 +1,15 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + + _inherit = "res.config.settings" + + scrap_default_location_id = fields.Many2one( + comodel_name="stock.location", + related="company_id.scrap_default_location_id", + readonly=False, + ) diff --git a/stock_scrap_location_default/models/stock_scrap.py b/stock_scrap_location_default/models/stock_scrap.py new file mode 100644 index 000000000..86c5d9aa9 --- /dev/null +++ b/stock_scrap_location_default/models/stock_scrap.py @@ -0,0 +1,22 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + +from odoo.addons.stock.models.stock_location import Location as StockLocation + + +class StockScrap(models.Model): + + _inherit = "stock.scrap" + + def _get_default_scrap_location_id(self) -> StockLocation: + """ + Returns the default scrap location defined on company level + """ + if self.env.company.scrap_default_location_id: + return self.env.company.scrap_default_location_id + return super()._get_default_scrap_location_id() + + # This is necessary as Odoo still uses (for v<=16) static method for default + scrap_location_id = fields.Many2one(default=_get_default_scrap_location_id) diff --git a/stock_scrap_location_default/readme/CONFIGURE.rst b/stock_scrap_location_default/readme/CONFIGURE.rst new file mode 100644 index 000000000..11bfd0251 --- /dev/null +++ b/stock_scrap_location_default/readme/CONFIGURE.rst @@ -0,0 +1,3 @@ +#. Go to Inventory > Settings > Warehouse +#. Check the box 'Storage Locations' if not yet activated. +#. Define a scrap location that will be used as default when doing scrap diff --git a/stock_scrap_location_default/readme/CONTRIBUTORS.rst b/stock_scrap_location_default/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..9179ee4b8 --- /dev/null +++ b/stock_scrap_location_default/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Denis Roussel diff --git a/stock_scrap_location_default/readme/DESCRIPTION.rst b/stock_scrap_location_default/readme/DESCRIPTION.rst new file mode 100644 index 000000000..d5d22cf67 --- /dev/null +++ b/stock_scrap_location_default/readme/DESCRIPTION.rst @@ -0,0 +1,4 @@ +This module allows to define a default scrap location when creating a scrap. + +By default, Odoo searches for the first location that is a scrap one. This +changes from the standard behavior. diff --git a/stock_scrap_location_default/readme/ROADMAP.rst b/stock_scrap_location_default/readme/ROADMAP.rst new file mode 100644 index 000000000..8b5df9e8d --- /dev/null +++ b/stock_scrap_location_default/readme/ROADMAP.rst @@ -0,0 +1 @@ +This module should be enhanced in order to support multi-company/mutli-warehouse. diff --git a/stock_scrap_location_default/static/description/icon.png b/stock_scrap_location_default/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/stock_scrap_location_default/static/description/icon.png differ diff --git a/stock_scrap_location_default/static/description/index.html b/stock_scrap_location_default/static/description/index.html new file mode 100644 index 000000000..955ef0715 --- /dev/null +++ b/stock_scrap_location_default/static/description/index.html @@ -0,0 +1,438 @@ + + + + + +Stock Scrap Location Default + + + +
+

Stock Scrap Location Default

+ + +

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

+

This module allows to define a default scrap location when creating a scrap.

+

By default, Odoo searches for the first location that is a scrap one. This +changes from the standard behavior.

+

Table of contents

+ +
+

Configuration

+
    +
  1. Go to Inventory > Settings > Warehouse
  2. +
  3. Check the box ‘Storage Locations’ if not yet activated.
  4. +
  5. Define a scrap location that will be used as default when doing scrap
  6. +
+
+
+

Known issues / Roadmap

+

This module should be enhanced in order to support multi-company/mutli-warehouse.

+
+
+

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

+
    +
  • ACSONE SA/NV
  • +
+
+
+

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:

+

rousseldenis

+

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_scrap_location_default/tests/__init__.py b/stock_scrap_location_default/tests/__init__.py new file mode 100644 index 000000000..cf5ea7913 --- /dev/null +++ b/stock_scrap_location_default/tests/__init__.py @@ -0,0 +1 @@ +from . import test_scrap_location_default diff --git a/stock_scrap_location_default/tests/test_scrap_location_default.py b/stock_scrap_location_default/tests/test_scrap_location_default.py new file mode 100644 index 000000000..fa865fb82 --- /dev/null +++ b/stock_scrap_location_default/tests/test_scrap_location_default.py @@ -0,0 +1,84 @@ +# Copyright 2023 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import Form, TransactionCase + + +class TestScrapLocationDefault(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + parent_location = cls.env.ref( + "stock.stock_location_locations_virtual", raise_if_not_found=False + ) + cls.product = cls.env["product.product"].create({"name": "Test"}) + cls.company = cls.env.ref("base.main_company") + cls.company_2 = cls.env["res.company"].create( + { + "name": "Company 2 (test scrap)", + } + ) + # As creating new company creates also a scrap location + cls.scrap_location = cls.env["stock.location"].search( + [("company_id", "=", cls.company_2.id), ("scrap_location", "=", True)], + limit=1, + ) + cls.scrap_location_2 = cls.env["stock.location"].create( + { + "name": "Test Scrap 2", + "location_id": parent_location.id, + "company_id": cls.company_2.id, + "scrap_location": True, + } + ) + cls.scrap_location_3 = cls.env["stock.location"].create( + { + "name": "Test Scrap 3", + "location_id": parent_location.id, + "company_id": cls.company_2.id, + "scrap_location": True, + } + ) + cls.scrap_location_4 = cls.env["stock.location"].create( + { + "name": "Test Scrap 4", + "location_id": parent_location.id, + "company_id": cls.company.id, + "scrap_location": True, + } + ) + # Set advanced locations group + cls.env.user.groups_id += cls.env.ref("stock.group_stock_multi_locations") + + def test_scrap_location_default(self): + # Set default scrap location on company 2 + # Should be that one that is selected + # Set the scrap location 4 on main company + # Check if both different default scrap location are used + self.company_2.scrap_default_location_id = self.scrap_location_3 + scrap_form = Form(self.env["stock.scrap"].with_company(self.company_2)) + + scrap_form.product_id = self.product + self.assertEqual(self.scrap_location_3, scrap_form.scrap_location_id) + + # Set default on main company + self.company.scrap_default_location_id = self.scrap_location_4 + + # Check behaviour on main company + scrap_form = Form(self.env["stock.scrap"].with_company(self.company)) + scrap_form.product_id = self.product + self.assertEqual(self.scrap_location_4, scrap_form.scrap_location_id) + + # Check again behaviour on company 2 + scrap_form = Form(self.env["stock.scrap"].with_company(self.company_2)) + scrap_form.product_id = self.product + self.assertEqual(self.scrap_location_3, scrap_form.scrap_location_id) + + def test_scrap_location_no_default(self): + # Set no default scrap location + # Should be the one created with company + scrap_form = Form(self.env["stock.scrap"].with_company(self.company_2)) + scrap_form.product_id = self.product + self.assertTrue(self.scrap_location) + self.assertEqual(self.scrap_location, scrap_form.scrap_location_id) diff --git a/stock_scrap_location_default/views/res_config_settings.xml b/stock_scrap_location_default/views/res_config_settings.xml new file mode 100644 index 000000000..549f111b0 --- /dev/null +++ b/stock_scrap_location_default/views/res_config_settings.xml @@ -0,0 +1,32 @@ + + + + + + res.config.settings.form (in stock_scrap_location_default) + res.config.settings + + +
+
+
+
+
+
+
+
+
+
+ +