Merge PR #445 into 17.0

Signed-off-by pedrobaeza
This commit is contained in:
OCA-git-bot
2025-02-12 14:05:53 +00:00

View File

@@ -1,11 +1,14 @@
# Copyright 2020 Tecnativa - Ernesto Tejeda
# Copyright 2023 Tecnativa - Pedro M. Baeza
# Copyright 2023 Michael Tietz (MT Software) <mtietz@mt-software.de>
# Copyright 2025 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from collections import defaultdict
from itertools import groupby
from markupsafe import Markup
from odoo import _, api, fields, models
from odoo.exceptions import AccessError, ValidationError
from odoo.tools import html2plaintext
@@ -303,16 +306,10 @@ class Rma(models.Model):
@api.depends("product_uom_qty", "delivered_qty")
def _compute_remaining_qty(self):
"""Compute 'remaining_qty' and 'remaining_qty_to_done' fields.
"""Compute 'remaining_qty' field.
remaining_qty: is used to set a default quantity of replacing
or returning of product to the customer.
remaining_qty_to_done: the aim of this field to control when the
RMA cam be set to 'delivered' state. An RMA with
remaining_qty_to_done <= 0 can be set to 'delivery'. It is used
in stock.move._action_done method of stock.move and
rma.extract_quantity.
"""
for r in self:
r.remaining_qty = r.product_uom_qty - r.delivered_qty
@@ -377,7 +374,7 @@ class Rma(models.Model):
for r in self:
if r.product_uom_qty > 1 and (
(r.state == "waiting_return" and r.remaining_qty > 0)
or (r.state == "waiting_replacement" and r.remaining_qty_to_done > 0)
or (r.state == "waiting_replacement" and r.remaining_qty > 0)
):
r.can_be_split = True
else:
@@ -981,11 +978,13 @@ class Rma(models.Model):
subtype_id=self.env["ir.model.data"]._xmlid_to_res_id("mail.mt_note"),
)
self.message_post(
body=_(
'Split: <a href="#" data-oe-model="rma" '
'data-oe-id="%(id)d">%(name)s</a> has been created.'
body=Markup(
_(
'Split: <a href="#" data-oe-model="rma" '
'data-oe-id="%(id)d">%(name)s</a> has been created.'
)
% ({"id": extracted_rma.id, "name": extracted_rma.name})
)
% ({"id": extracted_rma.id, "name": extracted_rma.name})
)
return extracted_rma
@@ -1115,11 +1114,13 @@ class Rma(models.Model):
picking = rma.delivery_move_ids.picking_id.sorted("id", reverse=True)[0]
pickings[picking] |= rma
rma.message_post(
body=_(
'Return: <a href="#" data-oe-model="stock.picking" '
'data-oe-id="%(id)d">%(name)s</a> has been created.'
body=Markup(
_(
'Return: <a href="#" data-oe-model="stock.picking" '
'data-oe-id="%(id)d">%(name)s</a> has been created.'
)
% ({"id": picking.id, "name": picking.name})
)
% ({"id": picking.id, "name": picking.name})
)
for picking, rmas in pickings.items():
picking.action_confirm()
@@ -1183,7 +1184,7 @@ class Rma(models.Model):
# The product replacement could explode into several moves like in the case of
# MRP BoM Kits
for new_move in new_moves:
body += (
body += Markup(
_(
'Replacement: Move <a href="#" data-oe-model="stock.move"'
' data-oe-id="%(move_id)d">%(move_name)s</a> (Picking <a'
@@ -1209,21 +1210,23 @@ class Rma(models.Model):
self.ensure_one()
self.message_post(
body=body
or _(
"Replacement:<br/>"
'Product <a href="#" data-oe-model="product.product" '
'data-oe-id="%(id)d">%(name)s</a><br/>'
"Quantity %(qty)s %(uom)s<br/>"
"This replacement did not create a new move, but one of "
"the previously created moves was updated with this data."
)
% (
{
"id": self.id,
"name": self.display_name,
"qty": qty,
"uom": uom.name,
}
or Markup(
_(
"Replacement:<br/>"
'Product <a href="#" data-oe-model="product.product" '
'data-oe-id="%(id)d">%(name)s</a><br/>'
"Quantity %(qty)s %(uom)s<br/>"
"This replacement did not create a new move, but one of "
"the previously created moves was updated with this data."
)
% (
{
"id": self.product_id.id,
"name": self.product_id.display_name,
"qty": qty,
"uom": uom.name,
}
)
)
)