Skip to content

Commit

Permalink
[MIG] maintenance_stock: Migration to 14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Reyes4711-S73 committed Sep 22, 2023
1 parent b6a5612 commit b573f37
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 102 deletions.
11 changes: 8 additions & 3 deletions maintenance_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
"summary": "Links maintenance requests to stock",
"author": "Odoo Community Association (OCA), Solvos",
"license": "AGPL-3",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"category": "Warehouse",
"website": "https://github.com/OCA/maintenance",
"depends": ["base_maintenance", "stock",],
"depends": [
"base_maintenance",
"stock",
],
"data": [
"views/maintenance_equipment_views.xml",
"views/maintenance_request_views.xml",
"views/stock_move_views.xml",
"views/stock_move_line_views.xml",
"views/stock_picking_views.xml",
],
"demo": ["data/demo_maintenance_stock.xml",],
"demo": [
"data/demo_maintenance_stock.xml",
],
"post_init_hook": "post_init_hook",
"installable": True,
}
51 changes: 30 additions & 21 deletions maintenance_stock/data/demo_maintenance_stock.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<record id="location_inventory" model="stock.location">
<field name="name">Inventory adjustment</field>
<field name="usage">inventory</field>

</record>
<record id="stock_warehouse_maintenance" model="stock.warehouse">
<field name="name">Maintenance Warehouse</field>
<field name="partner_id" ref="stock.res_partner_address_41" />
<field name="code">Main</field>
<field name="reception_steps">one_step</field>
<field name="delivery_steps">ship_only</field>
</record>

<function model="ir.model.data" name="_update_xmlids">
Expand Down Expand Up @@ -37,18 +43,20 @@
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field
name="image"
name="image_1920"
type="base64"
file="maintenance_stock/static/img/toner.png"
/>

</record>

<record id="stock_inventory_toner" model="stock.inventory">
<field name="name">Inventory for Toner</field>
<field
name="product_ids"
eval="[(4, ref('maintenance_stock.product_toner'))]"
eval="[(6,0,[ref('maintenance_stock.product_toner'),])]"
/>

</record>

<record id="stock_inventory_toner_line" model="stock.inventory.line">
Expand All @@ -58,18 +66,16 @@
<field name="product_qty">50.0</field>
<field name="location_id" ref="maintenance_stock.main_location_stock" />
</record>

<function model="stock.inventory" name="_action_start">
<function name="action_start" model="stock.inventory">
<function
eval="[[('state','=','draft'),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
eval="[[('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
model="stock.inventory"
name="search"
/>
</function>

<function model="stock.inventory" name="action_validate">
<function
eval="[[('state','=','confirm'),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
eval="[[('state','in', ['draft', 'confirm']),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
model="stock.inventory"
name="search"
/>
Expand All @@ -81,6 +87,7 @@
name="default_consumption_warehouse_id"
ref="maintenance_stock.stock_warehouse_maintenance"
/>

</record>

<record id="m_request_1" model="maintenance.request">
Expand All @@ -90,12 +97,13 @@
<field name="equipment_id" ref="maintenance.equipment_printer1" />
<field name="color">7</field>
<field name="stage_id" ref="maintenance.stage_1" />
<field
name="maintenance_team_id"
ref="maintenance.equipment_team_maintenance"
/>
</record>

</record>
<record model="stock.quant" id="stock_quant_toner">
<field name="product_id" ref="maintenance_stock.product_toner" />
<field name="location_id" ref="maintenance_stock.main_location_stock" />
<field name="quantity">1.0</field>
</record>
<record id="consuption_picking_m_request_1" model="stock.picking">
<field
name="picking_type_id"
Expand All @@ -105,6 +113,7 @@
<field name="location_id" ref="maintenance_stock.main_location_stock" />
<field name="location_dest_id" ref="maintenance_stock.main_location_cons" />
<field name="maintenance_request_id" ref="maintenance_stock.m_request_1" />

<field
name="move_lines"
model="stock.move"
Expand All @@ -116,13 +125,7 @@
'picking_type_id': ref('maintenance_stock.main_picking_type_cons'),
'location_id': ref('maintenance_stock.main_location_stock'),
'location_dest_id': ref('maintenance_stock.main_location_cons'),
'move_line_ids': [(0, 0, {
'product_id': ref('maintenance_stock.product_toner'),
'qty_done': 1,
'product_uom_id': ref('uom.product_uom_unit'),
'location_id': ref('maintenance_stock.main_location_stock'),
'location_dest_id': ref('maintenance_stock.main_location_cons'),
})],
})]"
/>
</record>
Expand All @@ -134,8 +137,14 @@
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
/>
</function>

