forked from OCA/stock-logistics-warehouse
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIGR] stock_available_mrp: migrate to v8
Compute potential quantities for both product templates and variants. To keep the code simple, only the biggest potential of any single variant is accounted for in the template's potential. Take all levels of phantom BoM into account, respects validity dates etc. thanks to the use of the standard method _bom_explode, as suggested by @gdgellatly in OCA#5 (comment) Improve tests, rewritten in python. Adhere to new file/manifest conventions. Simplify copyright headers
- Loading branch information
Lionel Sausin
committed
Nov 20, 2015
1 parent
bcf19ba
commit d7861aa
Showing
17 changed files
with
370 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved. | ||
# | ||
# 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 Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
# © 2014 Numérigraphe SARL | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import product | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,18 @@ | ||
# -*- coding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved. | ||
# | ||
# 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 Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
|
||
# © 2014 Numérigraphe SARL | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
{ | ||
'name': 'Consider the production potential is available to promise', | ||
'version': '2.0', | ||
'version': '8.0.3.0.0', | ||
"author": u"Numérigraphe,Odoo Community Association (OCA)", | ||
'category': 'Hidden', | ||
'depends': ['stock_available', 'mrp'], | ||
'data': [ | ||
'product_view.xml', | ||
'views/product_template_view.xml', | ||
], | ||
'test': [ | ||
'test/potential_qty.yml', | ||
'demo': [ | ||
'demo/mrp_bom.yml', | ||
], | ||
'license': 'AGPL-3', | ||
'installable': False | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
- Create a UoM in the category of PCE | ||
- !record {model: product.uom, id: thousand}: | ||
name: Thousand | ||
factor: 0.001 | ||
rounding: 0.001 | ||
uom_type: bigger | ||
category_id: product.product_uom_categ_unit | ||
|
||
- Add a BOM whereby 0.042K "RAM SR2" can be replaced with 13 dozens "HDD-SH1" + 8 CPUa8 with 50% efficiency. This lets us test UoM conversions for the finished product and the raw materials, as well as the unfolding of phantom BoMs | ||
- !record {model: mrp.bom, id: sr2_from_hdd}: | ||
name: RAM SR2 made from HDD-SH1 | ||
product_id: product.product_product_14 | ||
product_tmpl_id: product.product_product_14_product_template | ||
product_uom: thousand | ||
product_qty: 0.042 | ||
type: phantom | ||
sequence: -1 | ||
product_efficiency: 0.5 | ||
- !record {model: mrp.bom.line, id: sr2_from_hdd_line1}: | ||
bom_id: sr2_from_hdd | ||
product_id: product.product_product_18 | ||
product_qty: 13 | ||
product_uom: product.product_uom_dozen | ||
- !record {model: mrp.bom.line, id: sr2_from_hdd_line2}: | ||
bom_id: sr2_from_hdd | ||
product_id: product.product_product_23 | ||
product_qty: 8 | ||
product_uom: product.product_uom_unit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2014 Numérigraphe SARL | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import product_product | ||
from . import product_template |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2014 Numérigraphe SARL | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from collections import Counter | ||
|
||
from openerp import models, fields, api | ||
from openerp.addons import decimal_precision as dp | ||
|
||
|
||
class ProductProduct(models.Model): | ||
_inherit = 'product.product' | ||
|
||
potential_qty = fields.Float( | ||
compute='_get_potential_qty', | ||
type='float', | ||
digits_compute=dp.get_precision('Product Unit of Measure'), | ||
string='Potential', | ||
help="Quantity of this Product that could be produced using " | ||
"the materials already at hand.") | ||
|
||
@api.multi | ||
@api.depends('potential_qty') | ||
def _immediately_usable_qty(self): | ||
"""Add the potential quantity to the quantity available to promise. | ||
This is the same implementation as for templates.""" | ||
super(ProductProduct, self)._immediately_usable_qty() | ||
for product in self: | ||
product.immediately_usable_qty += product.potential_qty | ||
|
||
@api.multi | ||
def _get_potential_qty(self): | ||
"""Compute the potential qty based on the available components.""" | ||
# Browse the BOMs as superuser to bypass access rights | ||
bom_obj = self.env['mrp.bom'].sudo() | ||
|
||
for product in self: | ||
bom_id = bom_obj._bom_find(product_id=product.id) | ||
if not bom_id: | ||
product.potential_qty = 0.0 | ||
continue | ||
|
||
# Need by product (same product can be in many BOM lines/levels) | ||
component_needs = Counter() | ||
for component in bom_obj._bom_explode(bom_obj.browse(bom_id), | ||
product, 1.0,)[0]: | ||
component_needs += Counter( | ||
{component['product_id']: component['product_qty']}) | ||
if not component_needs: | ||
# The BoM has no line we can use | ||
product.potential_qty = 0.0 | ||
continue | ||
|
||
# Find the lowest quantity we can make with the stock at hand | ||
product.potential_qty = min( | ||
[self.browse(component_id).qty_available // need | ||
for component_id, need in component_needs.items()]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
# © 2014 Numérigraphe SARL | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openerp import models, fields, api | ||
from openerp.addons import decimal_precision as dp | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = 'product.template' | ||
|
||
potential_qty = fields.Float( | ||
compute='_get_potential_qty', | ||
type='float', | ||
digits_compute=dp.get_precision('Product Unit of Measure'), | ||
string='Potential', | ||
help="Quantity of this Product that could be produced using " | ||
"the materials already at hand. " | ||
"If the product has several variants, this will be the biggest " | ||
"quantity that can be made for a any single variant.") | ||
|
||
@api.multi | ||
@api.depends('potential_qty') | ||
def _immediately_usable_qty(self): | ||
"""Add the potential quantity to the quantity available to promise. | ||
This is the same implementation as for variants.""" | ||
super(ProductTemplate, self)._immediately_usable_qty() | ||
for tmpl in self: | ||
tmpl.immediately_usable_qty += tmpl.potential_qty | ||
|
||
@api.multi | ||
@api.depends('product_variant_ids.potential_qty') | ||
def _get_potential_qty(self): | ||
"""Compute the potential as the max of all the variants's potential. | ||
We can't add the potential of variants: if they share components we | ||
may not be able to make all the variants. | ||
So we set the arbitrary rule that we can promise up to the biggest | ||
variant's potential. | ||
""" | ||
for tmpl in self: | ||
if not tmpl.product_variant_ids: | ||
continue | ||
tmpl.potential_qty = max( | ||
[v.potential_qty for v in tmpl.product_variant_ids]) |
Oops, something went wrong.