Skip to content

Commit

Permalink
[FIX] corrected calculation of immediately_usable_qty on product.prod…
Browse files Browse the repository at this point in the history
…uct and

product.template, now takes in account variants and correctly displays value.
[FLAKE8]

Removing duplicate modules and moving README.rst into __unported__
  • Loading branch information
gfcapalbo committed Jun 19, 2015
1 parent e2b9ccb commit 6c16913
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
42 changes: 38 additions & 4 deletions stock_available/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
from openerp.addons import decimal_precision as dp


class ProductTemplate(models.Model):
class Product(models.Model):
"""Add a field for the stock available to promise.
Useful implementations need to be installed through the Settings menu or by
installing one of the modules stock_available_*
"""
_inherit = 'product.template'
_inherit = 'product.product'

@api.depends('virtual_available')
def _product_available(self):
def _immediately_usable_qty(self):
"""No-op implementation of the stock available to promise.
By default, available to promise = forecasted quantity.
Expand All @@ -43,7 +43,41 @@ def _product_available(self):

immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),
compute='_product_available',
compute='_immediately_usable_qty',
string='Available to promise',
help="Stock for this Product that can be safely proposed "
"for sale to Customers.\n"
"The definition of this value can be configured to suit "
"your needs")


class ProductTemplate(models.Model):
"""Add a field for the stock available to promise.
Useful implementations need to be installed through the Settings menu or by
installing one of the modules stock_available_*
"""
_inherit = 'product.template'

@api.depends('virtual_available')
def _immediately_usable_qty(self):
"""No-op implementation of the stock available to promise.
By default, available to promise = forecasted quantity.
Must be overridden by another module that actually implement
computations."""
product_model = self.env['product.product']
for product_template in self:
products = product_model.search([(
'product_tmpl_id', '=', product_template.id)])
qty = 0
for product in products:
qty += product.immediately_usable_qty
product_template.immediately_usable_qty = qty

immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),
compute='_immediately_usable_qty',
string='Available to promise',
help="Stock for this Product that can be safely proposed "
"for sale to Customers.\n"
Expand Down
13 changes: 5 additions & 8 deletions stock_available_immediately/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
#
##############################################################################

from openerp import models, fields, api
from openerp import models


class ProductTemplate(models.Model):
class Product(models.Model):
"""Subtract incoming qty from immediately_usable_qty"""
_inherit = 'product.template'
_inherit = 'product.product'

@api.depends('virtual_available')
def _product_available(self):
def _immediately_usable_qty(self):
"""Ignore the incoming goods in the quantity available to promise"""
super(ProductTemplate, self)._product_available()
super(Product, self)._immediately_usable_qty()
for product in self:
product.immediately_usable_qty -= product.incoming_qty

immediately_usable_qty = fields.Float(compute='_product_available')

0 comments on commit 6c16913

Please sign in to comment.