Skip to content

Commit 4627857

Browse files
committed
[MIG] stock_request: Migration to 19.0
1 parent ccf0ea2 commit 4627857

15 files changed

+129
-137
lines changed

stock_request/README.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ Stock Request
2121
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
2222
:alt: License: LGPL-3
2323
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--request-lightgray.png?logo=github
24-
:target: https://github.com/OCA/stock-logistics-request/tree/18.0/stock_request
24+
:target: https://github.com/OCA/stock-logistics-request/tree/19.0/stock_request
2525
:alt: OCA/stock-logistics-request
2626
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27-
:target: https://translation.odoo-community.org/projects/stock-logistics-request-18-0/stock-logistics-request-18-0-stock_request
27+
:target: https://translation.odoo-community.org/projects/stock-logistics-request-19-0/stock-logistics-request-19-0-stock_request
2828
:alt: Translate me on Weblate
2929
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30-
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-request&target_branch=18.0
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-request&target_branch=19.0
3131
:alt: Try me on Runboat
3232

3333
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -96,7 +96,7 @@ Bug Tracker
9696
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-request/issues>`_.
9797
In case of trouble, please check there if your issue has already been reported.
9898
If you spotted it first, help us to smash it by providing a detailed and welcomed
99-
`feedback <https://github.com/OCA/stock-logistics-request/issues/new?body=module:%20stock_request%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
99+
`feedback <https://github.com/OCA/stock-logistics-request/issues/new?body=module:%20stock_request%0Aversion:%2019.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
100100

101101
Do not contact contributors directly about support or help with technical issues.
102102

@@ -151,6 +151,6 @@ Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
151151

152152
|maintainer-LoisRForgeFlow| |maintainer-etobella|
153153

154-
This module is part of the `OCA/stock-logistics-request <https://github.com/OCA/stock-logistics-request/tree/18.0/stock_request>`_ project on GitHub.
154+
This module is part of the `OCA/stock-logistics-request <https://github.com/OCA/stock-logistics-request/tree/19.0/stock_request>`_ project on GitHub.
155155

156156
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

stock_request/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Stock Request",
66
"summary": "Internal request for stock",
7-
"version": "18.0.1.1.3",
7+
"version": "19.0.1.0.0",
88
"license": "LGPL-3",
99
"website": "https://github.com/OCA/stock-logistics-request",
1010
"author": "ForgeFlow, Odoo Community Association (OCA)",

stock_request/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from . import procurement_group
21
from . import stock_request_abstract
32
from . import stock_request
43
from . import stock_request_allocation

stock_request/models/procurement_group.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

stock_request/models/stock_request.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ def _get_expected_date():
103103
product_id = fields.Many2one()
104104
product_uom_id = fields.Many2one()
105105
product_uom_qty = fields.Float()
106-
procurement_group_id = fields.Many2one()
106+
reference_ids = fields.Many2many()
107107
company_id = fields.Many2one()
108108
route_id = fields.Many2one()
109109

110-
_sql_constraints = [
111-
("name_uniq", "unique(name, company_id)", "Stock Request name must be unique")
112-
]
110+
_name_uniq = models.Constraint(
111+
"unique(name, company_id)", "Stock Request name must be unique"
112+
)
113113

114114
@api.constrains("state", "product_qty")
115115
def _check_qty(self):
@@ -221,15 +221,14 @@ def check_order_location(self):
221221
):
222222
raise ValidationError(_("Location must be equal to the order"))
223223

224-
@api.constrains("order_id", "procurement_group_id")
225-
def check_order_procurement_group(self):
224+
@api.constrains("order_id", "reference_ids")
225+
def check_order_reference_ids(self):
226226
for stock_request in self:
227227
if (
228228
stock_request.order_id
229-
and stock_request.order_id.procurement_group_id
230-
!= stock_request.procurement_group_id
229+
and stock_request.order_id.reference_ids != stock_request.reference_ids
231230
):
232-
raise ValidationError(_("Procurement group must be equal to the order"))
231+
raise ValidationError(_("References must be equal to the order"))
233232

