From 738f7f5cf04895fd2452932bb78baa75504e7b88 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Tue, 28 Aug 2018 11:21:29 +0200 Subject: [PATCH] Take draft PO quantities into account for forecast stock in mrp_mto_with_stock --- mrp_mto_with_stock/models/mrp_production.py | 9 ++++++ mrp_mto_with_stock_purchase/__init__.py | 5 +++ mrp_mto_with_stock_purchase/__manifest__.py | 21 +++++++++++++ .../models/__init__.py | 5 +++ .../models/mrp_production.py | 31 +++++++++++++++++++ .../readme/CONFIGURE.rst | 1 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 5 +++ mrp_mto_with_stock_purchase/readme/USAGE.rst | 8 +++++ 9 files changed, 86 insertions(+) create mode 100644 mrp_mto_with_stock_purchase/__init__.py create mode 100644 mrp_mto_with_stock_purchase/__manifest__.py create mode 100644 mrp_mto_with_stock_purchase/models/__init__.py create mode 100644 mrp_mto_with_stock_purchase/models/mrp_production.py create mode 100644 mrp_mto_with_stock_purchase/readme/CONFIGURE.rst create mode 100644 mrp_mto_with_stock_purchase/readme/CONTRIBUTORS.rst create mode 100644 mrp_mto_with_stock_purchase/readme/DESCRIPTION.rst create mode 100644 mrp_mto_with_stock_purchase/readme/USAGE.rst diff --git a/mrp_mto_with_stock/models/mrp_production.py b/mrp_mto_with_stock/models/mrp_production.py index 73ad9012b..c2ae07cf8 100644 --- a/mrp_mto_with_stock/models/mrp_production.py +++ b/mrp_mto_with_stock/models/mrp_production.py @@ -122,6 +122,13 @@ class MrpProduction(models.Model): raise UserError('\n'.join(errors)) return True + # 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... + @api.model + def _get_incoming_qty_waiting_validation(self, move): + return 0.0 + @api.multi def get_mto_qty_to_procure(self, move): self.ensure_one() @@ -130,6 +137,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/__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..a598c18b0 --- /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://odoo-community.org/", + "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.