[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__

[ADD} location calculations

[FIX] typo
This commit is contained in:
gfcapalbo
2015-03-18 13:20:03 +01:00
committed by ps-tubtim
parent 8da242ce15
commit c3519850df
2 changed files with 29 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
#-*- coding: utf-8 -*-
##############################################################################
#
# This module is copyright (C) 2014 Numérigraphe SARL. All Rights Reserved.
@@ -24,28 +24,41 @@ from openerp.addons import decimal_precision as dp
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'
# immediately usable quantity caluculated with the quant method
@api.multi
@api.depends('virtual_available')
def _product_available(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."""
for product in self:
product.immediately_usable_qty = product.virtual_available
def _immediately_usable_qty(self):
stock_location_obj = self.env['stock.location']
internal_locations = stock_location_obj.search([
('usage', '=', 'internal')])
sublocation_ids = []
for location in internal_locations:
sublocation_ids.append(self.env['stock.location'].search(
[('id', 'child_of', location.id)]).ids)
for product_template in self:
quant_obj = self.env['stock.quant']
quants = quant_obj.search([
('location_id', 'in', sublocation_ids),
('product_id', 'in', product_template.ids),
('reservation_id', '=', False)])
availability = 0
if quants:
for quant in quants:
availability += quant.qty
product_template.immediately_usable_qty = availability
immediately_usable_qty = fields.Float(
digits=dp.get_precision('Product Unit of Measure'),
compute='_product_available',
string='Available to promise',
compute='_immediately_usable_qty',
string='Available to promise (quant calculation)',
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")
"your needs , this number is obtained by using the new odoo 8 "
"quants, so it gives us the actual curren quants minus reserved"
"quants")

View File

@@ -22,8 +22,8 @@
<tree position="attributes">
<attribute name="colors">red:immediately_usable_qty&lt;0;blue:immediately_usable_qty&gt;=0 and state in ('draft', 'end', 'obsolete');black:immediately_usable_qty&gt;=0 and state not in ('draft', 'end', 'obsolete')</attribute>
</tree>
<field name="virtual_available" position="after">
<field name="immediately_usable_qty" />
<field name="virtual_available" position="after">
<field name="immediately_usable_qty" />
</field>
</data>
</field>