<function model="stock.picking" name="action_done">
<function model="stock.picking" name="action_assign">
<value
model="stock.picking"
eval="[
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
/>
</function>
<function model="stock.picking" name="button_validate">
<value
model="stock.picking"
eval="[
Expand Down
17 changes: 9 additions & 8 deletions maintenance_stock/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
class MaintenanceEquipment(models.Model):
_inherit = "maintenance.equipment"

stock_picking_ids = fields.One2many(
comodel_name="stock.picking",
inverse_name="maintenance_equipment_id",
groups="stock.group_stock_user",
)
allow_consumptions = fields.Boolean(
groups="stock.group_stock_user",
)
Expand All @@ -27,7 +22,9 @@ def _onchange_allow_consumptions(self):

def action_view_stock_picking_ids(self):
self.ensure_one()
action = self.env.ref("stock.action_picking_tree_all").read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock.action_picking_tree_all"
)
action["domain"] = [("maintenance_equipment_id", "=", self.id)]
action["context"] = {
"show_maintenance_request_id": True,
Expand All @@ -36,13 +33,17 @@ def action_view_stock_picking_ids(self):

def action_view_stock_move_ids(self):
self.ensure_one()
action = self.env.ref("stock.stock_move_action").read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock.stock_move_action"
)
action["domain"] = [("maintenance_equipment_id", "=", self.id)]
return action

def action_view_stock_move_line_ids(self):
self.ensure_one()
action = self.env.ref("stock.stock_move_line_action").read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock.stock_move_line_action"
)
action["domain"] = [("maintenance_equipment_id", "=", self.id)]

# TODO Grouping by destination allows separating consumptions
Expand Down
12 changes: 9 additions & 3 deletions maintenance_stock/models/maintenance_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class MaintenanceRequest(models.Model):

def action_view_stock_picking_ids(self):
self.ensure_one()
action = self.env.ref("stock.stock_picking_action_picking_type").read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock.stock_picking_action_picking_type"
)
action["domain"] = [("maintenance_request_id", "=", self.id)]
action["context"] = {
"default_picking_type_id": self.default_consumption_warehouse_id.cons_type_id.id,
Expand All @@ -34,13 +36,17 @@ def action_view_stock_picking_ids(self):

def action_view_stock_move_ids(self):
self.ensure_one()
action = self.env.ref("stock.stock_move_action").read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock.stock_move_action"
)
action["domain"] = [("maintenance_request_id", "=", self.id)]
return action

def action_view_stock_move_line_ids(self):
self.ensure_one()
action = self.env.ref("stock.stock_move_line_action").read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock.stock_move_line_action"
)
action["domain"] = [("maintenance_request_id", "=", self.id)]

# TODO Grouping by destination allows separating consumptions
Expand Down
11 changes: 7 additions & 4 deletions maintenance_stock/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ def _create_or_update_sequences_and_picking_types(self):
# solved with a hook
if "cons_type_id" in warehouse_data:
PickingType.browse(warehouse_data["cons_type_id"]).write(
{"return_picking_type_id": warehouse_data.get("in_type_id", False),}
{
"return_picking_type_id": warehouse_data.get("in_type_id", False),
}
)
return warehouse_data

Expand All @@ -41,8 +43,9 @@ def _get_picking_type_create_values(self, max_sequence):
"use_existing_lots": True,
"default_location_src_id": self.lot_stock_id.id,
"default_location_dest_id": self.wh_cons_loc_id.id,
"sequence": max_sequence_new,
"sequence_code": max_sequence_new,
"barcode": self.code.replace(" ", "").upper() + "-CONS",
"company_id": self.company_id.id or self.env.company.id,
},
},
max_sequence_new + 1,
Expand All @@ -64,8 +67,8 @@ def _get_sequence_values(self):
},
}

def _get_locations_values(self, vals):
sub_locations = super()._get_locations_values(vals)
def _get_locations_values(self, vals, code=False):
sub_locations = super()._get_locations_values(vals, code)
code = vals.get("code") or self.code
code = code.replace(" ", "").upper()
company_id = vals.get("company_id", self.company_id.id)
Expand Down
83 changes: 24 additions & 59 deletions maintenance_stock/tests/test_maintenance_stock.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
import odoo.tests.common as test_common
from odoo.tests.common import Form


class TestMaintenanceStock(test_common.TransactionCase):
def setUp(self):
super().setUp()