234233
@api.constrains("order_id", "company_id")
235234
def check_order_company(self):
@@ -318,7 +317,7 @@ def _check_cancel_allocation(self):
318317
and float_compare(self.qty_cancelled, 0, precision_digits=precision) > 0
319318
)
320319

321-
def _prepare_procurement_values(self, group_id=False):
320+
def _prepare_procurement_values(self, reference_ids=False):
322321
"""Prepare specific key for moves or other components that
323322
will be created from a procurement rule
324323
coming from a stock request. This method could be override
@@ -329,7 +328,9 @@ def _prepare_procurement_values(self, group_id=False):
329328
"date_planned": self.expected_date,
330329
"warehouse_id": self.warehouse_id,
331330
"stock_request_allocation_ids": self.id,
332-
"group_id": group_id or self.procurement_group_id.id or False,
331+
"reference_ids": reference_ids
332+
or self.reference_ids
333+
or self.env["stock.reference"],
333334
"route_ids": self.route_id,
334335
"stock_request_id": self.id,
335336
}
@@ -339,7 +340,6 @@ def _skip_procurement(self):
339340

340341
def _prepare_stock_move(self, qty):
341342
return {
342-
"name": self.product_id.display_name,
343343
"company_id": self.company_id.id,
344344
"product_id": self.product_id.id,
345345
"product_uom_qty": qty,
@@ -380,9 +380,9 @@ def _action_use_stock_available(self):
380380

381381
def _action_launch_procurement_rule(self):
382382
"""
383-
Launch procurement group (if not enough stock is available) run method
383+
Launch stock rule (if not enough stock is available) run method
384384
with required/custom fields genrated by a
385-
stock request. procurement group will launch '_run_move',
385+
stock request. stock rule will launch '_run_move',
386386
'_run_buy' or '_run_manufacture'
387387
depending on the stock request product rule.
388388
"""
@@ -416,12 +416,12 @@ def _action_launch_procurement_rule(self):
416416
continue
417417

418418
values = request._prepare_procurement_values(
419-
group_id=request.procurement_group_id
419+
reference_ids=request.reference_ids
420420
)
421421
try:
422422
procurements = []
423423
procurements.append(
424-
self.env["procurement.group"].Procurement(
424+
self.env["stock.rule"].Procurement(
425425
request.product_id,
426426
request.product_uom_qty,
427427
request.product_uom_id,
@@ -432,7 +432,7 @@ def _action_launch_procurement_rule(self):
432432
values,
433433
)
434434
)
435-
self.env["procurement.group"].run(procurements)
435+
self.env["stock.rule"].run(procurements)
436436
except UserError as error:
437437
errors.append(str(error))
438438
if errors:

stock_request/models/stock_request_abstract.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,15 @@ def _compute_product_qty(self):
6363
allow_virtual_location = fields.Boolean(
6464
related="company_id.stock_request_allow_virtual_loc", readonly=True
6565
)
66-
allowed_uom_categ_id = fields.Many2one(related="product_id.uom_id.category_id")
66+
allowed_uom_ids = fields.Many2many(
67+
comodel_name="uom.uom", compute="_compute_allowed_uom_ids"
68+
)
6769
product_uom_id = fields.Many2one(
6870
comodel_name="uom.uom",
6971
string="Product Unit of Measure",
70-
domain="[('category_id', '=?', allowed_uom_categ_id)]",
72+
domain="[('id', 'in', allowed_uom_ids)]",
7173
required=True,
72-
default=lambda self: self._context.get("product_uom_id", False),
74+
default=lambda self: self.env.context.get("product_uom_id", False),
7375
)
7476
product_uom_qty = fields.Float(
7577
"Quantity",
@@ -85,11 +87,11 @@ def _compute_product_qty(self):
8587
digits="Product Unit of Measure",
8688
help="Quantity in the default UoM of the product",
8789
)
88-
procurement_group_id = fields.Many2one(
89-
"procurement.group",
90-
"Procurement Group",
91-
help="Moves created through this stock request will be put in this "
92-
"procurement group. If none is given, the moves generated by "
90+
reference_ids = fields.Many2many(
91+
"stock.reference",
92+
"References",
93+
help="Moves created through this stock request will be grouped using "
94+
"these references. If none are given, the moves generated by "
9395
"procurement rules will be grouped into one big picking.",
9496
)
9597
company_id = fields.Many2one(
@@ -109,9 +111,14 @@ def _compute_product_qty(self):
109111
readonly=True,
110112
)
111113

112-
_sql_constraints = [
113-
("name_uniq", "unique(name, company_id)", "Name must be unique")
114-
]
114+
_name_uniq = models.Constraint("unique(name, company_id)", "Name must be unique")
115+
116+
@api.depends("product_id", "product_id.uom_id", "product_id.uom_ids")
117+
def _compute_allowed_uom_ids(self):
118+
for record in self:
119+
record.allowed_uom_ids = (
120+
record.product_id.uom_id | record.product_id.uom_ids
121+
)
115122

116123
@api.depends("product_id", "warehouse_id", "location_id")
117124
def _compute_route_ids(self):
@@ -190,7 +197,12 @@ def _check_product_uom(self):
190197
"""Check if the UoM has the same category as the
191198
product standard UoM"""
192199
if any(
193-
request.product_id.uom_id.category_id != request.product_uom_id.category_id
200+
request.product_id.uom_id
201+
not in (
202+
request.product_uom_id
203+
| request.product_uom_id.relative_uom_id
204+
| request.product_uom_id.relative_uom_id.related_uom_ids
205+
)
194206
for request in self
195207
):
196208
raise ValidationError(

stock_request/models/stock_request_order.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2018 Creu Blanca
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
33

4-
from odoo import _, api, fields, models
4+
from odoo import Command, _, api, fields, models
55
from odoo.exceptions import UserError, ValidationError
66

77

@@ -76,11 +76,14 @@ def _get_default_requested_by(self):
7676
allow_virtual_location = fields.Boolean(
7777
related="company_id.stock_request_allow_virtual_loc", readonly=True
7878
)
79-
procurement_group_id = fields.Many2one(
80-
"procurement.group",
81-
"Procurement Group",
82-
help="Moves created through this stock request will be put in this "
83-
"procurement group. If none is given, the moves generated by "
79+
reference_ids = fields.Many2many(
80+
comodel_name="stock.reference",
81+
relation="stock_request_order_stock_reference_rel",
82+
column1="stock_request_order_id",
83+
column2="stock_reference_id",
84+
string="References",
85+
help="Moves created through this stock request will be grouped using "
86+
"these references. If none are given, the moves generated by "
8487
"procurement rules will be grouped into one big picking.",
8588
)
8689
company_id = fields.Many2one(
@@ -143,9 +146,9 @@ def _get_default_requested_by(self):
143146
help="The route related to a stock request order",
144147
)
145148

146-
_sql_constraints = [
147-
("name_uniq", "unique(name, company_id)", "Stock Request name must be unique")
148-
]
149+
_name_uniq = models.Constraint(
150+
"unique(name, company_id)", "Stock Request name must be unique"
151+
)
149152

150153
@api.depends("warehouse_id", "location_id", "stock_request_ids")
151154
def _compute_route_ids(self):
@@ -271,8 +274,8 @@ def onchange_warehouse_id(self):
271274
self.with_context(no_change_childs=True).onchange_company_id()
272275
self.change_childs()
273276

274-
@api.onchange("procurement_group_id")
275-
def onchange_procurement_group_id(self):
277+
@api.onchange("reference_ids")
278+
def onchange_reference_ids(self):
276279
self.change_childs()
277280

278281
@api.onchange("company_id")
@@ -287,15 +290,15 @@ def onchange_company_id(self):
287290
self.change_childs()
288291

289292
def change_childs(self):
290-
if not self._context.get("no_change_childs", False):
293+
if not self.env.context.get("no_change_childs", False):
291294
for line in self.stock_request_ids:
292295
line.warehouse_id = self.warehouse_id
293296
line.location_id = self.location_id
294297
line.company_id = self.company_id
295298
line.picking_policy = self.picking_policy
296299
line.expected_date = self.expected_date
297300
line.requested_by = self.requested_by
298-
line.procurement_group_id = self.procurement_group_id
301+
line.reference_ids = [Command.set(self.reference_ids.ids)]
299302

300303
def action_confirm(self):
301304
if not self.stock_request_ids:

stock_request/models/stock_rule.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2017-2020 ForgeFlow, S.L.
22
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
33

4-
from odoo import models
4+
from odoo import api, models
55

66

77
class StockRule(models.Model):
@@ -40,3 +40,24 @@ def _get_stock_move_values(
4040
)
4141
]
4242
return result
43+
44+
@api.model
45+
def run(self, procurements, raise_user_error=True):
46+
indexes_to_pop = []
47+
new_procs = []
48+
for i, procurement in enumerate(procurements):
49+
if "stock_request_id" in procurement.values and procurement.values.get(
50+
"stock_request_id"
51+
):
52+
req = self.env["stock.request"].browse(
53+
procurement.values.get("stock_request_id")
54+
)
55+
if req.order_id:
56+
new_procs.append(procurement._replace(origin=req.order_id.name))
57+
indexes_to_pop.append(i)
58+
if new_procs:
59+
indexes_to_pop.reverse()
60+
for index in indexes_to_pop:
61+
procurements.pop(index)
62+
procurements.extend(new_procs)
63+
return super().run(procurements, raise_user_error=raise_user_error)

stock_request/security/stock_request_security.xml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3-
<record model="ir.module.category" id="module_category_stock_request">
3+
<record model="res.groups.privilege" id="res_groups_privilege_stock_request">
44
<field name="name">Stock Request</field>
5-
<field name="parent_id" ref="base.module_category_inventory" />
6-
<field name="sequence">10</field>
5+
<field name="category_id" ref="base.module_category_supply_chain" />
6+
</record>
7+
<record model="res.groups.privilege" id="res_groups_privilege_stock_request_order">
8+
<field name="name">Stock Request Orders</field>
9+
<field name="category_id" ref="base.module_category_hidden" />
710
</record>
811
<record id="group_stock_request_user" model="res.groups">
912
<field name="name">Stock Request User</field>
1013
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
11-
<field name="category_id" ref="module_category_stock_request" />
14+
<field name="privilege_id" ref="res_groups_privilege_stock_request" />
1215
</record>
1316
<record id="group_stock_request_manager" model="res.groups">
1417
<field name="name">Stock Request Manager</field>
1518
<field
16-
name="users"
19+
name="user_ids"
1720
eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"
1821
/>
1922
<field
2023
name="implied_ids"
2124
eval="[(4, ref('stock_request.group_stock_request_user')),(4, ref('stock.group_stock_user'))]"
2225
/>
23-
<field name="category_id" ref="module_category_stock_request" />
26+
<field name="privilege_id" ref="res_groups_privilege_stock_request" />
2427
</record>
2528
<record id="group_stock_request_order" model="res.groups">
2629
<field name="name">Stock Request Order</field>
27-
<field name="category_id" ref="base.module_category_hidden" />
30+
<field name="privilege_id" ref="res_groups_privilege_stock_request_order" />
2831
</record>
2932
<data noupdate="1">
3033
<record model="ir.rule" id="stock_picking_rule">

0 commit comments

Comments
 (0)