Skip to content

Commit 3ab39ac

Browse files
committed
[MIG] maintenance_stock: Migration to 14.0
1 parent b6a5612 commit 3ab39ac

10 files changed

+90
-102
lines changed

maintenance_stock/__manifest__.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@
55
"summary": "Links maintenance requests to stock",
66
"author": "Odoo Community Association (OCA), Solvos",
77
"license": "AGPL-3",
8-
"version": "13.0.1.0.0",
8+
"version": "14.0.1.0.0",
99
"category": "Warehouse",
1010
"website": "https://github.com/OCA/maintenance",
11-
"depends": ["base_maintenance", "stock",],
11+
"depends": [
12+
"base_maintenance",
13+
"stock",
14+
],
1215
"data": [
1316
"views/maintenance_equipment_views.xml",
1417
"views/maintenance_request_views.xml",
1518
"views/stock_move_views.xml",
1619
"views/stock_move_line_views.xml",
1720
"views/stock_picking_views.xml",
1821
],
19-
"demo": ["data/demo_maintenance_stock.xml",],
22+
"demo": [
23+
"data/demo_maintenance_stock.xml",
24+
],
2025
"post_init_hook": "post_init_hook",
2126
"installable": True,
2227
}

maintenance_stock/data/demo_maintenance_stock.xml

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
33
<data noupdate="1">
4+
<record id="location_inventory" model="stock.location">
5+
<field name="name">Inventory adjustment</field>
6+
<field name="usage">inventory</field>
47

8+
</record>
59
<record id="stock_warehouse_maintenance" model="stock.warehouse">
610
<field name="name">Maintenance Warehouse</field>
711
<field name="partner_id" ref="stock.res_partner_address_41" />
812
<field name="code">Main</field>
13+
<field name="reception_steps">one_step</field>
14+
<field name="delivery_steps">ship_only</field>
915
</record>
1016

1117
<function model="ir.model.data" name="_update_xmlids">
@@ -37,18 +43,20 @@
3743
<field name="uom_id" ref="uom.product_uom_unit" />
3844
<field name="uom_po_id" ref="uom.product_uom_unit" />
3945
<field
40-
name="image"
46+
name="image_1920"
4147
type="base64"
4248
file="maintenance_stock/static/img/toner.png"
4349
/>
50+
4451
</record>
4552

4653
<record id="stock_inventory_toner" model="stock.inventory">
4754
<field name="name">Inventory for Toner</field>
4855
<field
4956
name="product_ids"
50-
eval="[(4, ref('maintenance_stock.product_toner'))]"
57+
eval="[(6,0,[ref('maintenance_stock.product_toner'),])]"
5158
/>
59+
5260
</record>
5361

5462
<record id="stock_inventory_toner_line" model="stock.inventory.line">
@@ -58,18 +66,16 @@
5866
<field name="product_qty">50.0</field>
5967
<field name="location_id" ref="maintenance_stock.main_location_stock" />
6068
</record>
61-
62-
<function model="stock.inventory" name="_action_start">
69+
<function name="action_start" model="stock.inventory">
6370
<function
64-
eval="[[('state','=','draft'),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
71+
eval="[[('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
6572
model="stock.inventory"
6673
name="search"
6774
/>
6875
</function>
69-
7076
<function model="stock.inventory" name="action_validate">
7177
<function
72-
eval="[[('state','=','confirm'),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
78+
eval="[[('state','in', ['draft', 'confirm']),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
7379
model="stock.inventory"
7480
name="search"
7581
/>
@@ -81,6 +87,7 @@
8187
name="default_consumption_warehouse_id"
8288
ref="maintenance_stock.stock_warehouse_maintenance"
8389
/>
90+
8491
</record>
8592

8693
<record id="m_request_1" model="maintenance.request">
@@ -90,12 +97,13 @@
9097
<field name="equipment_id" ref="maintenance.equipment_printer1" />
9198
<field name="color">7</field>
9299
<field name="stage_id" ref="maintenance.stage_1" />
93-
<field
94-
name="maintenance_team_id"
95-
ref="maintenance.equipment_team_maintenance"
96-
/>
97-
</record>
98100

