mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[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:
@@ -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")
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
<tree position="attributes">
|
||||
<attribute name="colors">red:immediately_usable_qty<0;blue:immediately_usable_qty>=0 and state in ('draft', 'end', 'obsolete');black:immediately_usable_qty>=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>
|
||||
|
||||
Reference in New Issue
Block a user