mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] stock_change_qty_reason: Migration to 13.0
This commit is contained in:
committed by
GuillemCForgeFlow
parent
82cf7c8244
commit
55bd1cd717
@@ -14,20 +14,19 @@ Stock Change Quantity Reason
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
|
||||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_change_qty_reason
|
||||
:target: https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_change_qty_reason
|
||||
:alt: OCA/stock-logistics-warehouse
|
||||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_change_qty_reason
|
||||
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_change_qty_reason
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/153/12.0
|
||||
:target: https://runbot.odoo-community.org/runbot/153/13.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
This module extends the product stock management and allows to set a reason
|
||||
in the wizard when changing the product quantity or in inventory adjustments
|
||||
per line.
|
||||
in inventory adjustments globally or per line.
|
||||
|
||||
It also can manage preset reasons optionally.
|
||||
|
||||
@@ -55,13 +54,18 @@ To allow an Stock Manager configure preset reasons easily, you should:
|
||||
- Enable: Technical Settings > Manage Stock Change Qty Preset Reasons
|
||||
- Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
* Add a reason from Update Quantity button in Product Form View has been removed. This button no longer opens an Inventory Adjustment, it opens directly the stock quant view. Therefore, it must be decided how to implement the logic to add a reason when quantity is updated.
|
||||
|
||||
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 <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_change_qty_reason%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_change_qty_reason%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||
|
||||
Do not contact contributors directly about support or help with technical issues.
|
||||
|
||||
@@ -79,7 +83,7 @@ Contributors
|
||||
* Denis Roussel <denis.roussel@acsone.eu>
|
||||
* Meyomesse Gilles <meyomesse.gilles@gmail.com>
|
||||
* Andreas Dian S.P <andreasdian777@gmail.com>
|
||||
* Héctor Villarreal <hector.villarreal@eficent.com>
|
||||
* Héctor Villarreal <hector.villarreal@forgeflow.com>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
@@ -94,6 +98,6 @@ 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.
|
||||
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_change_qty_reason>`_ project on GitHub.
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_change_qty_reason>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# Copyright 2019 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
{
|
||||
"name": "Stock Change Quantity Reason",
|
||||
@@ -8,7 +8,7 @@
|
||||
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"category": "Warehouse Management",
|
||||
"version": "12.0.1.0.0",
|
||||
"version": "13.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"depends": ["stock"],
|
||||
"data": [
|
||||
@@ -18,7 +18,6 @@
|
||||
"views/stock_inventory_line_reason_view.xml",
|
||||
"views/stock_inventory_line_view.xml",
|
||||
"views/stock_inventory_view.xml",
|
||||
"wizard/stock_product_change_qty.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# Copyright 2019 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# Copyright 2019 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import api, fields, models
|
||||
|
||||
@@ -20,10 +20,16 @@ class StockInventory(models.Model):
|
||||
|
||||
@api.onchange("reason")
|
||||
def onchange_reason(self):
|
||||
for line in self.line_ids:
|
||||
line_ids = self.line_ids
|
||||
if not isinstance(self.id, int):
|
||||
line_ids = self.browse(self.id.origin).line_ids
|
||||
for line in line_ids:
|
||||
line.reason = self.reason
|
||||
|
||||
@api.onchange("preset_reason_id")
|
||||
def onchange_preset_reason(self):
|
||||
for line in self.line_ids:
|
||||
line_ids = self.line_ids
|
||||
if not isinstance(self.id, int):
|
||||
line_ids = self.browse(self.id.origin).line_ids
|
||||
for line in line_ids:
|
||||
line.preset_reason_id = self.preset_reason_id
|
||||
|
||||
@@ -18,9 +18,7 @@ class StockInventoryLine(models.Model):
|
||||
qty, location_id, location_dest_id, out
|
||||
)
|
||||
context = (
|
||||
self.env.context.get("change_quantity_reason", False) or self.reason
|
||||
if not self.preset_reason_id
|
||||
else self.preset_reason_id.name
|
||||
self.reason if not self.preset_reason_id else self.preset_reason_id.name
|
||||
)
|
||||
if res.get("origin"):
|
||||
res["origin"] = " ,".join([res.get("origin"), context])
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# Copyright 2019 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services, S.L.
|
||||
# Copyright 2019 ForgeFlow S.L.
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
* Denis Roussel <denis.roussel@acsone.eu>
|
||||
* Meyomesse Gilles <meyomesse.gilles@gmail.com>
|
||||
* Andreas Dian S.P <andreasdian777@gmail.com>
|
||||
* Héctor Villarreal <hector.villarreal@eficent.com>
|
||||
* Héctor Villarreal <hector.villarreal@forgeflow.com>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
This module extends the product stock management and allows to set a reason
|
||||
in the wizard when changing the product quantity or in inventory adjustments
|
||||
per line.
|
||||
in inventory adjustments globally or per line.
|
||||
|
||||
It also can manage preset reasons optionally.
|
||||
|
||||
1
stock_change_qty_reason/readme/ROADMAP.rst
Normal file
1
stock_change_qty_reason/readme/ROADMAP.rst
Normal file
@@ -0,0 +1 @@
|
||||
* Add a reason from Update Quantity button in Product Form View has been removed. This button no longer opens an Inventory Adjustment, it opens directly the stock quant view. Therefore, it must be decided how to implement the logic to add a reason when quantity is updated.
|
||||
@@ -367,20 +367,20 @@ ul.auto-toc {
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_change_qty_reason"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-12-0/stock-logistics-warehouse-12-0-stock_change_qty_reason"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/153/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_change_qty_reason"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_change_qty_reason"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/153/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module extends the product stock management and allows to set a reason
|
||||
in the wizard when changing the product quantity or in inventory adjustments
|
||||
per line.</p>
|
||||
in inventory adjustments globally or per line.</p>
|
||||
<p>It also can manage preset reasons optionally.</p>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#configuration" id="id1">Configuration</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id2">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id3">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id4">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id5">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id6">Maintainers</a></li>
|
||||
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
@@ -402,39 +402,45 @@ products change quantity.</p>
|
||||
<li>Go to Inventory > Configuration > Inventory Adjustment > Change Qty Reasons</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="known-issues-roadmap">
|
||||
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
|
||||
<ul class="simple">
|
||||
<li>Add a reason from Update Quantity button in Product Form View has been removed. This button no longer opens an Inventory Adjustment, it opens directly the stock quant view. Therefore, it must be decided how to implement the logic to add a reason when quantity is updated.</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
|
||||
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
|
||||
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
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_change_qty_reason%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_change_qty_reason%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id3">Credits</a></h1>
|
||||
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id4">Authors</a></h2>
|
||||
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>ACSONE SA/NV</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id5">Contributors</a></h2>
|
||||
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Denis Roussel <<a class="reference external" href="mailto:denis.roussel@acsone.eu">denis.roussel@acsone.eu</a>></li>
|
||||
<li>Meyomesse Gilles <<a class="reference external" href="mailto:meyomesse.gilles@gmail.com">meyomesse.gilles@gmail.com</a>></li>
|
||||
<li>Andreas Dian S.P <<a class="reference external" href="mailto:andreasdian777@gmail.com">andreasdian777@gmail.com</a>></li>
|
||||
<li>Héctor Villarreal <<a class="reference external" href="mailto:hector.villarreal@eficent.com">hector.villarreal@eficent.com</a>></li>
|
||||
<li>Héctor Villarreal <<a class="reference external" href="mailto:hector.villarreal@forgeflow.com">hector.villarreal@forgeflow.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
|
||||
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>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.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/12.0/stock_change_qty_reason">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_change_qty_reason">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# pylint: disable=import-error,protected-access,too-few-public-methods
|
||||
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# Copyright 2019 ForgeFlow S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo.tests.common import SavepointCase
|
||||
@@ -27,89 +27,46 @@ class TestStockQuantityChangeReason(SavepointCase):
|
||||
{"name": name, "categ_id": self.category.id, "type": "product"}
|
||||
)
|
||||
|
||||
def _product_change_qty(self, product, new_qty, reason, preset_reason_id=None):
|
||||
values = {"product_id": product.id, "new_quantity": new_qty, "reason": reason}
|
||||
if preset_reason_id:
|
||||
values.update({"preset_reason_id": preset_reason_id.id})
|
||||
def _product_change_qty(self, product, new_qty):
|
||||
values = {
|
||||
"product_tmpl_id": product.product_tmpl_id.id,
|
||||
"product_id": product.id,
|
||||
"new_quantity": new_qty,
|
||||
}
|
||||
wizard = self.wizard_model.create(values)
|
||||
wizard.change_product_qty()
|
||||
|
||||
def _create_reason(self, name, description=None):
|
||||
return self.preset_reason_id.create({"name": name, "description": description})
|
||||
|
||||
def test_product_change_qty(self):
|
||||
""" Check product quantity update move reason is well set
|
||||
"""
|
||||
|
||||
# create products
|
||||
product2 = self._create_product("product_product_2")
|
||||
product3 = self._create_product("product_product_3")
|
||||
product4 = self._create_product("product_product_4")
|
||||
product5 = self._create_product("product_product_5")
|
||||
product6 = self._create_product("product_product_6")
|
||||
|
||||
# update qty on hand and add reason
|
||||
self._product_change_qty(product2, 10, "product_2_reason")
|
||||
self._product_change_qty(product3, 0, "product_3_reason")
|
||||
self._product_change_qty(product4, 0, "product_4_reason")
|
||||
self._product_change_qty(product5, 10, "product_5_reason")
|
||||
self._product_change_qty(product6, 0, "product_6_reason")
|
||||
|
||||
# check stock moves created
|
||||
move2 = self.stock_move.search([("product_id", "=", product2.id)])
|
||||
move3 = self.stock_move.search([("product_id", "=", product3.id)])
|
||||
move4 = self.stock_move.search([("product_id", "=", product4.id)])
|
||||
move5 = self.stock_move.search([("product_id", "=", product5.id)])
|
||||
move6 = self.stock_move.search([("product_id", "=", product6.id)])
|
||||
|
||||
self.assertEqual(move2.origin, "product_2_reason")
|
||||
self.assertFalse(move3)
|
||||
self.assertFalse(move4)
|
||||
self.assertEqual(move5.origin, "product_5_reason")
|
||||
self.assertFalse(move6)
|
||||
|
||||
def test_product_change_qty_with_preset_reason(self):
|
||||
""" Check product quantity update move reason is well set
|
||||
"""
|
||||
# create reason
|
||||
reason = self._create_reason("Test", "Description Test")
|
||||
# create products
|
||||
product2 = self._create_product("product_product_2")
|
||||
product3 = self._create_product("product_product_3")
|
||||
|
||||
# update qty on hand and add reason
|
||||
self._product_change_qty(product2, 10, reason.name, reason)
|
||||
self._product_change_qty(product3, 0, reason.name, reason)
|
||||
|
||||
# check stock moves created
|
||||
move2 = self.stock_move.search([("product_id", "=", product2.id)])
|
||||
move3 = self.stock_move.search([("product_id", "=", product3.id)])
|
||||
# asserts
|
||||
self.assertEqual(move2.origin, reason.name)
|
||||
self.assertEqual(move2.preset_reason_id, reason)
|
||||
self.assertFalse(move3)
|
||||
|
||||
def test_inventory_adjustment_onchange_reason_preset_reason(self):
|
||||
""" Check that adding a reason or a preset reason explode to lines
|
||||
"""
|
||||
product2 = self._create_product("product_product_2")
|
||||
self._product_change_qty(product2, 50, "product_2_reason")
|
||||
self._product_change_qty(product2, 50)
|
||||
inventory = self.env["stock.inventory"].create(
|
||||
{
|
||||
"name": "remove product2",
|
||||
"filter": "product",
|
||||
"location_id": self.stock_location.id,
|
||||
"product_id": product2.id,
|
||||
"product_ids": [(4, product2.id)],
|
||||
"location_ids": [(4, self.stock_location.id)],
|
||||
}
|
||||
)
|
||||
inventory.preset_reason_id = self._create_reason("Test 1", "Description Test 1")
|
||||
inventory.action_start()
|
||||
self.assertEqual(len(inventory.line_ids), 1)
|
||||
inventory.reason = "Reason 2"
|
||||
inventory.onchange_reason()
|
||||
self.assertEquals(inventory.line_ids.reason, inventory.reason)
|
||||
inventory.preset_reason_id = self._create_reason("Test 2", "Description Test 2")
|
||||
inventory.onchange_preset_reason()
|
||||
self.assertEquals(
|
||||
inventory.line_ids.preset_reason_id, inventory.preset_reason_id
|
||||
)
|
||||
inventory.reason = "Reason 2"
|
||||
inventory.onchange_reason()
|
||||
self.assertEquals(inventory.line_ids.reason, inventory.reason)
|
||||
inventory.line_ids[0].write({"product_qty": 10})
|
||||
inventory.action_validate()
|
||||
move = self.stock_move.search(
|
||||
[("product_id", "=", product2.id), ("preset_reason_id", "!=", False)]
|
||||
)
|
||||
self.assertEqual(len(move), 1)
|
||||
self.assertEqual(move.origin, inventory.preset_reason_id.name)
|
||||
self.assertEqual(move.preset_reason_id, inventory.preset_reason_id)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
<!-- Copyright 2019 ForgeFlow S.L.
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
<!-- Copyright 2019 ForgeFlow S.L.
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
<record id="view_preset_reason" model="ir.ui.view">
|
||||
@@ -30,7 +30,6 @@
|
||||
<field name="name">Change Qty Reasons</field>
|
||||
<field name="res_model">stock.inventory.line.reason</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">list,form</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -46,33 +46,4 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_inventory_form" model="ir.ui.view">
|
||||
<field name="name">stock.inventory.form.inherit</field>
|
||||
<field name="model">stock.inventory</field>
|
||||
<field name="inherit_id" ref="stock.view_inventory_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='line_ids']/tree/field[@name='location_id']" position="after">
|
||||
<field name="reason"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='line_ids']/kanban/field[@name='location_id']" position="after">
|
||||
<field name="reason"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_inventory_form_reason_id" model="ir.ui.view">
|
||||
<field name="name">stock.inventory.form.inherit.reason.code</field>
|
||||
<field name="model">stock.inventory</field>
|
||||
<field name="inherit_id" ref="view_inventory_form"/>
|
||||
<field name="groups_id" eval="[(4, ref('stock_change_qty_reason.group_qty_reason_preset'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='line_ids']/tree/field[@name='reason']" position="replace">
|
||||
<field name="preset_reason_id"/>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='line_ids']/kanban/field[@name='reason']" position="replace">
|
||||
<field name="preset_reason_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
<!-- Copyright 2019 ForgeFlow S.L.
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
<record id="reason_stock_inventory_form_inherit" model="ir.ui.view">
|
||||
@@ -7,7 +7,7 @@
|
||||
<field name="model">stock.inventory</field>
|
||||
<field name="inherit_id" ref="stock.view_inventory_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="date" position="after">
|
||||
<field name="company_id" position="after">
|
||||
<field name="reason"/>
|
||||
</field>
|
||||
</field>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/license
|
||||
|
||||
from . import stock_change_product_qty
|
||||
@@ -1,39 +0,0 @@
|
||||
# Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockChangeProductQty(models.TransientModel):
|
||||
"""Class to inherit model stock.change.product.qty"""
|
||||
|
||||
_inherit = "stock.change.product.qty"
|
||||
|
||||
reason = fields.Char(help="Type in a reason for the " "product quantity change")
|
||||
preset_reason_id = fields.Many2one("stock.inventory.line.reason")
|
||||
|
||||
@api.multi
|
||||
def change_product_qty(self):
|
||||
"""Function to super change_product_qty"""
|
||||
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()
|
||||
|
||||
def _action_start_line(self):
|
||||
res = super(StockChangeProductQty, self)._action_start_line()
|
||||
if self.preset_reason_id:
|
||||
res.update(
|
||||
{
|
||||
"preset_reason_id": self.preset_reason_id.id,
|
||||
"reason": self.preset_reason_id.name,
|
||||
}
|
||||
)
|
||||
elif self.reason:
|
||||
res.update({"reason": self.reason})
|
||||
return res
|
||||
|
||||
@api.onchange("preset_reason_id")
|
||||
def onchange_preset_reason_id(self):
|
||||
if self.preset_reason_id:
|
||||
self.reason = self.preset_reason_id.name
|
||||
@@ -1,31 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright 2016-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
Copyright 2019 Eficent Business and IT Consulting Services S.L.
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
|
||||
<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"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_change_product_quantity_reason_id" 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="view_change_product_quantity_reason"/>
|
||||
<field name="groups_id" eval="[(4, ref('stock_change_qty_reason.group_qty_reason_preset'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="reason" position="replace">
|
||||
<field name="preset_reason_id" required="True"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user