Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
6
maintenance_stock/models/__init__.py
Normal file
6
maintenance_stock/models/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from . import maintenance_equipment
|
||||
from . import maintenance_request
|
||||
from . import stock_move
|
||||
from . import stock_move_line
|
||||
from . import stock_picking
|
||||
from . import stock_warehouse
|
||||
65
maintenance_stock/models/maintenance_equipment.py
Normal file
65
maintenance_stock/models/maintenance_equipment.py
Normal file
@@ -0,0 +1,65 @@
|
||||
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class MaintenanceEquipment(models.Model):
|
||||
_inherit = "maintenance.equipment"
|
||||
|
||||
allow_consumptions = fields.Boolean(
|
||||
groups="stock.group_stock_user",
|
||||
)
|
||||
default_consumption_warehouse_id = fields.Many2one(
|
||||
string="Default Consumption Warehouse",
|
||||
comodel_name="stock.warehouse",
|
||||
groups="stock.group_stock_user",
|
||||
)
|
||||
|
||||
@api.onchange("allow_consumptions")
|
||||
def _onchange_allow_consumptions(self):
|
||||
if not self.allow_consumptions:
|
||||
self.default_consumption_warehouse_id = False
|
||||
|
||||
def action_view_stock_picking_ids(self):
|
||||
self.ensure_one()
|
||||
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,
|
||||
}
|
||||
return action
|
||||
|
||||
def action_view_stock_move_ids(self):
|
||||
self.ensure_one()
|
||||
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["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
|
||||
# and returns. Look for a better system and remove this
|
||||
show_groupby_to = (
|
||||
len(
|
||||
self.env["stock.move.line"]
|
||||
.search([("maintenance_equipment_id", "=", self.id)])
|
||||
.mapped("location_dest_id")
|
||||
)
|
||||
> 1
|
||||
)
|
||||
|
||||
action["context"] = {
|
||||
"search_default_done": 1,
|
||||
"search_default_groupby_location_dest_id": show_groupby_to,
|
||||
"search_default_groupby_product_id": 1,
|
||||
}
|
||||
return action
|
||||
69
maintenance_stock/models/maintenance_request.py
Normal file
69
maintenance_stock/models/maintenance_request.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class MaintenanceRequest(models.Model):
|
||||
_inherit = "maintenance.request"
|
||||
|
||||
allow_consumptions = fields.Boolean(
|
||||
related="equipment_id.allow_consumptions",
|
||||
store=True,
|
||||
groups="stock.group_stock_user",
|
||||
)
|
||||
default_consumption_warehouse_id = fields.Many2one(
|
||||
related="equipment_id.default_consumption_warehouse_id",
|
||||
groups="stock.group_stock_user",
|
||||
)
|
||||
stock_picking_ids = fields.One2many(
|
||||
string="Picking list",
|
||||
comodel_name="stock.picking",
|
||||
inverse_name="maintenance_request_id",
|
||||
groups="stock.group_stock_user",
|
||||
)
|
||||
|
||||
def action_view_stock_picking_ids(self):
|
||||
self.ensure_one()
|
||||
action = self.env["ir.actions.act_window"]._for_xml_id(
|
||||
"stock.stock_picking_action_picking_type"
|
||||
)
|
||||
action["domain"] = [("maintenance_request_id", "=", self.id)]
|
||||
cons_type = self.default_consumption_warehouse_id.cons_type_id
|
||||
action["context"] = {
|
||||
"default_picking_type_id": cons_type.id,
|
||||
"default_maintenance_request_id": self.id,
|
||||
}
|
||||
return action
|
||||
|
||||
def action_view_stock_move_ids(self):
|
||||
self.ensure_one()
|
||||
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["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
|
||||
# and returns. Look for a better system and remove this
|
||||
show_groupby_to = (
|
||||
len(
|
||||
self.env["stock.move.line"]
|
||||
.search([("maintenance_request_id", "=", self.id)])
|
||||
.mapped("location_dest_id")
|
||||
)
|
||||
> 1
|
||||
)
|
||||
|
||||
action["context"] = {
|
||||
"search_default_done": 1,
|
||||
"search_default_groupby_location_dest_id": show_groupby_to,
|
||||
"search_default_groupby_product_id": 1,
|
||||
}
|
||||
return action
|
||||
16
maintenance_stock/models/stock_move.py
Normal file
16
maintenance_stock/models/stock_move.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = "stock.move"
|
||||
|
||||
maintenance_request_id = fields.Many2one(
|
||||
comodel_name="maintenance.request",
|
||||
related="picking_id.maintenance_request_id",
|
||||
)
|
||||
maintenance_equipment_id = fields.Many2one(
|
||||
comodel_name="maintenance.equipment",
|
||||
related="picking_id.maintenance_equipment_id",
|
||||
)
|
||||
16
maintenance_stock/models/stock_move_line.py
Normal file
16
maintenance_stock/models/stock_move_line.py
Normal file
@@ -0,0 +1,16 @@
|
||||
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class StockMoveLine(models.Model):
|
||||
_inherit = "stock.move.line"
|
||||
|
||||
maintenance_request_id = fields.Many2one(
|
||||
comodel_name="maintenance.request",
|
||||
related="picking_id.maintenance_request_id",
|
||||
)
|
||||
maintenance_equipment_id = fields.Many2one(
|
||||
comodel_name="maintenance.equipment",
|
||||
related="picking_id.maintenance_equipment_id",
|
||||
)
|
||||
17
maintenance_stock/models/stock_picking.py
Normal file
17
maintenance_stock/models/stock_picking.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = "stock.picking"
|
||||
|
||||
maintenance_request_id = fields.Many2one(
|
||||
comodel_name="maintenance.request",
|
||||
index=True,
|
||||
)
|
||||
maintenance_equipment_id = fields.Many2one(
|
||||
comodel_name="maintenance.equipment",
|
||||
related="maintenance_request_id.equipment_id",
|
||||
store=True,
|
||||
)
|
||||
82
maintenance_stock/models/stock_warehouse.py
Normal file
82
maintenance_stock/models/stock_warehouse.py
Normal file
@@ -0,0 +1,82 @@
|
||||
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
from odoo import _, fields, models
|
||||
|
||||
|
||||
class StockWarehouse(models.Model):
|
||||
_inherit = "stock.warehouse"
|
||||
|
||||
wh_cons_loc_id = fields.Many2one(
|
||||
"stock.location", "Consumption Location", domain=[("usage", "=", "inventory")]
|
||||
)
|
||||
cons_type_id = fields.Many2one("stock.picking.type", "Consumption Type")
|
||||
|
||||
def _create_or_update_sequences_and_picking_types(self):
|
||||
warehouse_data = super()._create_or_update_sequences_and_picking_types()
|
||||
PickingType = self.env["stock.picking.type"]
|
||||
|
||||
# TODO when is called for an existing warehouse (e.g. during the
|
||||
# module installation in_type_id is not accesible). Temporary
|
||||
# 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 warehouse_data
|
||||
|
||||
def _update_name_and_code(self, new_name=False, new_code=False):
|
||||
for warehouse in self:
|
||||
sequence_data = warehouse._get_sequence_values()
|
||||
warehouse.cons_type_id.sequence_id.write(sequence_data["cons_type_id"])
|
||||
|
||||
def _get_picking_type_create_values(self, max_sequence):
|
||||
data, max_sequence_new = super()._get_picking_type_create_values(max_sequence)
|
||||
return (
|
||||
{
|
||||
**data,
|
||||
"cons_type_id": {
|
||||
"name": _("Consumption"),
|
||||
"code": "outgoing",
|
||||
"use_create_lots": False,
|
||||
"use_existing_lots": True,
|
||||
"default_location_src_id": self.lot_stock_id.id,
|
||||
"default_location_dest_id": self.wh_cons_loc_id.id,
|
||||
"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,
|
||||
)
|
||||
|
||||
def _get_picking_type_update_values(self):
|
||||
data = super()._get_picking_type_update_values()
|
||||
return {**data, "cons_type_id": {}}
|
||||
|
||||
def _get_sequence_values(self, name=False, code=False):
|
||||
data = super()._get_sequence_values(name=name, code=code)
|
||||
return {
|
||||
**data,
|
||||
"cons_type_id": {
|
||||
"name": self.name + " " + _("Sequence consumption"),
|
||||
"prefix": self.code + "/CONS/",
|
||||
"padding": 5,
|
||||
"company_id": self.company_id.id,
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
return {
|
||||
**sub_locations,
|
||||
"wh_cons_loc_id": {
|
||||
"name": _("Consumptions"),
|
||||
"usage": "inventory",
|
||||
"barcode": self._valid_barcode(code + "-CONS", company_id),
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user