Skip to content

Commit

Permalink
[IMP] Decouple the quantity for templates and variants
Browse files Browse the repository at this point in the history
There are cases where we dot NOT want to simply sum the quantities of all the variants. For example when dealing with manufacturing capacities, we may have to chose between variants because we can't make ALL of them with the same components.
So instead of a simple non-modular implementation, we'll let each module define his own implementation of how to compute the product template's quantity available for sale.
  • Loading branch information
Lionel Sausin committed Nov 9, 2015
1 parent ab46612 commit d32921d
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 10 deletions.
2 changes: 1 addition & 1 deletion stock_available/__openerp__.py
Expand Up @@ -20,7 +20,7 @@

{
'name': 'Stock available to promise',
'version': '8.0.2.0.0',
'version': '8.0.3.0.0',
"author": u"Numérigraphe,Odoo Community Association (OCA)",
'category': 'Warehouse',
'depends': ['stock'],
Expand Down
7 changes: 5 additions & 2 deletions stock_available/models/product_product.py
Expand Up @@ -36,8 +36,11 @@ def _immediately_usable_qty(self):
By default, available to promise = forecasted quantity.
Must be overridden by another module that actually implement
computations."""
**Each** sub-module **must** override this method in **both**
`product.product` **and** `product.template`, because we can't
decide in advance how to compute the template's quantity from the
variants.
"""
for prod in self:
prod.immediately_usable_qty = prod.virtual_available

Expand Down
15 changes: 10 additions & 5 deletions stock_available/models/product_template.py
Expand Up @@ -28,12 +28,17 @@ class ProductTemplate(models.Model):
@api.multi
@api.depends('product_variant_ids.immediately_usable_qty')
def _immediately_usable_qty(self):
"""Compute the quantity using all the variants"""
"""No-op implementation of the stock available to promise.
By default, available to promise = forecasted quantity.
**Each** sub-module **must** override this method in **both**
`product.product` **and** `product.template`, because we can't
decide in advance how to compute the template's quantity from the
variants.
"""
for tmpl in self:
tmpl.immediately_usable_qty = sum(
v.immediately_usable_qty
for v in tmpl.product_variant_ids
)
tmpl.immediately_usable_qty = tmpl.virtual_available

immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),
Expand Down
2 changes: 1 addition & 1 deletion stock_available_immediately/__openerp__.py
Expand Up @@ -22,7 +22,7 @@

{
"name": "Ignore planned receptions in quantity available to promise",
"version": "8.0.2.0.0",
"version": "8.0.2.0.1",
"depends": ["stock_available"],
"author": "Camptocamp,Odoo Community Association (OCA)",
"license": "AGPL-3",
Expand Down
1 change: 1 addition & 0 deletions stock_available_immediately/models/__init__.py
Expand Up @@ -19,3 +19,4 @@
##############################################################################

from . import product_product
from . import product_template
4 changes: 3 additions & 1 deletion stock_available_immediately/models/product_product.py
Expand Up @@ -28,7 +28,9 @@ class ProductProduct(models.Model):
@api.multi
@api.depends('virtual_available', 'incoming_qty')
def _immediately_usable_qty(self):
"""Ignore the incoming goods in the quantity available to promise"""
"""Ignore the incoming goods in the quantity available to promise
This is the same implementation as for templates."""
super(ProductProduct, self)._immediately_usable_qty()
for prod in self:
prod.immediately_usable_qty -= prod.incoming_qty
35 changes: 35 additions & 0 deletions stock_available_immediately/models/product_template.py
@@ -0,0 +1,35 @@
# -*- 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/>.
#
##############################################################################

from openerp import models, api


class ProductTemplate(models.Model):
_inherit = 'product.template'

@api.multi
@api.depends('virtual_available', 'incoming_qty')
def _immediately_usable_qty(self):
"""Ignore the incoming goods in 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.incoming_qty

0 comments on commit d32921d

Please sign in to comment.