diff --git a/mrp_mto_with_stock/models/mrp_production.py b/mrp_mto_with_stock/models/mrp_production.py index dc6a585f5..5fb115486 100644 --- a/mrp_mto_with_stock/models/mrp_production.py +++ b/mrp_mto_with_stock/models/mrp_production.py @@ -99,6 +99,15 @@ class MrpProduction(models.Model): vals['move_dest_id'] = move.id return vals + @api.model + def _get_incoming_qty_waiting_validation(self, move): + """ + This method should be overriden in submodule to manage cases where + we need to add quantities to the forecast quantity. Like draft + purchase order, purchase request, etc... + """ + return 0.0 + @api.multi def get_mto_qty_to_procure(self, move): self.ensure_one() @@ -107,6 +116,8 @@ class MrpProduction(models.Model): virtual_available = move_location.product_id.virtual_available qty_available = move.product_id.uom_id._compute_quantity( virtual_available, move.product_uom) + draft_incoming_qty = self._get_incoming_qty_waiting_validation(move) + qty_available += draft_incoming_qty if qty_available >= 0: return 0.0 else: diff --git a/mrp_mto_with_stock_purchase/README.rst b/mrp_mto_with_stock_purchase/README.rst new file mode 100644 index 000000000..98de72359 --- /dev/null +++ b/mrp_mto_with_stock_purchase/README.rst @@ -0,0 +1,94 @@ +=========================== +MRP MTO with Stock Purchase +=========================== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! 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%2Fmanufacture-lightgray.png?logo=github + :target: https://github.com/OCA/manufacture/tree/10.0/mrp_mto_with_stock_purchase + :alt: OCA/manufacture +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/manufacture-10-0/manufacture-10-0-mrp_mto_with_stock_purchase + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/129/10.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module make compatible mrp_mto_with_stock and purchase modules. +Indeed, there is an option in mto_mto_with_stock to check the forecast stock +when checking the availibility of a Manufacture Order. But this forecast stock +does not take into account the quantities coming from draft POs. This module +adds this behavior. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +* This module is installed automatically when mrp_mto_with_stock and purchase module are installed + +Usage +===== + +When a manufacturing order is created out of a procurement evaluation +(from an orderpoint, MTO,...) the calendar is considered in the computation +of the planned start date of the manufacturing order. + +For example, if it takes 1 day to manufacture a product and it is required +for Monday, the manufacturing order will be created with planned start date +on the previous Friday, if the warehouse operates under a Mo-Fri working +calendar. + +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 +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* * Florian da Costa + +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/manufacture `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mrp_mto_with_stock_purchase/__init__.py b/mrp_mto_with_stock_purchase/__init__.py new file mode 100644 index 000000000..9cf531149 --- /dev/null +++ b/mrp_mto_with_stock_purchase/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import models diff --git a/mrp_mto_with_stock_purchase/__manifest__.py b/mrp_mto_with_stock_purchase/__manifest__.py new file mode 100644 index 000000000..00bfe22b3 --- /dev/null +++ b/mrp_mto_with_stock_purchase/__manifest__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "MRP MTO with Stock Purchase", + "summary": "Module needed to make mrp_mto_with_stock module compatible " + "with purchase module.", + "author": "Akretion, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/manufacture", + "category": "Manufacturing", + "version": "10.0.1.0.0", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "mrp_mto_with_stock", + "purchase" + ], + "auto_install": True, +} diff --git a/mrp_mto_with_stock_purchase/models/__init__.py b/mrp_mto_with_stock_purchase/models/__init__.py new file mode 100644 index 000000000..387c06773 --- /dev/null +++ b/mrp_mto_with_stock_purchase/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import mrp_production diff --git a/mrp_mto_with_stock_purchase/models/mrp_production.py b/mrp_mto_with_stock_purchase/models/mrp_production.py new file mode 100644 index 000000000..6c0e8274c --- /dev/null +++ b/mrp_mto_with_stock_purchase/models/mrp_production.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Copyright 2018 Akretion +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class MrpProduction(models.Model): + _inherit = 'mrp.production' + + @api.model + def _get_incoming_qty_waiting_validation(self, move): + qty = super(MrpProduction, self)._get_incoming_qty_waiting_validation( + move) + location_ids = self.env['stock.location'].search( + [('id', 'child_of', move.location_id.id)]) + picking_types = self.env['stock.picking.type'].search( + [('default_location_dest_id', 'in', + location_ids.ids)]) + orders = self.env['purchase.order'].search( + [('picking_type_id', 'in', picking_types.ids), + ('state', 'in', ['draft', 'sent', 'to approve'])]) + po_lines = self.env['purchase.order.line'].search( + [('order_id', 'in', orders.ids), + ('product_qty', '>', 0.0), + ('product_id', '=', move.product_id.id)]) + for line in po_lines: + qty_uom = line.product_uom._compute_quantity( + line.product_qty, move.product_uom) + qty += qty_uom + return qty diff --git a/mrp_mto_with_stock_purchase/readme/CONFIGURE.rst b/mrp_mto_with_stock_purchase/readme/CONFIGURE.rst new file mode 100644 index 000000000..d632fcb9f --- /dev/null +++ b/mrp_mto_with_stock_purchase/readme/CONFIGURE.rst @@ -0,0 +1 @@ +* This module is installed automatically when mrp_mto_with_stock and purchase module are installed diff --git a/mrp_mto_with_stock_purchase/readme/CONTRIBUTORS.rst b/mrp_mto_with_stock_purchase/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..28e4ebc3a --- /dev/null +++ b/mrp_mto_with_stock_purchase/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* * Florian da Costa diff --git a/mrp_mto_with_stock_purchase/readme/DESCRIPTION.rst b/mrp_mto_with_stock_purchase/readme/DESCRIPTION.rst new file mode 100644 index 000000000..a1e77ff2a --- /dev/null +++ b/mrp_mto_with_stock_purchase/readme/DESCRIPTION.rst @@ -0,0 +1,5 @@ +This module make compatible mrp_mto_with_stock and purchase modules. +Indeed, there is an option in mto_mto_with_stock to check the forecast stock +when checking the availibility of a Manufacture Order. But this forecast stock +does not take into account the quantities coming from draft POs. This module +adds this behavior. diff --git a/mrp_mto_with_stock_purchase/readme/USAGE.rst b/mrp_mto_with_stock_purchase/readme/USAGE.rst new file mode 100644 index 000000000..081b0392d --- /dev/null +++ b/mrp_mto_with_stock_purchase/readme/USAGE.rst @@ -0,0 +1,8 @@ +When a manufacturing order is created out of a procurement evaluation +(from an orderpoint, MTO,...) the calendar is considered in the computation +of the planned start date of the manufacturing order. + +For example, if it takes 1 day to manufacture a product and it is required +for Monday, the manufacturing order will be created with planned start date +on the previous Friday, if the warehouse operates under a Mo-Fri working +calendar.