101+
</record>
102+
<record model="stock.quant" id="stock_quant_toner">
103+
<field name="product_id" ref="maintenance_stock.product_toner" />
104+
<field name="location_id" ref="maintenance_stock.main_location_stock" />
105+
<field name="quantity">1.0</field>
106+
</record>
99107
<record id="consuption_picking_m_request_1" model="stock.picking">
100108
<field
101109
name="picking_type_id"
@@ -105,6 +113,7 @@
105113
<field name="location_id" ref="maintenance_stock.main_location_stock" />
106114
<field name="location_dest_id" ref="maintenance_stock.main_location_cons" />
107115
<field name="maintenance_request_id" ref="maintenance_stock.m_request_1" />
116+
108117
<field
109118
name="move_lines"
110119
model="stock.move"
@@ -116,13 +125,7 @@
116125
'picking_type_id': ref('maintenance_stock.main_picking_type_cons'),
117126
'location_id': ref('maintenance_stock.main_location_stock'),
118127
'location_dest_id': ref('maintenance_stock.main_location_cons'),
119-
'move_line_ids': [(0, 0, {
120-
'product_id': ref('maintenance_stock.product_toner'),
121-
'qty_done': 1,
122-
'product_uom_id': ref('uom.product_uom_unit'),
123-
'location_id': ref('maintenance_stock.main_location_stock'),
124-
'location_dest_id': ref('maintenance_stock.main_location_cons'),
125-
})],
128+
126129
})]"
127130
/>
128131
</record>
@@ -134,8 +137,14 @@
134137
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
135138
/>
136139
</function>
137-
138-
<function model="stock.picking" name="action_done">
140+
<function model="stock.picking" name="action_assign">
141+
<value
142+
model="stock.picking"
143+
eval="[
144+
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
145+
/>
146+
</function>
147+
<function model="stock.picking" name="button_validate">
139148
<value
140149
model="stock.picking"
141150
eval="[

maintenance_stock/models/maintenance_equipment.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66
class MaintenanceEquipment(models.Model):
77
_inherit = "maintenance.equipment"
88

9-
stock_picking_ids = fields.One2many(
10-
comodel_name="stock.picking",
11-
inverse_name="maintenance_equipment_id",
12-
groups="stock.group_stock_user",
13-
)
149
allow_consumptions = fields.Boolean(
1510
groups="stock.group_stock_user",
1611
)
@@ -27,7 +22,9 @@ def _onchange_allow_consumptions(self):
2722

