Skip to content

Commit

Permalink
[MIG] stock_request_submit: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed May 15, 2024
1 parent 709b2ce commit 03cd63c
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 27 deletions.
3 changes: 3 additions & 0 deletions stock_request_submit/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Contributors

- Héctor Villarreal Ortega <hector.villarreal@eficent.com>
- Pimolnat Suntian <pimolnats@ecosoft.co.th>
- `APSL-Nagarro <https://www.apsl.tech>`__:

- Antoni Marroig <amarroig@apsl.net>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion stock_request_submit/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Stock Request Submit",
"summary": "Add submit state on Stock Requests",
"version": "16.0.1.0.0",
"version": "17.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-request",
"author": "Open Source Integrators, Odoo Community Association (OCA)",
Expand Down
4 changes: 1 addition & 3 deletions stock_request_submit/hooks.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Copyright 2019-2020 ForgeFlow S.L. (https://www.forgeflow.com)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import SUPERUSER_ID, api


def uninstall_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
def uninstall_hook(env):
sr = env["stock.request"].search([("state", "=", "submitted")])
sr.write({"state": "draft"})
sro = env["stock.request.order"].search([("state", "=", "submitted")])
Expand Down
4 changes: 1 addition & 3 deletions stock_request_submit/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class StockRequest(models.Model):

state = fields.Selection(selection_add=[("submitted", "Submitted"), ("open",)])

route_id = fields.Many2one(
states={"draft": [("readonly", False)], "submitted": [("readonly", False)]}
)
route_id = fields.Many2one()

def action_submit(self):
self._action_submit()
Expand Down
2 changes: 2 additions & 0 deletions stock_request_submit/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
- Urvisha Desai \<<udesai@opensourceintegrators.com>\>
- Héctor Villarreal Ortega \<<hector.villarreal@eficent.com>\>
- Pimolnat Suntian \<<pimolnats@ecosoft.co.th>\>
- [APSL-Nagarro](https://www.apsl.tech):
- Antoni Marroig \<<amarroig@apsl.net>\>
4 changes: 4 additions & 0 deletions stock_request_submit/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
</li>
<li>Héctor Villarreal Ortega &lt;<a class="reference external" href="mailto:hector.villarreal&#64;eficent.com">hector.villarreal&#64;eficent.com</a>&gt;</li>
<li>Pimolnat Suntian &lt;<a class="reference external" href="mailto:pimolnats&#64;ecosoft.co.th">pimolnats&#64;ecosoft.co.th</a>&gt;</li>
<li><a class="reference external" href="https://www.apsl.tech">APSL-Nagarro</a>:<ul>
<li>Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
53 changes: 49 additions & 4 deletions stock_request_submit/tests/test_stock_request_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0).

from odoo import fields

from odoo.addons.stock_request.tests.test_stock_request import TestStockRequest
from odoo.tests import common, new_test_user

from ..hooks import uninstall_hook


class TestStockRequestSubmit(TestStockRequest):
class TestStockRequestSubmit(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.main_company = cls.env.ref("base.main_company")
cls.company_2 = cls.env["res.company"].create(
{"name": "Company2", "parent_id": cls.main_company.id}
)
cls.route = cls._create_location_route(
name="Transfer", company_id=cls.main_company.id
)
cls.product = cls._create_product("SH", "Shoes", False)
cls.product.route_ids = [(6, 0, cls.route.ids)]
cls.warehouse = cls.env.ref("stock.warehouse0")
vals = {
"company_id": cls.main_company.id,
"warehouse_id": cls.warehouse.id,
Expand All @@ -34,9 +42,46 @@ def setUpClass(cls):
)
],
}
cls.request_order = cls.env["stock.request.order"]
cls.stock_request_user = new_test_user(
cls.env,
login="stock_request_user2",
groups="stock_request.group_stock_request_user",
company_ids=[(6, 0, [cls.main_company.id, cls.company_2.id])],
)
cls.stock_request_manager = new_test_user(
cls.env,
login="stock_request_manager",
groups="stock_request.group_stock_request_manager",
company_ids=[(6, 0, [cls.main_company.id, cls.company_2.id])],
)
cls.order = cls.request_order.with_user(cls.stock_request_user).create(vals)
cls.stock_request = cls.order.stock_request_ids

@classmethod
def _create_location_route(self, **vals):
return self.env["stock.route"].create(
dict(
product_categ_selectable=False,
product_selectable=True,
sequence=10,
**vals,
)
)

@classmethod
def _create_product(self, default_code, name, company_id, **vals):
return self.env["product.product"].create(
dict(
name=name,
default_code=default_code,
uom_id=self.env.ref("uom.product_uom_unit").id,
company_id=company_id,
detailed_type="product",
**vals,
)
)

def test_stock_request_submit(self):
self.order.action_submit()
self.assertEqual(self.order.state, "submitted")
Expand All @@ -52,7 +97,7 @@ def test_uninstall_hook(self):
self.assertEqual(self.stock_request.state, "submitted")

# Uninstall this module
uninstall_hook(self.cr, self.registry)
uninstall_hook(self.env)

# Check state after uninstall
self.assertEqual(self.order.state, "draft")
Expand Down
22 changes: 12 additions & 10 deletions stock_request_submit/views/stock_request_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,31 @@
name="action_submit"
string="Submit"
type="object"
attrs="{'invisible': [('state', '!=', 'draft')]}"
invisible="state != 'draft'"
/>
</button>
<button name="action_confirm" position="attributes">
<attribute
name="attrs"
>{'invisible': [('state', '!=', 'submitted')]}</attribute>
<attribute name="invisible">state != 'submitted'</attribute>
</button>
<button name="action_draft" position="attributes">
<attribute name="states">submitted,cancel</attribute>
<attribute
name="invisible"
>state not in ['submitted', 'cancel']</attribute>
</button>
<button name="action_cancel" position="attributes">
<attribute name="states">draft,submitted,open</attribute>
<attribute
name="invisible"
>state not in ['draft', 'submitted', 'open']</attribute>
</button>
<field name="stock_request_ids" position="attributes">
<attribute
name="attrs"
>{'readonly': [('state', 'not in', ['draft', 'submitted'])]}</attribute>
name="readonly"
>state not in ['draft', 'submitted']</attribute>
</field>
<field name="route_id" position="attributes">
<attribute
name="attrs"
>{'readonly': [('state', 'not in', ['draft', 'submitted'])]}</attribute>
name="readonly"
>state not in ['draft', 'submitted']</attribute>
</field>
</field>
</record>
Expand Down
14 changes: 8 additions & 6 deletions stock_request_submit/views/stock_request_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@
name="action_submit"
string="Submit"
type="object"
attrs="{'invisible': [('state', '!=', 'draft')]}"
invisible="state != 'draft'"
/>
</button>
<button name="action_confirm" position="attributes">
<attribute
name="attrs"
>{'invisible': [('state', '!=', 'submitted')]}</attribute>
<attribute name="invisible">state != 'submitted'</attribute>
</button>
<button name="action_draft" position="attributes">
<attribute name="states">submitted,cancel</attribute>
<attribute
name="invisible"
>state not in ['submitted', 'cancel']</attribute>
</button>
<button name="action_cancel" position="attributes">
<attribute name="states">draft,submitted,open</attribute>
<attribute
name="invisible"
>state not in ['draft', 'submitted', 'open']</attribute>
</button>
</field>
</record>
Expand Down

0 comments on commit 03cd63c

Please sign in to comment.