Skip to content

Commit

Permalink
[MIG] stock_request_picking_type: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
peluko00 committed May 16, 2024
1 parent 2f705fd commit 05cc872
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 201 deletions.
4 changes: 3 additions & 1 deletion stock_request_picking_type/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Stock Request Picking Type
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d1fd32d3de59cc5caa70018b4d2a579ee2af8c28c01a8e896149243576a14abf
!! source digest: sha256:ee201635a3febbcba6e6023c0a23b866ec29c66e143a839b7bd41970e6a2ce46
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -66,6 +66,8 @@ Contributors
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
* Raphael Lee <rlee@opensourceintegrators.com>
* [APSL-Nagarro](https://apsl.tech):
* Antoni Marroig <amarroig@apsl.net>

Maintainers
~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion stock_request_picking_type/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"name": "Stock Request Picking Type",
"summary": "Add Stock Requests to the Inventory App",
"version": "14.0.1.1.0",
"version": "16.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
16 changes: 0 additions & 16 deletions stock_request_picking_type/migrations/12.0.2.0.0/post-migration.py

This file was deleted.

49 changes: 19 additions & 30 deletions stock_request_picking_type/models/stock_request_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,32 @@
class StockRequestOrder(models.Model):
_inherit = "stock.request.order"

@api.model
def _get_default_picking_type(self):
companies = self._context.get("allowed_company_ids", []).copy()
companies.append(False)
return (
self.env["stock.picking.type"]
.search(
[
("code", "=", "stock_request_order"),
"|",
("warehouse_id.company_id", "in", companies),
("warehouse_id", "=", False),
],
limit=1,
)
.id
)

picking_type_id = fields.Many2one(
comodel_name="stock.picking.type",
string="Operation Type",
default=_get_default_picking_type,
compute="_compute_picking_type_id",
required=True,
store=True,
)

@api.onchange("warehouse_id")
def onchange_warehouse_picking_id(self):
if self.warehouse_id:
picking_type_id = self.env["stock.picking.type"].search(
[
("code", "=", "stock_request_order"),
("warehouse_id", "=", self.warehouse_id.id),
],
limit=1,
@api.depends("warehouse_id")
def _compute_picking_type_id(self):
companies = self.env.context.get("allowed_company_ids", []).copy()
companies.append(False)
for order in self:
order.picking_type_id = (
self.env["stock.picking.type"]
.search(
[
("code", "=", "stock_request_order"),
"|",
("warehouse_id.company_id", "in", companies),
("warehouse_id", "=", self.warehouse_id.id or False),
],
limit=1,
)
.id
)
if picking_type_id:
self._origin.write({"picking_type_id": picking_type_id.id})

@api.model
def create(self, vals):
Expand Down
2 changes: 2 additions & 0 deletions stock_request_picking_type/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
* Pimolnat Suntian <pimolnats@ecosoft.co.th>
* Raphael Lee <rlee@opensourceintegrators.com>
* [APSL-Nagarro](https://apsl.tech):
* Antoni Marroig <amarroig@apsl.net>
4 changes: 3 additions & 1 deletion stock_request_picking_type/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Stock Request Picking Type</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:d1fd32d3de59cc5caa70018b4d2a579ee2af8c28c01a8e896149243576a14abf
!! source digest: sha256:ee201635a3febbcba6e6023c0a23b866ec29c66e143a839b7bd41970e6a2ce46
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" 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 image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/stock-logistics-request/tree/16.0/stock_request_picking_type"><img alt="OCA/stock-logistics-request" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--request-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/stock-logistics-request-16-0/stock-logistics-request-16-0-stock_request_picking_type"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-request&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds stock request orders within the Inventory app with a new operation type.</p>
Expand Down Expand Up @@ -414,6 +414,8 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<li>Maxime Chambreuil &lt;<a class="reference external" href="mailto:mchambreuil&#64;opensourceintegrators.com">mchambreuil&#64;opensourceintegrators.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>Raphael Lee &lt;<a class="reference external" href="mailto:rlee&#64;opensourceintegrators.com">rlee&#64;opensourceintegrators.com</a>&gt;</li>
<li>[APSL-Nagarro](<a class="reference external" href="https://apsl.tech">https://apsl.tech</a>):
* Antoni Marroig &lt;<a class="reference external" href="mailto:amarroig&#64;apsl.net">amarroig&#64;apsl.net</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
118 changes: 61 additions & 57 deletions stock_request_picking_type/tests/test_stock_picking_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,103 +8,107 @@


class TestStockRequest(common.TransactionCase):
def setUp(self):
super(TestStockRequest, self).setUp()
@classmethod
def _create_user(cls, name, group_ids, company_ids):
return (
cls.env["res.users"]
.with_context(**{"no_reset_password": True})
.create(
{
"name": name,
"password": "demo",
"login": name,
"email": "@".join([name, "test.com"]),
"groups_id": [(6, 0, group_ids)],
"company_ids": [(6, 0, company_ids)],
}
)
)

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

@classmethod
def setUpClass(cls):
super().setUpClass()

# common models
self.stock_request = self.env["stock.request"]
self.request_order = self.env["stock.request.order"]
cls.stock_request = cls.env["stock.request"]
cls.request_order = cls.env["stock.request.order"]

# refs
self.stock_request_user_group = self.env.ref(
cls.stock_request_user_group = cls.env.ref(
"stock_request.group_stock_request_user"
)
self.stock_request_manager_group = self.env.ref(
cls.stock_request_manager_group = cls.env.ref(
"stock_request.group_stock_request_manager"
)
self.main_company = self.env.ref("base.main_company")
self.warehouse = self.env.ref("stock.warehouse0")
self.categ_unit = self.env.ref("uom.product_uom_categ_unit")
self.default_picking_type = self.env.ref(
cls.main_company = cls.env.ref("base.main_company")
cls.warehouse = cls.env.ref("stock.warehouse0")
cls.categ_unit = cls.env.ref("uom.product_uom_categ_unit")
cls.default_picking_type = cls.env.ref(
"stock_request_picking_type.stock_request_order"
)

self.product = self._create_product("SH", "Shoes", False)
self.stock_request_manager = self._create_user(
cls.product = cls._create_product("Shoes", "SH", False)
cls.stock_request_manager = cls._create_user(
"stock_request_manager",
[self.stock_request_manager_group.id],
[self.main_company.id],
[cls.stock_request_manager_group.id],
[cls.main_company.id],
)

self.ressuply_loc = self.env["stock.location"].create(
cls.ressuply_loc = cls.env["stock.location"].create(
{
"name": "Ressuply",
"location_id": self.warehouse.view_location_id.id,
"location_id": cls.warehouse.view_location_id.id,
"usage": "internal",
"company_id": self.main_company.id,
"company_id": cls.main_company.id,
}
)

self.route = self.env["stock.location.route"].create(
cls.route = cls.env["stock.route"].create(
{
"name": "Transfer",
"product_categ_selectable": False,
"product_selectable": True,
"company_id": self.main_company.id,
"company_id": cls.main_company.id,
"sequence": 10,
}
)

self.rule = self.env["stock.rule"].create(
cls.rule = cls.env["stock.rule"].create(
{
"name": "Transfer",
"route_id": self.route.id,
"location_src_id": self.ressuply_loc.id,
"location_id": self.warehouse.lot_stock_id.id,
"route_id": cls.route.id,
"location_src_id": cls.ressuply_loc.id,
"location_dest_id": cls.warehouse.lot_stock_id.id,
"action": "pull",
"picking_type_id": self.warehouse.int_type_id.id,
"picking_type_id": cls.warehouse.int_type_id.id,
"procure_method": "make_to_stock",
"warehouse_id": self.warehouse.id,
"company_id": self.main_company.id,
"warehouse_id": cls.warehouse.id,
"company_id": cls.main_company.id,
}
)

self.env["ir.config_parameter"].sudo().set_param(
cls.env["ir.config_parameter"].sudo().set_param(
"stock.no_auto_scheduler", "True"
)

def _create_user(self, name, group_ids, company_ids):
return (
self.env["res.users"]
.with_context({"no_reset_password": True})
.create(
{
"name": name,
"password": "demo",
"login": name,
"email": "@".join([name, "test.com"]),
"groups_id": [(6, 0, group_ids)],
"company_ids": [(6, 0, company_ids)],
}
)
)

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,
type="product",
**vals
)
)


class TestStockPickingType(TestStockRequest):
def setUp(self):
super(TestStockPickingType, self).setUp()
@classmethod
def setUpClass(cls):
super().setUpClass()

def test_compute_sr_count(self):
expected_date = fields.Datetime.now()
Expand Down
Loading

0 comments on commit 05cc872

Please sign in to comment.