Skip to content

Commit 2572282

Browse files
SodexisTeamasaunier
authored andcommitted
[10.0][MIG] stock_available & stock_available_immediately (OCA#219)
1 parent bfbd328 commit 2572282

13 files changed

+157
-43
lines changed

stock_available/README.rst

+31-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
==========================
16
Stock available to promise
27
==========================
38

@@ -8,16 +13,16 @@ configuration, it can account for various data such as sales quotations or
813
immediate production capacity.
914
In case of immediate production capacity, it is possible to configure on which
1015
field the potential is computed, by default Quantity On Hand is used.
11-
This can be configured in the menu Settings > Configuration > Warehouse.
16+
This can be configured in `Inventory` > `Configuration` > `Settings`.
1217

1318
Configuration
1419
=============
1520

1621
By default, this module computes the stock available to promise as the virtual
1722
stock.
18-
To take davantage of the additional features, you must which information you
23+
To take advantage of the additional features, you must which information you
1924
want to base the computation, by checking one or more boxes in the settings:
20-
`Configuration` > `Warehouse` > `Stock available to promise`.
25+
`Inventory` > `Configuration` > `Settings` > `Stock available to promise`.
2126
In case of "Include the production potential", it is also possible to configure
2227
which field of product to use to compute the production potential.
2328

@@ -28,25 +33,43 @@ This module adds a field named `Available for sale` on the Product form.
2833
Various additional fields may be added, depending on which information you
2934
chose to base the computation on.
3035

36+
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
37+
:alt: Try me on Runbot
38+
:target: https://runbot.odoo-community.org/runbot/153/10.0
39+
40+
Bug Tracker
41+
===========
42+
43+
Bugs are tracked on `GitHub Issues
44+
<https://github.com/OCA/stock-logistics-warehouse/issues>`_. In case of trouble, please
45+
check there if your issue has already been reported. If you spotted it first,
46+
help us smashing it by providing a detailed and welcomed feedback.
47+
3148
Credits
3249
=======
3350

51+
Images
52+
------
53+
54+
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
55+
3456
Contributors
3557
------------
3658

3759
* Lionel Sausin (Numérigraphe) <ls@numerigraphe.com>
3860
* Sodexis <sodexis@sodexis.com>
39-
* many others contributed to sub-modules, please refer to each sub-module's credits
4061

4162
Maintainer
4263
----------
4364

44-
.. image:: http://odoo-community.org/logo.png
65+
.. image:: https://odoo-community.org/logo.png
4566
:alt: Odoo Community Association
46-
:target: http://odoo-community.org
67+
:target: https://odoo-community.org
4768

4869
This module is maintained by the OCA.
4970

50-
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
71+
OCA, or the Odoo Community Association, is a nonprofit organization whose
72+
mission is to support the collaborative development of Odoo features and
73+
promote its widespread use.
5174

52-
To contribute to this module, please visit http://odoo-community.org.
75+
To contribute to this module, please visit https://odoo-community.org.

stock_available/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
2-
# © 2014 Numérigraphe, Sodexis
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
45

56
from . import models

stock_available/__manifest__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# -*- coding: utf-8 -*-
2-
# © 2014 Numérigraphe, Sodexis
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
45

56
{
67
'name': 'Stock available to promise',
7-
'version': '9.0.1.1.0',
8+
'version': '10.0.1.0.0',
89
"author": "Numérigraphe, Sodexis, Odoo Community Association (OCA)",
910
'category': 'Warehouse',
1011
'depends': ['stock'],

stock_available/models/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# -*- coding: utf-8 -*-
2-
# © 2014 Numérigraphe, Sodexis
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
45

5-
from . import product_template, product_product, res_config
6+
from . import product_template
7+
from . import product_product
8+
from . import res_config

stock_available/models/product_product.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# -*- coding: utf-8 -*-
2-
# © 2014 Numérigraphe, Sodexis
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
45

5-
from openerp import models, fields, api
6-
from openerp.addons import decimal_precision as dp
6+
from odoo import models, fields, api
7+
from odoo.addons import decimal_precision as dp
78

89

910
class ProductProduct(models.Model):
@@ -16,7 +17,7 @@ class ProductProduct(models.Model):
1617

1718
@api.multi
1819
@api.depends('virtual_available')
19-
def _immediately_usable_qty(self):
20+
def _compute_immediately_usable_qty(self):
2021
"""No-op implementation of the stock available to promise.
2122
2223
By default, available to promise = forecasted quantity.
@@ -29,11 +30,26 @@ def _immediately_usable_qty(self):
2930
for prod in self:
3031
prod.immediately_usable_qty = prod.virtual_available
3132

33+
@api.multi
34+
@api.depends()
35+
def _compute_potential_qty(self):
36+
"""Set potential qty to 0.0 to define the field defintion used by
37+
other modules to inherit it
38+
"""
39+
for product in self:
40+
product.potential_qty = 0.0
41+
3242
immediately_usable_qty = fields.Float(
3343
digits=dp.get_precision('Product Unit of Measure'),
34-
compute='_immediately_usable_qty',
44+
compute='_compute_immediately_usable_qty',
3545
string='Available to promise',
3646
help="Stock for this Product that can be safely proposed "
3747
"for sale to Customers.\n"
3848
"The definition of this value can be configured to suit "
3949
"your needs")
50+
potential_qty = fields.Float(
51+
compute='_compute_potential_qty',
52+
digits=dp.get_precision('Product Unit of Measure'),
53+
string='Potential',
54+
help="Quantity of this Product that could be produced using "
55+
"the materials already at hand.")
+30-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# -*- coding: utf-8 -*-
2-
# © 2014 Numérigraphe, Sodexis
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
45

5-
from openerp import models, fields, api
6-
from openerp.addons import decimal_precision as dp
6+
from odoo import models, fields, api
7+
from odoo.addons import decimal_precision as dp
78

89

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

1213
@api.multi
1314
@api.depends('product_variant_ids.immediately_usable_qty')
14-
def _immediately_usable_qty(self):
15+
def _compute_immediately_usable_qty(self):
1516
"""No-op implementation of the stock available to promise.
1617
1718
By default, available to promise = forecasted quantity.
@@ -24,11 +25,35 @@ def _immediately_usable_qty(self):
2425
for tmpl in self:
2526
tmpl.immediately_usable_qty = tmpl.virtual_available
2627

28+
@api.multi
29+
@api.depends('product_variant_ids.potential_qty')
30+
def _compute_potential_qty(self):
31+
"""Compute the potential as the max of all the variants's potential.
32+
33+
We can't add the potential of variants: if they share components we
34+
may not be able to make all the variants.
35+
So we set the arbitrary rule that we can promise up to the biggest
36+
variant's potential.
37+
"""
38+
for tmpl in self:
39+
if not tmpl.product_variant_ids:
40+
continue
41+
tmpl.potential_qty = max(
42+
[v.potential_qty for v in tmpl.product_variant_ids])
43+
2744
immediately_usable_qty = fields.Float(
2845
digits=dp.get_precision('Product Unit of Measure'),
29-
compute='_immediately_usable_qty',
46+
compute='_compute_immediately_usable_qty',
3047
string='Available to promise',
3148
help="Stock for this Product that can be safely proposed "
3249
"for sale to Customers.\n"
3350
"The definition of this value can be configured to suit "
3451
"your needs")
52+
potential_qty = fields.Float(
53+
compute='_compute_potential_qty',
54+
digits=dp.get_precision('Product Unit of Measure'),
55+
string='Potential',
56+
help="Quantity of this Product that could be produced using "
57+
"the materials already at hand. "
58+
"If the product has several variants, this will be the biggest "
59+
"quantity that can be made for a any single variant.")

stock_available/models/res_config.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# -*- coding: utf-8 -*-
2-
# © 2014 Numérigraphe, Sodexis
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
34
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
45

5-
from openerp import api, models, fields
6+
from odoo import api, models, fields
67

78

89
class StockConfig(models.TransientModel):
9.23 KB
Loading

stock_available/tests/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
4+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
5+
6+
from . import test_stock_available
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2014 Numérigraphe
3+
# Copyright 2016 Sodexis
4+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
5+
6+
from odoo.tests.common import TransactionCase
7+
8+
9+
class TestStockLogisticsWarehouse(TransactionCase):
10+
11+
def test_res_config(self):
12+
"""Test the config file"""
13+
stock_setting = self.env['stock.config.settings'].create({})
14+
15+
self.assertEquals(
16+
stock_setting.stock_available_mrp_based_on,
17+
'qty_available')
18+
stock_setting.stock_available_mrp_based_on = 'immediately_usable_qty'
19+
stock_setting.set_stock_available_mrp_based_on()
20+
self.assertEquals(
21+
stock_setting.stock_available_mrp_based_on,
22+
'immediately_usable_qty')
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- © 2014 Numérigraphe, Sodexis
2+
<!-- Copyright 2014 Numérigraphe
3+
Copyright 2016 Sodexis
34
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
45

5-
<openerp>
6-
<data>
6+
<odoo>
77
<record model="ir.ui.view" id="product_normal_form_view">
88
<field name="name">Quantity available to promise (variant tree)</field>
99
<field name="model">product.product</field>
@@ -12,16 +12,24 @@
1212
<xpath expr="//button[@name='%(stock.action_stock_level_forecast_report_product)d']"
1313
position="after">
1414
<button type="action" name="%(stock.product_open_quants)d"
15-
attrs="{'invisible':[('type', '!=', 'product')]}"
15+
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
1616
class="oe_stat_button" icon="fa-building-o">
1717
<div class="o_form_field o_stat_info">
1818
<field name="immediately_usable_qty"
1919
widget="statinfo" nolabel="1" />
2020
<span class="o_stat_text">Available</span>
2121
</div>
2222
</button>
23+
<button type="action" name="%(stock.product_open_quants)d"
24+
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
25+
class="oe_stat_button" icon="fa-building-o">
26+
<div class="o_form_field o_stat_info">
27+
<field name="potential_qty"
28+
widget="statinfo" nolabel="1"/>
29+
<span class="o_stat_text">Potential</span>
30+
</div>
31+
</button>
2332
</xpath>
2433
</field>
2534
</record>
26-
</data>
27-
</openerp>
35+
</odoo>

stock_available/views/product_template_view.xml

+16-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- © 2014 Numérigraphe, Sodexis
2+
<!-- Copyright 2014 Numérigraphe
3+
Copyright 2016 Sodexis
34
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
45

5-
<openerp>
6-
<data>
6+
<odoo>
77
<record model="ir.ui.view" id="view_stock_available_form">
88
<field name="name">Quantity available to promise (form)</field>
99
<field name="model">product.template</field>
@@ -12,14 +12,23 @@
1212
<xpath expr="//button[@name='%(stock.action_stock_level_forecast_report_template)d']"
1313
position="after">
1414
<button type="object" name="action_open_quants"
15-
attrs="{'invisible':[('type', '!=', 'product')]}"
15+
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
1616
class="oe_stat_button" icon="fa-building-o">
1717
<div class="o_form_field o_stat_info">
1818
<field name="immediately_usable_qty"
1919
widget="statinfo" nolabel="1" />
2020
<span class="o_stat_text">Available</span>
2121
</div>
2222
</button>
23+
<button type="action" name="%(stock.product_open_quants)d"
24+
attrs="{'invisible':[('type', 'not in', ['product','consu'])]}"
25+
class="oe_stat_button" icon="fa-building-o">
26+
<div class="o_form_field o_stat_info">
27+
<field name="potential_qty"
28+
widget="statinfo" nolabel="1"/>
29+
<span class="o_stat_text">Potential</span>
30+
</div>
31+
</button>
2332
</xpath>
2433
</field>
2534
</record>
@@ -29,7 +38,8 @@
2938
<field name="inherit_id" ref="stock.view_stock_product_template_tree"/>
3039
<field name="arch" type="xml">
3140
<tree position="attributes">
32-
<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>
41+
<attribute name="decoration-danger">virtual_available&lt;0 or immediately_usable_qty&lt;0</attribute>
42+
<attribute name="decoration-info">virtual_available&gt;=0 or immediately_usable_qty&gt;0</attribute>
3343
</tree>
3444
<field name="virtual_available" position="after">
3545
<field name="immediately_usable_qty" />
@@ -46,5 +56,4 @@
4656
</ul>
4757
</field>
4858
</record>
49-
</data>
50-
</openerp>
59+
</odoo>

stock_available/views/res_config_view.xml

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<!-- © 2014 Numérigraphe, Sodexis
2+
<!-- Copyright 2014 Numérigraphe
3+
Copyright 2016 Sodexis
34
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
45

5-
<openerp>
6-
<data>
6+
<odoo>
77
<record id="view_stock_configuration" model="ir.ui.view">
88
<field name="name">Stock settings: quantity available to promise</field>
99
<field name="model">stock.config.settings</field>
@@ -35,5 +35,4 @@
3535
</data>
3636
</field>
3737
</record>
38-
</data>
39-
</openerp>
38+
</odoo>

0 commit comments

Comments
 (0)