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 Jan 29, 2024
1 parent b6a5612 commit 07b3541
Show file tree
Hide file tree
Showing 10 changed files with 195 additions and 213 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,
}
267 changes: 135 additions & 132 deletions maintenance_stock/data/demo_maintenance_stock.xml
Original file line number Diff line number Diff line change
@@ -1,147 +1,150 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data noupdate="1">
<odoo noupdate="1">
<record id="location_inventory" model="stock.location">
<field name="name">Inventory adjustment</field>
<field name="usage">inventory</field>

<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>
</record>
</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">
<value
model="base"
eval="[{
'xml_id': 'maintenance_stock.main_picking_type_cons',
'record': obj().env.ref('maintenance_stock.stock_warehouse_maintenance').cons_type_id,
'noupdate': True,
}, {
'xml_id': 'maintenance_stock.main_location_stock',
'record': obj().env.ref('maintenance_stock.stock_warehouse_maintenance').lot_stock_id,
'noupdate': True,
}, {
'xml_id': 'maintenance_stock.main_location_cons',
'record': obj().env.ref('maintenance_stock.stock_warehouse_maintenance').wh_cons_loc_id,
'noupdate': True,
}]"
/>
</function>
<function model="ir.model.data" name="_update_xmlids">
<value
model="base"
eval="[{
'xml_id': 'maintenance_stock.main_picking_type_cons',
'record': obj().env.ref('maintenance_stock.stock_warehouse_maintenance').cons_type_id,
'noupdate': True,
}, {
'xml_id': 'maintenance_stock.main_location_stock',
'record': obj().env.ref('maintenance_stock.stock_warehouse_maintenance').lot_stock_id,
'noupdate': True,
}, {
'xml_id': 'maintenance_stock.main_location_cons',
'record': obj().env.ref('maintenance_stock.stock_warehouse_maintenance').wh_cons_loc_id,
'noupdate': True,
}]"
/>
</function>

<record id="product_toner" model="product.product">
<field name="default_code">TON_1234</field>
<field name="name">Toner</field>
<field name="type">product</field>
<field name="categ_id" ref="product.product_category_5" />
<field name="lst_price">100.0</field>
<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="image"
type="base64"
file="maintenance_stock/static/img/toner.png"
/>
</record>
<record id="product_toner" model="product.product">
<field name="default_code">TON_1234</field>
<field name="name">Toner</field>
<field name="type">product</field>
<field name="categ_id" ref="product.product_category_5" />
<field name="lst_price">100.0</field>
<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="image_1920"
type="base64"
file="maintenance_stock/static/img/toner.png"
/>

<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'))]"
/>
</record>
</record>

<record id="stock_inventory_toner_line" model="stock.inventory.line">
<field name="product_id" ref="maintenance_stock.product_toner" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="maintenance_stock.stock_inventory_toner" />
<field name="product_qty">50.0</field>
<field name="location_id" ref="maintenance_stock.main_location_stock" />
</record>
<record id="stock_inventory_toner" model="stock.inventory">
<field name="name">Inventory for Toner</field>
<field
name="product_ids"
eval="[(6,0,[ref('maintenance_stock.product_toner'),])]"
/>

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

<function model="stock.inventory" name="action_validate">
<function
eval="[[('state','=','confirm'),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
model="stock.inventory"
name="search"
/>
</function>
<record id="stock_inventory_toner_line" model="stock.inventory.line">
<field name="product_id" ref="maintenance_stock.product_toner" />
<field name="product_uom_id" ref="uom.product_uom_unit" />
<field name="inventory_id" ref="maintenance_stock.stock_inventory_toner" />
<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','in', ['draft', 'confirm']),('id', '=', ref('maintenance_stock.stock_inventory_toner'))]]"
model="stock.inventory"
name="search"
/>
</function>

<record id="maintenance.equipment_printer1" model="maintenance.equipment">
<field name="allow_consumptions" eval="True" />
<field
name="default_consumption_warehouse_id"
ref="maintenance_stock.stock_warehouse_maintenance"
/>
</record>
<record id="maintenance.equipment_printer1" model="maintenance.equipment">
<field name="allow_consumptions" eval="True" />
<field
name="default_consumption_warehouse_id"
ref="maintenance_stock.stock_warehouse_maintenance"
/>

<record id="m_request_1" model="maintenance.request">
<field name="name">Change toner</field>
<field name="user_id" ref="base.user_demo" />
<field name="owner_user_id" ref="base.user_admin" />
<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 id="consuption_picking_m_request_1" model="stock.picking">
<field
name="picking_type_id"
ref="maintenance_stock.main_picking_type_cons"
/>
<field name="date" eval="DateTime.today() - timedelta(days=15)" />
<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"
eval="[(0, 0, {
'name': obj().env.ref('maintenance_stock.product_toner').name,
'product_id': ref('maintenance_stock.product_toner'),
'product_uom': ref('uom.product_uom_unit'),
'product_uom_qty': 1.0,
'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>
<record id="m_request_1" model="maintenance.request">
<field name="name">Change toner</field>
<field name="user_id" ref="base.user_demo" />
<field name="owner_user_id" ref="base.user_admin" />
<field name="equipment_id" ref="maintenance.equipment_printer1" />
<field name="color">7</field>
<field name="stage_id" ref="maintenance.stage_1" />

<function model="stock.picking" name="action_confirm">
<value
model="stock.picking"
eval="[
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
/>
</function>
</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" ref="maintenance_stock.main_picking_type_cons" />
<field name="date" eval="DateTime.today() - timedelta(days=15)" />
<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" />

<function model="stock.picking" name="action_done">
<value
model="stock.picking"
eval="[
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
/>
</function>
<field
name="move_lines"
model="stock.move"
eval="[(0, 0, {
'name': obj().env.ref('maintenance_stock.product_toner').name,
'product_id': ref('maintenance_stock.product_toner'),
'product_uom': ref('uom.product_uom_unit'),
'product_uom_qty': 1.0,
'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'),
</data>
})]"
/>
</record>

<function model="stock.picking" name="action_confirm">
<value
model="stock.picking"
eval="[
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
/>
</function>
<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="[
obj().env.ref('maintenance_stock.consuption_picking_m_request_1').id]"
/>
</function>
</odoo>
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
Loading

0 comments on commit 07b3541

Please sign in to comment.