diff --git a/rma_sale/models/__init__.py b/rma_sale/models/__init__.py
index c0f8b897..162f1ebd 100644
--- a/rma_sale/models/__init__.py
+++ b/rma_sale/models/__init__.py
@@ -1,6 +1,7 @@
# Copyright 2020 ForgeFlow S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from . import sale_order_line
+from . import sale_order
from . import rma_order_line
from . import rma_order
from . import rma_operation
diff --git a/rma_sale/models/sale_order.py b/rma_sale/models/sale_order.py
new file mode 100644
index 00000000..6c6960f5
--- /dev/null
+++ b/rma_sale/models/sale_order.py
@@ -0,0 +1,36 @@
+# Copyright 2017 Eficent Business and IT Consulting Services S.L.
+# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
+from odoo import fields, models
+
+
+class SaleOrder(models.Model):
+ _inherit = "sale.order"
+
+ rma_line_ids = fields.One2many(
+ comodel_name="rma.order.line", compute="_compute_rma_line"
+ )
+
+ rma_count = fields.Integer(compute="_compute_rma_count", string="# of RMA")
+
+ def _compute_rma_count(self):
+ for so in self:
+ rmas = self.mapped("rma_line_ids")
+ so.rma_count = len(rmas)
+
+ def _compute_rma_line(self):
+ for so in self:
+ so.rma_line_ids = so.mapped("order_line.rma_line_id")
+
+ def action_view_rma(self):
+ action = self.env.ref("rma.action_rma_customer_lines")
+ result = action.read()[0]
+ rma_ids = self.mapped("rma_line_ids").ids
+ if rma_ids:
+ # choose the view_mode accordingly
+ if len(rma_ids) > 1:
+ result["domain"] = [("id", "in", rma_ids)]
+ else:
+ res = self.env.ref("rma.view_rma_line_form", False)
+ result["views"] = [(res and res.id or False, "form")]
+ result["res_id"] = rma_ids[0]
+ return result
diff --git a/rma_sale/views/sale_order_view.xml b/rma_sale/views/sale_order_view.xml
index f45b0852..3bbdecbf 100644
--- a/rma_sale/views/sale_order_view.xml
+++ b/rma_sale/views/sale_order_view.xml
@@ -14,4 +14,27 @@
+
+
+
+
+ sale.order.form.sale.rma
+ sale.order
+
+
+
+
+
+
+
+
+
+
diff --git a/rma_sale/wizards/rma_order_line_make_sale_order.py b/rma_sale/wizards/rma_order_line_make_sale_order.py
index b8f2c420..9368251a 100644
--- a/rma_sale/wizards/rma_order_line_make_sale_order.py
+++ b/rma_sale/wizards/rma_order_line_make_sale_order.py
@@ -18,7 +18,9 @@ class RmaLineMakeSaleOrder(models.TransientModel):
comodel_name="rma.order.line.make.sale.order.item",
inverse_name="wiz_id",
string="Items",
+ readonly=False,
)
+
sale_order_id = fields.Many2one(
comodel_name="sale.order",
string="Sales Order",
@@ -67,16 +69,17 @@ class RmaLineMakeSaleOrder(models.TransientModel):
return res
@api.model
- def _prepare_sale_order(self, out_warehouse, company, item):
+ def _prepare_sale_order(self, line):
if not self.partner_id:
raise exceptions.Warning(_("Enter a customer."))
customer = self.partner_id
data = {
- "origin": item.line_id.name,
+ "origin": line.name,
"partner_id": customer.id,
- "warehouse_id": out_warehouse.id,
- "company_id": company.id,
+ "warehouse_id": line.out_warehouse_id.id,
+ "company_id": line.company_id.id,
}
+
return data
@api.model
@@ -108,10 +111,9 @@ class RmaLineMakeSaleOrder(models.TransientModel):
if self.sale_order_id:
sale = self.sale_order_id
if not sale:
- po_data = self._prepare_sale_order(
- line.out_warehouse_id, line.company_id, item
- )
+ po_data = self._prepare_sale_order(line)
sale = sale_obj.create(po_data)
+ sale.name = sale.name + " - " + line.name
so_line_data = self._prepare_sale_order_line(sale, item)
so_line_obj.create(so_line_data)
@@ -130,7 +132,9 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
wiz_id = fields.Many2one(
comodel_name="rma.order.line.make.sale.order", string="Wizard"
)
- line_id = fields.Many2one(comodel_name="rma.order.line", string="RMA Line")
+ line_id = fields.Many2one(
+ comodel_name="rma.order.line", string="RMA Line", compute="_compute_line_id"
+ )
rma_id = fields.Many2one(
comodel_name="rma.order", related="line_id.rma_id", readonly=False
)
@@ -142,3 +146,17 @@ class RmaLineMakeSaleOrderItem(models.TransientModel):
comodel_name="stock.warehouse", string="Outbound Warehouse"
)
free_of_charge = fields.Boolean(string="Free of Charge")
+
+ def _compute_line_id(self):
+ rma_line_obj = self.env["rma.order.line"]
+ for rec in self:
+ if not self.env.context["active_ids"]:
+ return
+ rma_line_ids = self.env.context["active_ids"] or []
+ lines = rma_line_obj.browse(rma_line_ids)
+ rec.line_id = lines[0]
+
+ @api.onchange("product_id")
+ def onchange_product_id(self):
+ if self.product_id:
+ self.name = self.product_id.name
diff --git a/rma_sale/wizards/rma_order_line_make_sale_order_view.xml b/rma_sale/wizards/rma_order_line_make_sale_order_view.xml
index 56d987ca..fdbba6a2 100644
--- a/rma_sale/wizards/rma_order_line_make_sale_order_view.xml
+++ b/rma_sale/wizards/rma_order_line_make_sale_order_view.xml
@@ -26,9 +26,10 @@
-
+
+
+ invisible="True"/>