Add new module to manage change product quantity reason

This commit is contained in:
Denis Roussel
2016-05-24 14:15:48 +02:00
committed by GuillemCForgeFlow
parent 2bf21d0b22
commit a7ce11509a
10 changed files with 189 additions and 0 deletions

View File

@@ -0,0 +1,47 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License: AGPL-3
Stock Change Quantity Reason
============================
This module extends the product stock management and allows to set a reason
in the wizard when changing the product quantity.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/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
`here <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_change_qty_reason%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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/167/8.0
Credits
=======
Contributors
------------
* Denis Roussel <denis.roussel@acsone.eu>
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,3 @@
# -*- coding: utf-8 -*-
from . import models
from . import wizard

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': "Stock Change Quantity Reason",
'summary': """
Stock Quantity Change Reason """,
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
'website': "http://acsone.eu",
'category': 'Warehouse Management',
'version': '8.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'stock',
],
'data': [
'wizard/stock_product_change_qty.xml'
],
}

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import stock

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, api
class StockInventoryLine(models.Model):
_inherit = "stock.inventory.line"
@api.model
def _resolve_inventory_line(self, inventory_line):
move_id = super(StockInventoryLine,
self)._resolve_inventory_line(inventory_line)
reason = self.env.context.get('change_quantity_reason', False)
if reason and move_id:
move = self.env['stock.move'].browse(move_id)
if move.origin:
move.origin = ' ,'.join([move.origin, reason])
else:
move.origin = reason
return move_id

View File

@@ -0,0 +1,2 @@
# -*- coding: utf-8 -*-
from . import test_stock_change_qty_reason

View File

@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# © 2016 Denis Roussel, Acsone SA/NV (http://www.acsone.eu)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import openerp.tests.common as common
class TestStockQuantityChangeReason(common.TransactionCase):
def _product_change_qty(self, product, new_qty, reason):
wizard_model = self.env['stock.change.product.qty']
wizard = wizard_model.create({'product_id': product.id,
'new_quantity': new_qty,
'reason': reason})
wizard.change_product_qty()
def test_product_change_qty(self):
""" Check product quantity update move reason is well set
"""
# set product in each period
product2 = self.env.ref('product.product_product_37')
product3 = self.env.ref('product.product_product_38')
product4 = self.env.ref('product.product_product_39')
product5 = self.env.ref('product.product_product_40')
product6 = self.env.ref('product.product_product_41')
self._product_change_qty(product2, 10, 'product_37_reason')
self._product_change_qty(product3, 0, 'product_38_reason')
self._product_change_qty(product4, 0, 'product_39_reason')
self._product_change_qty(product5, 10, 'product_40_reason')
self._product_change_qty(product6, 0, 'product_41_reason')
move2 = self.env['stock.move'].search([('product_id', '=',
product2.id)], limit=1,
order='id desc')
move3 = self.env['stock.move'].search([('product_id', '=',
product3.id)],
limit=1, order='id desc')
move4 = self.env['stock.move'].search([('product_id', '=',
product4.id)],
limit=1, order='id desc')
move5 = self.env['stock.move'].search([('product_id', '=',
product5.id)],
limit=1, order='id desc')
move6 = self.env['stock.move'].search([('product_id', '=',
product6.id)],
limit=1, order='id desc')
self.assertEqual(move2.origin, 'product_37_reason')
self.assertFalse(move3)
self.assertFalse(move4)
self.assertEqual(move5.origin, 'product_40_reason')
self.assertFalse(move6)

View File

@@ -0,0 +1 @@
from . import stock_change_product_qty

View File

@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api
class StockChangeProductQty(models.TransientModel):
_inherit = 'stock.change.product.qty'
reason = fields.Char('Reason',
help='Type in a reason for the '
'product quantity change')
@api.multi
def change_product_qty(self):
if self.reason:
this = self.with_context(change_quantity_reason=self.reason)
return super(StockChangeProductQty, this).change_product_qty()
return super(StockChangeProductQty, self).change_product_qty()

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_change_product_quantity_reason" model="ir.ui.view">
<field name="name">Change Product Quantity Reason</field>
<field name="model">stock.change.product.qty</field>
<field name="inherit_id" ref="stock.view_change_product_quantity"/>
<field name="arch" type="xml">
<field name="new_quantity" position="after">
<field name="reason" attrs="{'required':True}"/>
</field>
</field>
</record>
</data>
</openerp>