diff --git a/mrp_multi_level/tests/test_mrp_multi_level.py b/mrp_multi_level/tests/test_mrp_multi_level.py index 37782e06dc..bb70eafa7a 100644 --- a/mrp_multi_level/tests/test_mrp_multi_level.py +++ b/mrp_multi_level/tests/test_mrp_multi_level.py @@ -4,10 +4,12 @@ from datetime import date, datetime, timedelta from odoo import fields +from odoo.tests import tagged from .common import TestMrpMultiLevelCommon +@tagged("post_install", "-at_install") class TestMrpMultiLevel(TestMrpMultiLevelCommon): def test_01_mrp_levels(self): """Tests computation of MRP levels.""" diff --git a/mrp_production_date_planned_finished/models/mrp_production.py b/mrp_production_date_planned_finished/models/mrp_production.py index 81e50b3097..ecffdf6805 100644 --- a/mrp_production_date_planned_finished/models/mrp_production.py +++ b/mrp_production_date_planned_finished/models/mrp_production.py @@ -10,12 +10,16 @@ class MrpProduction(models.Model): _inherit = "mrp.production" + def _get_date_planned_start_using_delays(self): + date_planned_start = self.date_planned_finished + date_planned_start -= relativedelta(days=self.product_id.produce_delay) + date_planned_start -= relativedelta(days=self.company_id.manufacturing_lead) + return date_planned_start + @api.onchange("date_planned_finished") def _onchange_date_planned_finished_set_date_planned_start(self): if self.date_planned_finished and not self.is_planned: - date_planned_start = self.date_planned_finished - date_planned_start -= relativedelta(days=self.product_id.produce_delay) - date_planned_start -= relativedelta(days=self.company_id.manufacturing_lead) + date_planned_start = self._get_date_planned_start_using_delays() if date_planned_start == self.date_planned_finished: date_planned_start -= relativedelta(hours=1) if self.date_planned_start != date_planned_start: diff --git a/mrp_production_date_planned_finished_calendar/README.rst b/mrp_production_date_planned_finished_calendar/README.rst new file mode 100644 index 0000000000..7f3ff6d6b5 --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/README.rst @@ -0,0 +1,84 @@ +============================================= +MRP Production Date Planned Finished Calendar +============================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:dfe27f551e8bd826eacd465bf8752bcc528b7f000525d006fa4c6d1a51280a79 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/15.0/mrp_production_date_planned_finished_calendar + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-15-0/manufacture-15-0-mrp_production_date_planned_finished_calendar + :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/manufacture&target_branch=15.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Glue module between `mrp_production_date_planned_finished` and `mrp_warehouse_calendar`. + +**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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* ForgeFlow + +Contributors +~~~~~~~~~~~~ + +* 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. + +.. |maintainer-LoisRForgeFlow| image:: https://github.com/LoisRForgeFlow.png?size=40px + :target: https://github.com/LoisRForgeFlow + :alt: LoisRForgeFlow + +Current `maintainer `__: + +|maintainer-LoisRForgeFlow| + +This module is part of the `OCA/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_production_date_planned_finished_calendar/__init__.py b/mrp_production_date_planned_finished_calendar/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mrp_production_date_planned_finished_calendar/__manifest__.py b/mrp_production_date_planned_finished_calendar/__manifest__.py new file mode 100644 index 0000000000..cef4bb9609 --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "MRP Production Date Planned Finished Calendar", + "summary": "Allows to plan production from the desired finish date", + "version": "15.0.1.0.0", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "maintainers": ["LoisRForgeFlow"], + "website": "https://github.com/OCA/manufacture", + "license": "AGPL-3", + "category": "Manufacturing", + "depends": ["mrp_production_date_planned_finished", "mrp_warehouse_calendar"], + "installable": True, + "auto_install": True, +} diff --git a/mrp_production_date_planned_finished_calendar/models/__init__.py b/mrp_production_date_planned_finished_calendar/models/__init__.py new file mode 100644 index 0000000000..a9e5f13e42 --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/models/__init__.py @@ -0,0 +1 @@ +from . import mrp_production diff --git a/mrp_production_date_planned_finished_calendar/models/mrp_production.py b/mrp_production_date_planned_finished_calendar/models/mrp_production.py new file mode 100644 index 0000000000..8f892e7a93 --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/models/mrp_production.py @@ -0,0 +1,16 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class MrpProduction(models.Model): + _inherit = "mrp.production" + + def _get_date_planned_start_using_delays(self): + warehouse = self.picking_type_id.warehouse_id + date_planned_start = self.date_planned_finished + if warehouse.calendar_id: + delay = self.product_id.produce_delay + self.company_id.manufacturing_lead + return warehouse.calendar_id.plan_days(-1 * (delay + 1), date_planned_start) + return super()._get_date_planned_start_using_delays() diff --git a/mrp_production_date_planned_finished_calendar/readme/CONTRIBUTORS.rst b/mrp_production_date_planned_finished_calendar/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000000..77dfbe89e9 --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Lois Rilo diff --git a/mrp_production_date_planned_finished_calendar/readme/DESCRIPTION.rst b/mrp_production_date_planned_finished_calendar/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..c5fa6e12ca --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Glue module between `mrp_production_date_planned_finished` and `mrp_warehouse_calendar`. diff --git a/mrp_production_date_planned_finished_calendar/static/description/icon.png b/mrp_production_date_planned_finished_calendar/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/mrp_production_date_planned_finished_calendar/static/description/icon.png differ diff --git a/mrp_production_date_planned_finished_calendar/static/description/index.html b/mrp_production_date_planned_finished_calendar/static/description/index.html new file mode 100644 index 0000000000..58d9c1c9f0 --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/static/description/index.html @@ -0,0 +1,422 @@ + + + + + +MRP Production Date Planned Finished Calendar + + + +
+

