[ADD] new module 'stock_warehouse_orderpoint_stock_info_unreserved'

This commit is contained in:
Jordi Ballester
2017-05-30 14:43:13 +02:00
committed by ps-tubtim
parent 6d41d7a9b9
commit 15274d0cee
8 changed files with 252 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
======================================
Reordering Rules stock info unreserved
======================================
This modules allows to display the availability of stock on hand and
unreserved on a reordering rule.
Usage
=====
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/153/9.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/stock-logistics-warehouse/issues>`_. In case of
trouble, please check there if your issue has already been reported. If you
spotted it first, help us smashing it by providing a detailed and welcomed
feedback.
Credits
=======
Contributors
------------
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit https://odoo-community.org.

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import models

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Reordering rules stock info unreserved",
"version": "9.0.1.0.0",
"depends": [
"stock_warehouse_orderpoint_stock_info",
"stock_available_unreserved"
],
"author": "Eficent, "
"Odoo Community Association (OCA)",
"website": "http://www.eficent.com",
"category": "Warehouse",
"license": "AGPL-3",
"data": [
"views/stock_warehouse_orderpoint_view.xml",
],
"installable": True,
"auto_install": False,
}

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import stock_warehouse_orderpoint

View File

@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, fields, api
class StockWarehouseOrderpoint(models.Model):
_inherit = 'stock.warehouse.orderpoint'
@api.multi
def _compute_product_available_qty(self):
super(StockWarehouseOrderpoint, self)._compute_product_available_qty()
for rec in self:
product_available = rec.product_id.with_context(
location=rec.location_id.id
)._product_available()[rec.product_id.id]
rec.product_location_qty_available_not_res = \
product_available['qty_available_not_res']
product_location_qty_available_not_res = fields.Float(
string='Quantity On Location (Unreserved)',
compute='_compute_product_available_qty')

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from . import test_stock_warehouse_orderpoint

View File

@@ -0,0 +1,112 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Eficent Business and IT Consulting Services, S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp.tests import common
class TestStockWarehouseOrderpoint(common.TransactionCase):
def setUp(self):
super(TestStockWarehouseOrderpoint, self).setUp()
# Get required Model
self.reordering_rule_model = self.env['stock.warehouse.orderpoint']
self.stock_move_model = self.env['stock.move']
self.product_model = self.env['product.product']
self.product_ctg_model = self.env['product.category']
# Get required Model data
self.product_uom = self.env.ref('product.product_uom_unit')
self.location_stock = self.env.ref('stock.stock_location_stock')
self.location_shelf1 = self.env.ref('stock.stock_location_components')
self.location_customer = self.env.ref('stock.stock_location_customers')
self.location_supplier = self.env.ref('stock.stock_location_suppliers')
# Create product category and product
self.product_ctg = self._create_product_category()
self.product = self._create_product()
# Create Reordering Rule
self.reordering_record = self.create_orderpoint()
def _create_product_category(self):
"""Create a Product Category."""
product_ctg = self.product_ctg_model.create({
'name': 'test_product_ctg',
'type': 'normal',
})
return product_ctg
def _create_product(self):
"""Create a Stockable Product."""
product = self.product_model.create({
'name': 'Test Product',
'categ_id': self.product_ctg.id,
'type': 'product',
'uom_id': self.product_uom.id,
})
return product
def create_orderpoint(self):
"""Create a Reordering rule for the product."""
record = self.reordering_rule_model.create({
'name': 'Reordering Rule',
'product_id': self.product.id,
'product_min_qty': '1',
'product_max_qty': '5',
'qty_multiple': '1',
'location_id': self.location_stock.id,
})
return record
def create_move(self, source_location, destination_location):
move = self.env['stock.move'].create({
'name': 'Test move',
'product_id': self.product.id,
'product_uom': self.product_uom.id,
'product_uom_qty': 10,
'location_id': source_location.id,
'location_dest_id': destination_location.id}
)
move.action_confirm()
return move
def test_product_qty(self):
"""Tests the product quantity in the Reordering rules"""
# Create & process moves to test the product quantity
move_in = self.create_move(self.location_supplier, self.location_stock)
move_out = self.create_move(self.location_stock,
self.location_customer)
self.reordering_record.refresh()
self.assertEqual(self.reordering_record.
product_location_qty_available_not_res,
0.0,
'Quantity On Hand (Unreserved) does not match')
self.assertEqual(self.reordering_record.
product_location_qty_available_not_res,
self.product.qty_available_not_res,
'Quantity On Hand (Unreserved) in the orderpoint '
'does not match with the product.')
move_in.action_done()
self.reordering_record.refresh()
self.assertEqual(self.reordering_record.
product_location_qty_available_not_res,
10.0,
'Quantity On Hand (Unreserved) does not match')
self.assertEqual(self.reordering_record.
product_location_qty_available_not_res,
self.product.qty_available_not_res,
'Quantity On Hand (Unreserved) in the orderpoint '
'does not match with the product.')
move_out.action_assign()
self.reordering_record.refresh()
self.assertEqual(self.reordering_record.
product_location_qty_available_not_res,
0.0,
'Quantity On Hand (Unreserved) does not match')
self.assertEqual(self.reordering_record.
product_location_qty_available_not_res,
self.product.qty_available_not_res,
'Quantity On Hand (Unreserved) in the orderpoint '
'does not match with the product.')

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="stock_warehouse_orderpoint_tree_view">
<field name="name">stock.warehouse.orderpoint.tree</field>
<field name="model">stock.warehouse.orderpoint</field>
<field name="inherit_id"
ref="stock_warehouse_orderpoint_stock_info.stock_warehouse_orderpoint_tree_view" />
<field name="arch" type="xml">
<field name="product_location_qty" position="after">
<field name="product_location_qty_available_not_res" />
</field>
</field>
</record>
<record model="ir.ui.view" id="stock_warehouse_orderpoint_form_view">
<field name="name">stock.warehouse.orderpoint.form</field>
<field name="model">stock.warehouse.orderpoint</field>
<field name="inherit_id"
ref="stock_warehouse_orderpoint_stock_info.stock_warehouse_orderpoint_form_view" />
<field name="arch" type="xml">
<field name="product_location_qty" position="after">
<field name="product_location_qty_available_not_res" />
</field>
</field>
</record>
</data>
</openerp>