self.maintenance_warehouse = self.env["stock.warehouse"].create(
{"name": "Test warehouse", "code": "TEST",}
{"name": "Test warehouse", "code": "TEST"}
{
"name": "Test warehouse",
"code": "TEST",
Expand All @@ -30,6 +28,7 @@ def setUp(self):
{
"name": "Test equipment",
"allow_consumptions": True,
"equipment_assign_to": "employee",
"default_consumption_warehouse_id": self.maintenance_warehouse.id,
}
)
Expand Down Expand Up @@ -109,61 +108,26 @@ def test_request(self):

def test_picking(self):
self.assertEqual(len(self.request_1.stock_picking_ids), 0)
self.assertEqual(len(self.equipment_1.stock_picking_ids), 0)

qty_done = 5.0
move_line_data = {
"product_id": self.product1.id,
"product_uom_id": self.env.ref("uom.product_uom_unit").id,
"qty_done": qty_done,
"location_id": self.maintenance_warehouse.lot_stock_id.id,
"location_dest_id": self.maintenance_warehouse.wh_cons_loc_id.id,
}
location_id = self.maintenance_warehouse.lot_stock_id.id
location_dest_id = self.maintenance_warehouse.wh_cons_loc_id.id
picking_type_id = self.maintenance_warehouse.cons_type_id.id
picking = self.env["stock.picking"].create(
location_id = self.maintenance_warehouse.lot_stock_id
location_dest_id = self.maintenance_warehouse.wh_cons_loc_id
picking_type_id = self.maintenance_warehouse.cons_type_id
self.env["stock.quant"].create(
{
"maintenance_request_id": self.request_1.id,
"picking_type_id": picking_type_id,
"location_id": location_id,
"location_dest_id": location_dest_id,
"move_lines": [
(
0,
0,
{
"name": "Test move",
"product_id": self.product1.id,
"product_uom": self.env.ref("uom.product_uom_unit").id,
"product_uom_qty": 5.0,
"picking_type_id": picking_type_id,
"location_id": location_id,
"location_dest_id": location_dest_id,
"move_line_ids": [
(
0,
0,
{
"product_id": self.product1.id,
"product_uom_id": self.env.ref(
"uom.product_uom_unit"
).id,
"qty_done": qty_done,
"location_id": location_id,
"location_dest_id": location_dest_id,
},
)
],
},
)
],
"product_id": self.product1.id,
"location_id": location_id.id,
"quantity": 5,
}
)

picking_form = Form(self.env["stock.picking"])
picking_form.picking_type_id = picking_type_id
picking_form.location_id = location_id
picking_form.location_dest_id = location_dest_id
with picking_form.move_ids_without_package.new() as move:
move.product_id = self.product1
move.product_uom_qty = 5.0
picking = picking_form.save()
picking.write({"maintenance_request_id": self.request_1.id})
self.assertEqual(len(self.request_1.stock_picking_ids), 1)
self.assertEqual(len(self.equipment_1.stock_picking_ids), 1)

stock_quant_obj = self.env["stock.quant"]
domain_from = [
("product_id", "=", self.product1.id),
Expand All @@ -173,11 +137,12 @@ def test_picking(self):
("product_id", "=", self.product1.id),
("location_id", "=", self.maintenance_warehouse.wh_cons_loc_id.id),
]
self.assertEqual(stock_quant_obj.search(domain_from).quantity, 0)
self.assertEqual(stock_quant_obj.search(domain_from).quantity, 5)
self.assertEqual(stock_quant_obj.search(domain_to).quantity, 0)

picking.action_confirm()
picking.action_done()

self.assertEqual(stock_quant_obj.search(domain_from).quantity, -qty_done)
self.assertEqual(stock_quant_obj.search(domain_to).quantity, qty_done)
picking.action_assign()
picking.move_line_ids.write({"qty_done": 5.0})
picking.button_validate()
self.assertEqual(stock_quant_obj.search(domain_from).quantity, 0)
self.assertEqual(stock_quant_obj.search(domain_to).quantity, 5)
2 changes: 1 addition & 1 deletion maintenance_stock/views/maintenance_request_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="inherit_id" ref="maintenance.hr_equipment_request_view_search" />
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
<field name="arch" type="xml">
<xpath expr="//filter[@name='top_priority']" position="after">
<xpath expr="//filter[@name='high_priority']" position="after">
<separator />
<filter
string="Allow Consumptions"
Expand Down
Loading

0 comments on commit b573f37

Please sign in to comment.