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 Jul 7, 2023
1 parent d9982de commit bc0a774
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 81 deletions.
2 changes: 1 addition & 1 deletion maintenance_stock/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"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"],
Expand Down
57 changes: 37 additions & 20 deletions maintenance_stock/data/demo_maintenance_stock.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?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="company_id" ref="stock.res_company_1" />

<field name="code">Main</field>
</record>

Expand Down Expand Up @@ -37,18 +41,22 @@
<field name="standard_price">70.0</field>
<field name="uom_id" ref="uom.product_uom_unit" />
<field name="uom_po_id" ref="uom.product_uom_unit" />
<field name="property_stock_inventory" ref="stock.location_inventory" />

<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="filter">product</field>
<field name="product_id" ref="maintenance_stock.product_toner" />
<field
name="product_ids"
eval="[(6,0,[ref('maintenance_stock.product_toner'),])]"
/>

</record>

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

<function name="action_start" model="stock.inventory">
<function
eval="[[('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
model="stock.inventory"
name="search"
/>
</function>
<function model="stock.inventory" name="action_validate">
<function
eval="[[('state','=','draft'),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
Expand All @@ -73,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 @@ -82,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 @@ -97,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 @@ -108,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 @@ -126,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
5 changes: 0 additions & 5 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 Down
74 changes: 24 additions & 50 deletions maintenance_stock/tests/test_maintenance_stock.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# © 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",
Expand All @@ -28,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 @@ -107,54 +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
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 @@ -164,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
1 change: 0 additions & 1 deletion maintenance_stock/views/stock_move_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<field name="name">Product Moves</field>
<field name="res_model">stock.move.line</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">tree,kanban,pivot,form</field>
<field name="view_id" ref="stock.view_move_line_tree" />
<field name="domain">[('maintenance_request_id', '!=', False)]</field>
Expand Down
3 changes: 1 addition & 2 deletions maintenance_stock/views/stock_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@
</xpath>
</field>
</record>

<record id="stock_move_action" model="ir.actions.act_window">
<field name="name">Stock Moves</field>
<field name="res_model">stock.move</field>
<field name="type">ir.actions.act_window</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="stock.view_move_tree" />
<field name="search_view_id" ref="stock.view_move_search" />
<field name="domain">[('maintenance_request_id', '!=', False)]</field>
Expand Down
2 changes: 1 addition & 1 deletion maintenance_stock/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_internal_search" />
<field name="arch" type="xml">
<xpath expr="//field[@name='group_id']" position="after">
<xpath expr="//field[@name='picking_type_id']" position="after">
<field name="maintenance_equipment_id" />
<field name="maintenance_request_id" />
</xpath>
Expand Down

0 comments on commit bc0a774

Please sign in to comment.