From 3b5440808e8dd9a745defa6b1cd00356b35e7e64 Mon Sep 17 00:00:00 2001 From: "chafique.delli" Date: Mon, 16 Sep 2024 12:33:05 +0200 Subject: [PATCH] [ADD] smart button for sales in rma group --- rma/wizards/rma_add_stock_move.py | 2 +- rma_sale/models/rma_order.py | 20 +++++++++++++++++++- rma_sale/views/rma_order_line_view.xml | 8 ++++---- rma_sale/views/rma_order_view.xml | 24 +++++++++++++++++++++--- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/rma/wizards/rma_add_stock_move.py b/rma/wizards/rma_add_stock_move.py index 1169a104c..64fc819bf 100644 --- a/rma/wizards/rma_add_stock_move.py +++ b/rma/wizards/rma_add_stock_move.py @@ -34,7 +34,7 @@ def default_get(self, fields_list): move_ids = fields.Many2many( comodel_name="stock.move", string="Stock Moves", - domain="[('state', '=', 'done')]", + domain="[('state', '=', 'done'), ('partner_id', '=', partner_id)]", ) show_lot_filter = fields.Boolean( string="Show lot filter?", diff --git a/rma_sale/models/rma_order.py b/rma_sale/models/rma_order.py index d2e14c71f..f89243cb0 100644 --- a/rma_sale/models/rma_order.py +++ b/rma_sale/models/rma_order.py @@ -16,6 +16,16 @@ def _compute_src_sale_count(self): src_sales = rma.mapped("rma_line_ids.sale_line_id.order_id") rma.src_sale_count = len(src_sales) + @api.depends( + "rma_line_ids", + "rma_line_ids.sale_line_ids", + "rma_line_ids.sale_line_ids.order_id", + ) + def _compute_sale_count(self): + for rma in self: + sales = rma.mapped("rma_line_ids.sale_line_ids.order_id") + rma.sale_count = len(sales) + @api.depends("rma_line_ids", "rma_line_ids.qty_to_sell") def _compute_qty_to_sell(self): for rec in self: @@ -28,6 +38,7 @@ def _compute_qty_to_sell(self): digits="Product Unit of Measure", compute="_compute_qty_to_sell", ) + sale_count = fields.Integer(compute="_compute_sale_count", string="# of Sales") @api.model def _get_line_domain(self, rma_id, line): @@ -41,9 +52,16 @@ def _get_line_domain(self, rma_id, line): domain = super(RmaOrder, self)._get_line_domain(rma_id, line) return domain + def action_view_origin_sale_order(self): + action = self.env.ref("sale.action_orders") + result = action.sudo().read()[0] + so_ids = self.mapped("rma_line_ids.sale_line_id.order_id").ids + result["domain"] = [("id", "in", so_ids)] + return result + def action_view_sale_order(self): action = self.env.ref("sale.action_quotations") result = action.sudo().read()[0] - so_ids = self.mapped("rma_line_ids.sale_line_id.order_id").ids + so_ids = self.mapped("rma_line_ids.sale_line_ids.order_id").ids result["domain"] = [("id", "in", so_ids)] return result diff --git a/rma_sale/views/rma_order_line_view.xml b/rma_sale/views/rma_order_line_view.xml index 84c38fbb4..1f73791d2 100644 --- a/rma_sale/views/rma_order_line_view.xml +++ b/rma_sale/views/rma_order_line_view.xml @@ -22,15 +22,15 @@ />
- + +