2823
def action_view_stock_picking_ids(self):
2924
self.ensure_one()
30-
action = self.env.ref("stock.action_picking_tree_all").read()[0]
25+
action = self.env["ir.actions.act_window"]._for_xml_id(
26+
"stock.action_picking_tree_all"
27+
)
3128
action["domain"] = [("maintenance_equipment_id", "=", self.id)]
3229
action["context"] = {
3330
"show_maintenance_request_id": True,
@@ -36,13 +33,17 @@ def action_view_stock_picking_ids(self):
3633

3734
def action_view_stock_move_ids(self):
3835
self.ensure_one()
39-
action = self.env.ref("stock.stock_move_action").read()[0]
36+
action = self.env["ir.actions.act_window"]._for_xml_id(
37+
"stock.stock_move_action"
38+
)
4039
action["domain"] = [("maintenance_equipment_id", "=", self.id)]
4140
return action
4241

4342
def action_view_stock_move_line_ids(self):
4443
self.ensure_one()
45-
action = self.env.ref("stock.stock_move_line_action").read()[0]
44+
action = self.env["ir.actions.act_window"]._for_xml_id(
45+
"stock.stock_move_line_action"
46+
)
4647
action["domain"] = [("maintenance_equipment_id", "=", self.id)]
4748

4849
# TODO Grouping by destination allows separating consumptions

maintenance_stock/models/maintenance_request.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ class MaintenanceRequest(models.Model):
2424

2525
def action_view_stock_picking_ids(self):
2626
self.ensure_one()
27-
action = self.env.ref("stock.stock_picking_action_picking_type").read()[0]
27+
action = self.env["ir.actions.act_window"]._for_xml_id(
28+
"stock.stock_picking_action_picking_type"
29+
)
2830
action["domain"] = [("maintenance_request_id", "=", self.id)]
2931
action["context"] = {
3032
"default_picking_type_id": self.default_consumption_warehouse_id.cons_type_id.id,
@@ -34,13 +36,17 @@ def action_view_stock_picking_ids(self):
3436

3537
def action_view_stock_move_ids(self):
3638
self.ensure_one()
37-
action = self.env.ref("stock.stock_move_action").read()[0]
39+
action = self.env["ir.actions.act_window"]._for_xml_id(
40+
"stock.stock_move_action"
41+
)
3842
action["domain"] = [("maintenance_request_id", "=", self.id)]
3943
return action
4044

4145
def action_view_stock_move_line_ids(self):
4246
self.ensure_one()
43-
action = self.env.ref("stock.stock_move_line_action").read()[0]
47+
action = self.env["ir.actions.act_window"]._for_xml_id(
48+
"stock.stock_move_line_action"
49+
)
4450
action["domain"] = [("maintenance_request_id", "=", self.id)]
4551

4652
# TODO Grouping by destination allows separating consumptions

maintenance_stock/models/stock_warehouse.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def _create_or_update_sequences_and_picking_types(self):
2020
# solved with a hook
2121
if "cons_type_id" in warehouse_data:
2222
PickingType.browse(warehouse_data["cons_type_id"]).write(
23-
{"return_picking_type_id": warehouse_data.get("in_type_id", False),}
23+
{
24+
"return_picking_type_id": warehouse_data.get("in_type_id", False),
25+
}
2426
)
2527
return warehouse_data
2628

@@ -41,8 +43,9 @@ def _get_picking_type_create_values(self, max_sequence):
4143
"use_existing_lots": True,
4244
"default_location_src_id": self.lot_stock_id.id,
4345
"default_location_dest_id": self.wh_cons_loc_id.id,
44-
"sequence": max_sequence_new,
46+
"sequence_code": max_sequence_new,
4547
"barcode": self.code.replace(" ", "").upper() + "-CONS",
48+
"company_id": self.company_id.id or self.env.company.id,
4649
},
4750
},
4851
max_sequence_new + 1,
@@ -64,8 +67,8 @@ def _get_sequence_values(self):
6467
},
6568
}
6669

67-
def _get_locations_values(self, vals):
68-
sub_locations = super()._get_locations_values(vals)
70+
def _get_locations_values(self, vals, code=False):
71+
sub_locations = super()._get_locations_values(vals, code)
6972
code = vals.get("code") or self.code
7073
code = code.replace(" ", "").upper()
7174
company_id = vals.get("company_id", self.company_id.id)

maintenance_stock/tests/test_maintenance_stock.py

+24-59
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
22
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
33
import odoo.tests.common as test_common
4+
from odoo.tests.common import Form
45

56

