[9.0][IMP] mrp_mto_with_stock: adapt to OCA and minor fixes.

This commit is contained in:
lreficent
2017-04-26 18:38:39 +02:00
parent 63fb663bf3
commit 031578e7b0
6 changed files with 139 additions and 152 deletions

View File

@@ -0,0 +1,71 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==================
MRP MTO with Stock
==================
This module extends the functionality of Manufacturing to support the creation
of procurements when there is no stock available. This allow you to pull from
stock until the quantity on hand is zero, and then create a procurement
for fulfill the MO requirements.
Configuration
=============
To configure this module, you need to:
#. Activate the developer mode.
#. Go to the products you want to follow this behaviour.
#. In the view form got to the tab *Inventory* and check the box for the
route *Make To Order + Make To Stock*.
Usage
=====
To use this module, you need to:
#. Go to *Manufacturing* and create a Manufacturing Order.
#. Click on *Confirm Production*.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/129/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/manufacture/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* John Walsh <John.Walsh@interclean.com>
* Lois Rilo <lois.rilo@eficent.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -1,18 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
##############################################################################
import models
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2015 John Walsh
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

View File

@@ -1,47 +1,18 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
##############################################################################
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2015 John Walsh
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': "mrp_mto_with_stock",
'summary': """
Fix Manufacturing orders to pull from stock until qty is zero,
and then create a procurement for them""",
'description': """
Long description of module's purpose
""",
'author': "John Walsh",
'website': "http://github.com/michaeljohn32",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list
'category': 'Hidden/Dependency',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['mrp', 'stock_mts_mto_rule'],
# always loaded
'data': [
],
# only loaded in demonstration mode
'demo': [
],
"name": "MRP MTO with Stock",
"summary": "Fix Manufacturing orders to pull from stock until qty is "
"zero, and then create a procurement for them.",
"author": "John Walsh, Eficent, Odoo Community Association (OCA)",
"website": "https://odoo-community.org/",
"category": "Manufacturing",
"version": "9.0.1.0.0",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["mrp", "stock_mts_mto_rule"],
}

View File

@@ -1,19 +1,6 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.
#
##############################################################################
import stock
import mrp
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2015 John Walsh
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import mrp

View File

@@ -1,67 +1,62 @@
# -*- encoding: utf-8 -*-
from openerp import fields, models, api
import pdb
# -*- coding: utf-8 -*-
# Copyright 2017 Eficent Business and IT Consulting Services S.L.
# Copyright 2015 John Walsh
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import api, models
import logging
_logger = logging.getLogger(__name__)
class mrp_production(models.Model):
class MrpProduction(models.Model):
_inherit = 'mrp.production'
# @api.model
# def _make_consume_line_from_data(self, production, product, uom_id, qty, uos_id, uos_qty):
# '''Confirms stock move or put it in waiting if it's linked to another move.
# @returns list of ids'''
# pdb.set_trace()
# # change the qty to make two moves (if needed)
# res = super(mrp_production, self)._make_consume_line_from_data(production, product, uom_id, uos_id, uos_qty)
# return res
@api.one
def action_confirm(self):
'''Confirms stock move or put it in waiting if it's linked to another move.
@returns list of ids'''
# pdb.set_trace()
"""Confirms stock move or put it in waiting if it's linked to another move.
@returns list of ids"""
# change the qty to make two moves (if needed)
res = super(mrp_production, self).action_confirm()
res = super(MrpProduction, self).action_confirm()
# try to assign moves (and generate procurements!)
self.action_assign()
return res
@api.one
def action_assign(self):
'''Reserves available products to the production order
but also creates procurements for more items if we
cannot reserve enough (MTO with stock)
@returns list of ids'''
# reserve all that is available
res = super(mrp_production, self).action_assign()
"""Reserves available products to the production order but also reates
procurements for more items if we cannot reserve enough (MTO with
stock).
@returns list of ids"""
# reserve all that is available (standard behaviour):
res = super(MrpProduction, self).action_assign()
# try to create procurements:
mtos_route = self.env.ref('stock_mts_mto_rule.route_mto_mts')
for move in self.move_lines:
if move.state == 'confirmed' and mtos_route.id in move.product_id.route_ids.ids:
#This move is waiting availability
#create a domain
#TODO: check other possible states confirmed/exception?
domain = [('product_id','=', move.product_id.id),('state','=','running'),('move_dest_id','=',move.id)]
if (move.state == 'confirmed' and mtos_route.id in
move.product_id.route_ids.ids):
domain = [('product_id', '=', move.product_id.id),
('state', '=', 'running'),
('move_dest_id', '=', move.id)]
if move.group_id:
domain.append(('group_id','=',move.group_id.id))
domain.append(('group_id', '=', move.group_id.id))
procurement = self.env['procurement.order'].search(domain)
if not procurement:
# we need to create a procurement
qty_to_procure = move.remaining_qty - move.reserved_availability
proc_dict = self._prepare_mto_procurement(move, qty_to_procure)
procurement = self.env['procurement.order'].create(proc_dict)
qty_to_procure = (move.remaining_qty -
move.reserved_availability)
proc_dict = self._prepare_mto_procurement(
move, qty_to_procure)
self.env['procurement.order'].create(proc_dict)
return res
def _prepare_mto_procurement(self, move, qty):
'''Prepares a procurement for a MTO move
using similar logic to /stock/stock.py/class stock_move/_prepare_procurement_from_move()
'''
origin = ((move.group_id and (move.group_id.name) + ":") or "") + ((move.name and move.name + ":") or "") + ('MTO -> Production')
group_id = move.group_id and move.group_id.id or False
route_ids = [self.env.ref('stock.route_warehouse0_mto')]
return{
def _prepare_mto_procurement(self, move, qty):
"""Prepares a procurement for a MTO product."""
origin = ((move.group_id and move.group_id.name + ":") or "") + \
((move.name and move.name + ":") or "") + 'MTO -> Production'
group_id = move.group_id and move.group_id.id or False
route_ids = self.env.ref('stock.route_warehouse0_mto')
warehouse_id = (move.warehouse_id.id or (move.picking_type_id and
move.picking_type_id.warehouse_id.id or False))
return {
'name': move.name + ':' + str(move.id),
'origin': origin,
'company_id': move.company_id and move.company_id.id or False,
@@ -69,18 +64,10 @@ class mrp_production(models.Model):
'product_id': move.product_id.id,
'product_qty': qty,
'product_uom': move.product_uom.id,
'product_uos_qty': qty, #FIXME: (move.product_uos and move.product_uos_qty) or move.product_uom_qty,
'product_uos': move.product_uom.id, #FIXME:(move.product_uos and move.product_uos.id) or move.product_uom.id,
'location_id': move.location_id.id,
'move_dest_id': move.id,
'group_id': group_id,
'route_ids':[(4, x.id) for x in route_ids],
'warehouse_id': move.warehouse_id.id or (move.picking_type_id and move.picking_type_id.warehouse_id.id or False),
'route_ids': [(6, 0, route_ids.ids)],
'warehouse_id': warehouse_id,
'priority': move.priority,
}
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@@ -1,17 +0,0 @@
# -*- encoding: utf-8 -*-
from openerp import fields, models, api
import pdb
class stock_move(models.Model):
_inherit = 'stock.move'
@api.multi
def action_confirm(self):
'''Confirms stock move or put it in waiting if it's linked to another move.
@returns list of ids'''
res = super(stock_move, self).action_confirm()
return res
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: