[FIX] corrected calculation of immediately_usable_qty on product.product and

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

Removing duplicate modules and moving README.rst into __unported__
This commit is contained in:
gfcapalbo
2015-03-18 13:20:03 +01:00
parent e2b9ccbf1e
commit 6c16913493
4 changed files with 43 additions and 12 deletions

View File

@@ -22,16 +22,16 @@ from openerp import models, fields, api
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.
@@ -43,7 +43,41 @@ class ProductTemplate(models.Model):
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"

View File

@@ -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')