Files
stock-rma/rma_scrap/models/rma_order.py
2024-11-29 09:05:06 +05:30

32 lines
1.1 KiB
Python

# Copyright 2022 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import fields, models
class RmaOrder(models.Model):
_inherit = "rma.order"
def _compute_scrap_count(self):
for order in self:
moves = (
order.mapped("rma_line_ids.move_ids")
.filtered(lambda m: m.is_rma_scrap)
.move_line_ids
)
order.scrap_count = len(moves)
scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scrap")
def action_view_scrap_transfers(self):
self.ensure_one()
action = self.env.ref("stock.action_stock_scrap")
result = action.sudo().read()[0]
scraps = self.env["stock.scrap"].search([("origin", "=", self.name)])
if len(scraps) > 1:
result["domain"] = [("id", "in", scraps.ids)]
elif len(scraps) == 1:
res = self.env.ref("stock.stock_scrap_form_view", False)
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = scraps.ids[0]
return result