Skip to content

Commit

Permalink
[MIG] stock_request: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicomacr committed Nov 8, 2023
1 parent 2be131c commit b03b127
Show file tree
Hide file tree
Showing 17 changed files with 298 additions and 259 deletions.
1 change: 1 addition & 0 deletions setup/stock_request/odoo/addons/stock_request
6 changes: 6 additions & 0 deletions setup/stock_request/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
14 changes: 7 additions & 7 deletions stock_request/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Stock Request
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-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/15.0/stock_request
:alt: OCA/stock-logistics-warehouse
:target: https://github.com/OCA/stock-logistics-request/tree/15.0/stock_request
:alt: OCA/stock-logistics-request
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-15-0/stock-logistics-warehouse-15-0-stock_request
:target: https://translation.odoo-community.org/projects/stock-logistics-request-16-0/stock-logistics-request-16-0-stock_request
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=15.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-request&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -89,10 +89,10 @@ It is also required to manage active field logically from Orders to SRs.
Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-request/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_request%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/stock-logistics-request/issues/new?body=module:%20stock_request%0Aversion:%2015.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.

Expand Down Expand Up @@ -136,6 +136,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/15.0/stock_request>`_ project on GitHub.
This module is part of the `OCA/stock-logistics-request <https://github.com/OCA/stock-logistics-request/tree/15.0/stock_request>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions stock_request/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{
"name": "Stock Request",
"summary": "Internal request for stock",
"version": "15.0.1.6.3",
"version": "16.0.1.0.0",
"license": "LGPL-3",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"website": "https://github.com/OCA/stock-logistics-request",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"category": "Warehouse Management",
"depends": ["stock"],
Expand Down
14 changes: 0 additions & 14 deletions stock_request/migrations/15.0.1.4.0/noupdate_changes.xml

This file was deleted.

10 changes: 0 additions & 10 deletions stock_request/migrations/15.0.1.4.0/post-migration.py

This file was deleted.

2 changes: 1 addition & 1 deletion stock_request/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
from . import res_config_settings
from . import stock_warehouse
from . import stock_location
from . import stock_location_route
from . import stock_route
from . import res_company
4 changes: 2 additions & 2 deletions stock_request/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class StockPicking(models.Model):
"Stock Request #", compute="_compute_stock_request_ids"
)

@api.depends("move_lines")
@api.depends("move_ids")
def _compute_stock_request_ids(self):
for rec in self:
rec.stock_request_ids = rec.move_lines.mapped("stock_request_ids")
rec.stock_request_ids = rec.move_ids.mapped("stock_request_ids")
rec.stock_request_count = len(rec.stock_request_ids)

def action_view_stock_request(self):
Expand Down
68 changes: 40 additions & 28 deletions stock_request/models/stock_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,41 +180,50 @@ def _compute_qty(self):

@api.constrains("order_id", "requested_by")
def check_order_requested_by(self):
if self.order_id and self.order_id.requested_by != self.requested_by:
raise ValidationError(_("Requested by must be equal to the order"))
for rec in self:
if rec.order_id and rec.order_id.requested_by != rec.requested_by:
raise ValidationError(_("Requested by must be equal to the order"))

@api.constrains("order_id", "warehouse_id")
def check_order_warehouse_id(self):
if self.order_id and self.order_id.warehouse_id != self.warehouse_id:
raise ValidationError(_("Warehouse must be equal to the order"))
for rec in self:
if rec.order_id and rec.order_id.warehouse_id != rec.warehouse_id:
raise ValidationError(_("Warehouse must be equal to the order"))

@api.constrains("order_id", "location_id")
def check_order_location(self):
if self.order_id and self.order_id.location_id != self.location_id:
raise ValidationError(_("Location must be equal to the order"))
for rec in self:
if rec.order_id and rec.order_id.location_id != rec.location_id:
raise ValidationError(_("Location must be equal to the order"))

@api.constrains("order_id", "procurement_group_id")
def check_order_procurement_group(self):
if (
self.order_id
and self.order_id.procurement_group_id != self.procurement_group_id
):
raise ValidationError(_("Procurement group must be equal to the order"))
for rec in self:
if (
rec.order_id
and rec.order_id.procurement_group_id != rec.procurement_group_id
):
raise ValidationError(_("Procurement group must be equal to the order"))

@api.constrains("order_id", "company_id")
def check_order_company(self):
if self.order_id and self.order_id.company_id != self.company_id:
raise ValidationError(_("Company must be equal to the order"))
for rec in self:
if rec.order_id and rec.order_id.company_id != rec.company_id:
raise ValidationError(_("Company must be equal to the order"))

