Skip to content

Commit

Permalink
[FIX] stock_picking_create_repair: new way to access actions
Browse files Browse the repository at this point in the history
  • Loading branch information
oihane committed Jan 13, 2025
1 parent 403c833 commit 369cd7f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 43 deletions.
22 changes: 14 additions & 8 deletions stock_picking_create_repair/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
class AccountMove(models.Model):
_inherit = "account.move"

is_repair = fields.Boolean(string="Is repair", compute="_compute_is_repair")
is_repair = fields.Boolean(
string="Is repair",
compute="_compute_is_repair",
)
amount_total_products_rmas = fields.Monetary(
string="Amount repair orders",
currency_field="currency_id",
Expand All @@ -21,7 +24,10 @@ class AccountMove(models.Model):
copy=False,
)
count_repairs = fields.Integer(
string="Num. repairs", compute="_compute_count_repairs", store=True, copy=False
string="Num. repairs",
compute="_compute_count_repairs",
store=True,
copy=False,
)

def _compute_is_repair(self):
Expand Down Expand Up @@ -58,16 +64,16 @@ def unlink(self):

def action_repairs_from_sale(self):
self.ensure_one()
action = self.env.ref("repair.action_repair_order_tree")
action_dict = action.read()[0] if action else {}
domain = expression.AND(
action = self.env["ir.actions.actions"]._for_xml_id(
"repair.action_repair_order_tree"
)
action["domain"] = expression.AND(
[
[("id", "in", self.repair_ids.ids)],
safe_eval(action.domain or "[]"),
safe_eval(action.get("domain") or "[]"),
]
)
action_dict.update({"domain": domain})
return action_dict
return action

def get_rma_to_print(self):
repairs = ""
Expand Down
48 changes: 24 additions & 24 deletions stock_picking_create_repair/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,57 +100,57 @@ def _compute_count_pending_repairs(self):

def action_devolution_picking_repairs_from_sale(self):
self.ensure_one()
action = self.env.ref("stock.stock_picking_action_picking_type")
action_dict = action.read()[0] if action else {}
domain = expression.AND(
action = self.env["ir.actions.actions"]._for_xml_id(
"stock.stock_picking_action_picking_type"
)
action["domain"] = expression.AND(
[
[("id", "in", self.repair_devolution_picking_ids.ids)],
safe_eval(action.domain or "[]"),
safe_eval(action.get("domain") or "[]"),
]
)
action_dict.update({"domain": domain})
return action_dict
return action

def action_in_picking_repairs_from_sale(self):
self.ensure_one()
pickings = self._search_pickings_repair(self.type_id.picking_type_repair_in_id)
action = self.env.ref("stock.stock_picking_action_picking_type")
action_dict = action.read()[0] if action else {}
domain = expression.AND(
action = self.env["ir.actions.actions"]._for_xml_id(
"stock.stock_picking_action_picking_type"
)
action["domain"] = expression.AND(
[
[("id", "in", pickings.ids)],
safe_eval(action.domain or "[]"),
safe_eval(action.get("domain") or "[]"),
]
)
action_dict.update({"domain": domain})
return action_dict
return action

def action_out_picking_repairs_from_sale(self):
self.ensure_one()
pickings = self._search_pickings_repair(self.type_id.picking_type_repair_out_id)
action = self.env.ref("stock.stock_picking_action_picking_type")
action_dict = action.read()[0] if action else {}
domain = expression.AND(
action = self.env["ir.actions.actions"]._for_xml_id(
"stock.stock_picking_action_picking_type"
)
action["domain"] = expression.AND(
[
[("id", "in", pickings.ids)],
safe_eval(action.domain or "[]"),
safe_eval(action.get("domain") or "[]"),
]
)
action_dict.update({"domain": domain})
return action_dict
return action

def action_repairs_from_sale(self):
self.ensure_one()
action = self.env.ref("repair.action_repair_order_tree")
action_dict = action.read()[0] if action else {}
domain = expression.AND(
action = self.env["ir.actions.actions"]._for_xml_id(
"repair.action_repair_order_tree"
)
action["domain"] = expression.AND(
[
[("id", "in", self.repair_ids.ids)],
safe_eval(action.domain or "[]"),
safe_eval(action.get("domain") or "[]"),
]
)
action_dict.update({"domain": domain})
return action_dict
return action

def _search_pickings_repair(self, picking_type):
cond = [
Expand Down
36 changes: 25 additions & 11 deletions stock_picking_create_repair/models/stock_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,36 @@
class StockPicking(models.Model):
_inherit = "stock.picking"

is_repair = fields.Boolean(string="It's repair", default=False, copy=True)
is_repair = fields.Boolean(
string="It's repair",
default=False,
copy=True,
)
created_repair_ids = fields.One2many(
string="Created repairs",
comodel_name="repair.order",
inverse_name="created_from_picking_id",
copy=True,
)
repairs_count = fields.Integer(
string="# Repairs", compute="_compute_repairs_count", store=True, copy=True
string="# Repairs",
compute="_compute_repairs_count",
store=True,
copy=True,
)
sale_order_id = fields.Many2one(
string="Sale order", comodel_name="sale.order", copy=True
string="Sale order",
comodel_name="sale.order",
copy=True,
)
untreated_origin = fields.Char(
string="Untreated origin",
copy=True,
)
untreated_origin = fields.Char(string="Untreated origin", copy=True)
devolution_sale_order_id = fields.Many2one(
string="Sale order", comodel_name="sale.order", copy=True
string="Sale order",
comodel_name="sale.order",
copy=True,
)

@api.depends("created_repair_ids")
Expand Down Expand Up @@ -62,16 +76,16 @@ def create_repairs_from_picking(self):

def action_repairs_from_picking(self):
self.ensure_one()
action = self.env.ref("repair.action_repair_order_tree")
action_dict = action.read()[0] if action else {}
domain = expression.AND(
action = self.env["ir.actions.actions"]._for_xml_id(
"repair.action_repair_order_tree"
)
action["domain"] = expression.AND(
[
[("id", "in", self.created_repair_ids.ids)],
safe_eval(action.domain or "[]"),
safe_eval(action.get("domain") or "[]"),
]
)
action_dict.update({"domain": domain})
return action_dict
return action

def action_assign(self):
for picking in self:
Expand Down

0 comments on commit 369cd7f

Please sign in to comment.