MRP Production Date Planned Finished Calendar

+ + +

Beta License: AGPL-3 OCA/manufacture Translate me on Weblate Try me on Runboat

+

Glue module between mrp_production_date_planned_finished and mrp_warehouse_calendar.

+

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 to smash 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.

+

Current maintainer:

+

LoisRForgeFlow

+

This module is part of the OCA/manufacture project on GitHub.

+

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

+
+
+
+ + diff --git a/mrp_production_date_planned_finished_calendar/tests/__init__.py b/mrp_production_date_planned_finished_calendar/tests/__init__.py new file mode 100644 index 0000000000..d17b25990d --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/tests/__init__.py @@ -0,0 +1 @@ +from . import test_date_planned_finished_calendar diff --git a/mrp_production_date_planned_finished_calendar/tests/test_date_planned_finished_calendar.py b/mrp_production_date_planned_finished_calendar/tests/test_date_planned_finished_calendar.py new file mode 100644 index 0000000000..150fbddd5b --- /dev/null +++ b/mrp_production_date_planned_finished_calendar/tests/test_date_planned_finished_calendar.py @@ -0,0 +1,43 @@ +# Copyright 2024 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import date + +from odoo import fields +from odoo.tests import Form, TransactionCase + + +class TestDatePlannedFinished(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.company = cls.env.ref("base.main_company") + cls.warehouse = cls.env.ref("stock.warehouse0") + cls.calendar = cls.env.ref("resource.resource_calendar_std") + cls.company.manufacturing_lead = 1 + cls.product = cls.env.ref("mrp.product_product_computer_desk") + cls.product.produce_delay = 1 + cls.product_bom = cls.env.ref("mrp.mrp_bom_desk") + + def test_mrp_production_date_planned_finished_onchange(self): + """Test that date_planned_start is set when date_planned_finished + is changed respecting calendar.""" + with Form(self.env["mrp.production"]) as mo: + mo.product_id = self.product + mo.bom_id = self.product_bom + mo.product_qty = 1 + mo.date_planned_finished = "2024-11-18 10:00:00" # Monday + self.assertEqual( + fields.Date.to_date(mo.date_planned_start), date(2024, 11, 16) + ) # Saturday + # Configure calendar in warehouse (Monday to Friday) + self.warehouse.calendar_id = self.calendar + with Form(self.env["mrp.production"]) as mo: + mo.product_id = self.product + mo.bom_id = self.product_bom + mo.product_qty = 1 + mo.date_planned_finished = "2024-11-18 10:00:00" # Monday + self.assertEqual( + fields.Date.to_date(mo.date_planned_start), date(2024, 11, 14) + ) # Thursday diff --git a/setup/mrp_production_date_planned_finished_calendar/odoo/addons/mrp_production_date_planned_finished_calendar b/setup/mrp_production_date_planned_finished_calendar/odoo/addons/mrp_production_date_planned_finished_calendar new file mode 120000 index 0000000000..501012dfe5 --- /dev/null +++ b/setup/mrp_production_date_planned_finished_calendar/odoo/addons/mrp_production_date_planned_finished_calendar @@ -0,0 +1 @@ +../../../../mrp_production_date_planned_finished_calendar \ No newline at end of file diff --git a/setup/mrp_production_date_planned_finished_calendar/setup.py b/setup/mrp_production_date_planned_finished_calendar/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/mrp_production_date_planned_finished_calendar/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)