67
class TestMaintenanceStock(test_common.TransactionCase):
78
def setUp(self):
89
super().setUp()
9-
1010
self.maintenance_warehouse = self.env["stock.warehouse"].create(
11-
{"name": "Test warehouse", "code": "TEST",}
12-
{"name": "Test warehouse", "code": "TEST"}
1311
{
1412
"name": "Test warehouse",
1513
"code": "TEST",
@@ -30,6 +28,7 @@ def setUp(self):
3028
{
3129
"name": "Test equipment",
3230
"allow_consumptions": True,
31+
"equipment_assign_to": "employee",
3332
"default_consumption_warehouse_id": self.maintenance_warehouse.id,
3433
}
3534
)
@@ -109,61 +108,26 @@ def test_request(self):
109108

110109
def test_picking(self):
111110
self.assertEqual(len(self.request_1.stock_picking_ids), 0)
112-
self.assertEqual(len(self.equipment_1.stock_picking_ids), 0)
113-
114-
qty_done = 5.0
115-
move_line_data = {
116-
"product_id": self.product1.id,
117-
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
118-
"qty_done": qty_done,
119-
"location_id": self.maintenance_warehouse.lot_stock_id.id,
120-
"location_dest_id": self.maintenance_warehouse.wh_cons_loc_id.id,
121-
}
122-
location_id = self.maintenance_warehouse.lot_stock_id.id
123-
location_dest_id = self.maintenance_warehouse.wh_cons_loc_id.id
124-
picking_type_id = self.maintenance_warehouse.cons_type_id.id
125-
picking = self.env["stock.picking"].create(
111+
location_id = self.maintenance_warehouse.lot_stock_id
112+
location_dest_id = self.maintenance_warehouse.wh_cons_loc_id
113+
picking_type_id = self.maintenance_warehouse.cons_type_id
114+
self.env["stock.quant"].create(
126115
{
127-
"maintenance_request_id": self.request_1.id,
128-
"picking_type_id": picking_type_id,
129-
"location_id": location_id,
130-
"location_dest_id": location_dest_id,
131-
"move_lines": [
132-
(
133-
0,
134-
0,
135-
{
136-
"name": "Test move",
137-
"product_id": self.product1.id,
138-
"product_uom": self.env.ref("uom.product_uom_unit").id,
139-
"product_uom_qty": 5.0,
140-
"picking_type_id": picking_type_id,
141-
"location_id": location_id,
142-
"location_dest_id": location_dest_id,
143-
"move_line_ids": [
144-
(
145-
0,
146-
0,
147-
{
148-
"product_id": self.product1.id,
149-
"product_uom_id": self.env.ref(
150-
"uom.product_uom_unit"
151-
).id,
152-
"qty_done": qty_done,
153-
"location_id": location_id,
154-
"location_dest_id": location_dest_id,
155-
},
156-
)
157-
],
158-
},
159-
)
160-
],
116+
"product_id": self.product1.id,
117+
"location_id": location_id.id,
118+
"quantity": 5,
161119
}
162120
)
163-
121+
picking_form = Form(self.env["stock.picking"])
122+
picking_form.picking_type_id = picking_type_id
123+
picking_form.location_id = location_id
124+
picking_form.location_dest_id = location_dest_id
125+
with picking_form.move_ids_without_package.new() as move:
126+
move.product_id = self.product1
127+
move.product_uom_qty = 5.0
128+
picking = picking_form.save()
129+
picking.write({"maintenance_request_id": self.request_1.id})
164130
self.assertEqual(len(self.request_1.stock_picking_ids), 1)
165-
self.assertEqual(len(self.equipment_1.stock_picking_ids), 1)
166-
167131
stock_quant_obj = self.env["stock.quant"]
168132
domain_from = [
169133
("product_id", "=", self.product1.id),
@@ -173,11 +137,12 @@ def test_picking(self):
173137
("product_id", "=", self.product1.id),
174138
("location_id", "=", self.maintenance_warehouse.wh_cons_loc_id.id),
175139
]
176-
self.assertEqual(stock_quant_obj.search(domain_from).quantity, 0)
140+
self.assertEqual(stock_quant_obj.search(domain_from).quantity, 5)
177141
self.assertEqual(stock_quant_obj.search(domain_to).quantity, 0)
178142

179143
picking.action_confirm()
180-
picking.action_done()
181-
182-
self.assertEqual(stock_quant_obj.search(domain_from).quantity, -qty_done)
183-
self.assertEqual(stock_quant_obj.search(domain_to).quantity, qty_done)
144+
picking.action_assign()
145+
picking.move_line_ids.write({"qty_done": 5.0})
146+
picking.button_validate()
147+
self.assertEqual(stock_quant_obj.search(domain_from).quantity, 0)
148+
self.assertEqual(stock_quant_obj.search(domain_to).quantity, 5)

maintenance_stock/views/maintenance_request_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_search" />
77
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
88
<field name="arch" type="xml">
9-
<xpath expr="//filter[@name='top_priority']" position="after">
9+
<xpath expr="//filter[@name='high_priority']" position="after">
1010
<separator />
1111
<filter
1212
string="Allow Consumptions"

0 commit comments

Comments
 (0)