[14.0][MIG] - stock_available_unreserved

This commit is contained in:
sbejaoui
2021-06-03 17:55:13 +02:00
parent ddaeaffe4b
commit 0affe055f6
10 changed files with 62 additions and 50 deletions

View File

@@ -0,0 +1 @@
../../../../stock_available_unreserved

View File

@@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@@ -5,7 +5,7 @@
{
"name": "Stock Available Unreserved",
"summary": "Quantity of stock available for immediate use",
"version": "13.0.1.0.1",
"version": "14.0.1.0.1",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"development_status": "Production/Stable",
"maintainers": ["LoisRForgeFlow"],

View File

@@ -1,2 +1,3 @@
from . import product
from . import quant
from . import product_template
from . import product_product
from . import stock_quant

View File

@@ -9,45 +9,6 @@ from odoo.tools.float_utils import float_round
from odoo.addons.stock.models.product import OPERATORS
class ProductTemplate(models.Model):
_inherit = "product.template"
qty_available_not_res = fields.Float(
string="Quantity On Hand Unreserved",
digits="Product Unit of Measure",
compute="_compute_product_available_not_res",
search="_search_quantity_unreserved",
)
@api.depends("product_variant_ids.qty_available_not_res")
def _compute_product_available_not_res(self):
for tmpl in self:
if isinstance(tmpl.id, models.NewId):
continue
tmpl.qty_available_not_res = sum(
tmpl.mapped("product_variant_ids.qty_available_not_res")
)
def action_open_quants_unreserved(self):
products_ids = self.mapped("product_variant_ids").ids
quants = self.env["stock.quant"].search([("product_id", "in", products_ids)])
quant_ids = quants.filtered(
lambda x: x.product_id.qty_available_not_res > 0
).ids
result = self.env.ref("stock.product_template_open_quants").read()[0]
result["domain"] = [("id", "in", quant_ids)]
result["context"] = {
"search_default_locationgroup": 1,
"search_default_internal_loc": 1,
}
return result
def _search_quantity_unreserved(self, operator, value):
domain = [("qty_available_not_res", operator, value)]
product_variant_ids = self.env["product.product"].search(domain)
return [("product_variant_ids", "in", product_variant_ids.ids)]
class ProductProduct(models.Model):
_inherit = "product.product"

View File

@@ -0,0 +1,42 @@
# Copyright 2018 Camptocamp SA
# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import api, fields, models
class ProductTemplate(models.Model):
_inherit = "product.template"
qty_available_not_res = fields.Float(
string="Quantity On Hand Unreserved",
digits="Product Unit of Measure",
compute="_compute_product_available_not_res",
search="_search_quantity_unreserved",
)
@api.depends("product_variant_ids.qty_available_not_res")
def _compute_product_available_not_res(self):
for tmpl in self:
if isinstance(tmpl.id, models.NewId):
continue
tmpl.qty_available_not_res = sum(
tmpl.mapped("product_variant_ids.qty_available_not_res")
)
def action_open_quants_unreserved(self):
products_ids = self.mapped("product_variant_ids").ids
quants = self.env["stock.quant"].search([("product_id", "in", products_ids)])
quant_ids = quants.filtered(
lambda x: x.product_id.qty_available_not_res > 0
).ids
result = self.env.ref("stock.group_stock_multi_locations").read()[0]
result["domain"] = [("id", "in", quant_ids)]
result["context"] = {
"search_default_locationgroup": 1,
"search_default_internal_loc": 1,
}
return result
def _search_quantity_unreserved(self, operator, value):
return [("product_variant_ids.qty_available_not_res", operator, value)]

View File

@@ -3,3 +3,4 @@
* Mykhailo Panarin <m.panarin@mobilunity.com>
* Atte Isopuro <atte.isopuro@avoin.systems>
* Lois Rilo <lois.rilo@forgeflow.com>
* Souheil Bejaoui <souheil.bejaoui@acsone.eu>

View File

@@ -163,8 +163,8 @@ class TestStockLogisticsWarehouse(SavepointCase):
self.compare_qty_available_not_res(self.productA, 2)
self.compare_qty_available_not_res(self.templateAB, 2)
# will directly trigger action_done on self.productB
self.pickingInB.action_done()
# will directly trigger button_validate on self.productB
self.pickingInB.button_validate()
self.compare_qty_available_not_res(self.productA, 2)
self.compare_qty_available_not_res(self.productB, 3)
self.compare_qty_available_not_res(self.templateAB, 5)
@@ -180,7 +180,7 @@ class TestStockLogisticsWarehouse(SavepointCase):
self.compare_qty_available_not_res(self.productB, 1)
self.compare_qty_available_not_res(self.templateAB, 3)
self.pickingOutA.action_done()
self.pickingOutA.button_validate()
self.compare_qty_available_not_res(self.productB, 1)
self.compare_qty_available_not_res(self.templateAB, 3)
@@ -334,7 +334,7 @@ class TestStockLogisticsWarehouse(SavepointCase):
self.check_template_found_correctly("<=", 0, self.templateAB)
self.check_template_found_correctly("<=", -1, no_template)
self.pickingInB.action_done()
self.pickingInB.button_validate()
# product A has 2 unreserved, product B has 3 unreserved and
# the remaining variant has 0

View File

@@ -29,11 +29,11 @@
<field name="model">product.template</field>
<field name="inherit_id" ref="stock.product_template_kanban_stock_view" />
<field name="arch" type="xml">
<ul position="inside">
<li t-if="record.type.raw_value == 'product'">Unreserved: <field
<xpath expr="//field[@name='qty_available']/parent::div" position="after">
<div t-if="record.type.raw_value == 'product'">Unreserved: <field
name="qty_available_not_res"
/> <field name="uom_id" /></li>
</ul>
/> <field name="uom_id" /></div>
</xpath>
</field>
</record>
<record id="view_stock_product_tree" model="ir.ui.view">