@api.constrains("order_id", "expected_date")
def check_order_expected_date(self):
if self.order_id and self.order_id.expected_date != self.expected_date:
raise ValidationError(_("Expected date must be equal to the order"))
for rec in self:
if rec.order_id and rec.order_id.expected_date != rec.expected_date:
raise ValidationError(_("Expected date must be equal to the order"))

@api.constrains("order_id", "picking_policy")
def check_order_picking_policy(self):
if self.order_id and self.order_id.picking_policy != self.picking_policy:
raise ValidationError(_("The picking policy must be equal to the order"))
for rec in self:
if rec.order_id and rec.order_id.picking_policy != rec.picking_policy:
raise ValidationError(
_("The picking policy must be equal to the order")
)

def _action_confirm(self):
self._action_launch_procurement_rule()
Expand Down Expand Up @@ -351,17 +360,20 @@ def action_view_transfer(self):
action["res_id"] = pickings.id
return action

@api.model
def create(self, vals):
upd_vals = vals.copy()
if upd_vals.get("name", "/") == "/":
upd_vals["name"] = self.env["ir.sequence"].next_by_code("stock.request")
if "order_id" in upd_vals:
order_id = self.env["stock.request.order"].browse(upd_vals["order_id"])
upd_vals["expected_date"] = order_id.expected_date
else:
upd_vals["expected_date"] = self._get_expected_date()
return super().create(upd_vals)
@api.model_create_multi
def create(self, vals_list):
vals_list_upd = []
for vals in vals_list:
upd_vals = vals.copy()
if upd_vals.get("name", "/") == "/":
upd_vals["name"] = self.env["ir.sequence"].next_by_code("stock.request")
if "order_id" in upd_vals:
order_id = self.env["stock.request.order"].browse(upd_vals["order_id"])
upd_vals["expected_date"] = order_id.expected_date
else:
upd_vals["expected_date"] = self._get_expected_date()
vals_list_upd.append(upd_vals)
return super().create(vals_list_upd)

def unlink(self):
if self.filtered(lambda r: r.state != "draft"):
Expand Down
12 changes: 5 additions & 7 deletions stock_request/models/stock_request_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ def _compute_product_qty(self):
"res.company", "Company", required=True, default=lambda self: self.env.company
)
route_id = fields.Many2one(
"stock.location.route",
"stock.route",
string="Route",
domain="[('id', 'in', route_ids)]",
ondelete="restrict",
)

route_ids = fields.Many2many(
"stock.location.route",
"stock.route",
string="Routes",
compute="_compute_route_ids",
readonly=True,
Expand All @@ -113,16 +113,14 @@ def _compute_product_qty(self):

@api.depends("product_id", "warehouse_id", "location_id")
def _compute_route_ids(self):
route_obj = self.env["stock.location.route"]
route_obj = self.env["stock.route"]
routes = route_obj.search(
[("warehouse_ids", "in", self.mapped("warehouse_id").ids)]
)
routes_by_warehouse = {}
for route in routes:
for warehouse in route.warehouse_ids:
routes_by_warehouse.setdefault(
warehouse.id, self.env["stock.location.route"]
)
routes_by_warehouse.setdefault(warehouse.id, self.env["stock.route"])
routes_by_warehouse[warehouse.id] |= route
for record in self:
routes = route_obj
Expand All @@ -134,7 +132,7 @@ def _compute_route_ids(self):
routes |= routes_by_warehouse[record.warehouse_id.id]
parents = record.get_parents().ids
record.route_ids = routes.filtered(
lambda r: any(p.location_id.id in parents for p in r.rule_ids)
lambda r: any(p.location_dest_id.id in parents for p in r.rule_ids)
)

def get_parents(self):
Expand Down
19 changes: 11 additions & 8 deletions stock_request/models/stock_request_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,17 @@ def action_view_stock_requests(self):
action["res_id"] = self.stock_request_ids.id
return action

@api.model
def create(self, vals):
upd_vals = vals.copy()
if upd_vals.get("name", "/") == "/":
upd_vals["name"] = self.env["ir.sequence"].next_by_code(
"stock.request.order"
)
return super().create(upd_vals)
@api.model_create_multi
def create(self, vals_list):
vals_list_upd = []
for vals in vals_list:
upd_vals = vals.copy()
if upd_vals.get("name", "/") == "/":
upd_vals["name"] = self.env["ir.sequence"].next_by_code(
"stock.request.order"
)
vals_list_upd.append(upd_vals)
return super().create(vals_list_upd)

def unlink(self):
if self.filtered(lambda r: r.state != "draft"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from odoo.exceptions import ValidationError


class StockLocationRoute(models.Model):
_inherit = "stock.location.route"
class StockRoute(models.Model):
_inherit = "stock.route"

@api.constrains("company_id")
def _check_company_stock_request(self):
Expand Down
Loading

0 comments on commit b03b127

Please sign in to comment.