From ca8557ddb4e9a96c95516675c6d83c0c118b38df Mon Sep 17 00:00:00 2001 From: Christopher Ormaza Date: Tue, 5 Sep 2023 07:24:15 -0500 Subject: [PATCH 1/3] [14.0][IMP] added default operation on rma group, easy setup before rma lines created --- rma/models/rma_order.py | 5 +++++ rma/views/rma_order_view.xml | 7 +++++++ rma/wizards/rma_add_serial.py | 22 ++++++++++++---------- rma/wizards/rma_add_stock_move.py | 22 ++++++++++++---------- rma_sale/wizards/rma_add_sale.py | 6 ++++-- 5 files changed, 40 insertions(+), 22 deletions(-) diff --git a/rma/models/rma_order.py b/rma/models/rma_order.py index 576b90454..8a1182710 100644 --- a/rma/models/rma_order.py +++ b/rma/models/rma_order.py @@ -151,6 +151,11 @@ def _default_warehouse_id(self): default="draft", store=True, ) + operation_default_id = fields.Many2one( + comodel_name="rma.operation", + required=False, + string="Default Operation Type", + ) @api.constrains("partner_id", "rma_line_ids") def _check_partner_id(self): diff --git a/rma/views/rma_order_view.xml b/rma/views/rma_order_view.xml index 334366502..fa1a99d59 100644 --- a/rma/views/rma_order_view.xml +++ b/rma/views/rma_order_view.xml @@ -118,6 +118,10 @@ + + + [('type','=','supplier')] + diff --git a/rma/wizards/rma_add_serial.py b/rma/wizards/rma_add_serial.py index b06c16dea..6c13aea3e 100644 --- a/rma/wizards/rma_add_serial.py +++ b/rma/wizards/rma_add_serial.py @@ -58,16 +58,18 @@ def onchange_partner_id(self): ) def _prepare_rma_line_from_lot_vals(self, lot): - if self.env.context.get("customer"): - operation = ( - lot.product_id.rma_customer_operation_id - or lot.product_id.categ_id.rma_customer_operation_id - ) - else: - operation = ( - lot.product_id.rma_supplier_operation_id - or lot.product_id.categ_id.rma_supplier_operation_id - ) + operation = self.rma_id.operation_default_id + if not operation: + if self.env.context.get("customer"): + operation = ( + lot.product_id.rma_customer_operation_id + or lot.product_id.categ_id.rma_customer_operation_id + ) + else: + operation = ( + lot.product_id.rma_supplier_operation_id + or lot.product_id.categ_id.rma_supplier_operation_id + ) if not operation: operation = self.env["rma.operation"].search( [("type", "=", self.rma_id.type)], limit=1 diff --git a/rma/wizards/rma_add_stock_move.py b/rma/wizards/rma_add_stock_move.py index 50db2af5e..782610454 100644 --- a/rma/wizards/rma_add_stock_move.py +++ b/rma/wizards/rma_add_stock_move.py @@ -75,16 +75,18 @@ def select_all(self): } def _prepare_rma_line_from_stock_move(self, sm, lot=False): - if self.env.context.get("customer"): - operation = ( - sm.product_id.rma_customer_operation_id - or sm.product_id.categ_id.rma_customer_operation_id - ) - else: - operation = ( - sm.product_id.rma_supplier_operation_id - or sm.product_id.categ_id.rma_supplier_operation_id - ) + operation = self.rma_id.operation_default_id + if not operation: + if self.env.context.get("customer"): + operation = ( + sm.product_id.rma_customer_operation_id + or sm.product_id.categ_id.rma_customer_operation_id + ) + else: + operation = ( + sm.product_id.rma_supplier_operation_id + or sm.product_id.categ_id.rma_supplier_operation_id + ) if not operation: operation = self.env["rma.operation"].search( [("type", "=", self.rma_id.type)], limit=1 diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index c4810f1f2..ed6815405 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -85,9 +85,11 @@ def select_all(self): } def _prepare_rma_line_from_sale_order_line(self, line, lot=None): - operation = line.product_id.rma_customer_operation_id + operation = self.rma_id.operation_default_id if not operation: - operation = line.product_id.categ_id.rma_customer_operation_id + operation = line.product_id.rma_customer_operation_id + if not operation: + operation = line.product_id.categ_id.rma_customer_operation_id if not operation: operation = self.env["rma.operation"].search( [("type", "=", self.rma_id.type)], limit=1 From 8d8220284a66bb0829514b42705830d8c98ffe0d Mon Sep 17 00:00:00 2001 From: Christopher Ormaza Date: Thu, 7 Sep 2023 08:04:16 -0500 Subject: [PATCH 2/3] [IMP] added fields for default route created by wizard on rma group --- rma/models/rma_order.py | 37 +++++++++++++++++++++++++++- rma/models/rma_order_line.py | 24 ++++++++++++------ rma/views/rma_order_view.xml | 30 ++++++++++++++++++++++ rma/wizards/rma_add_serial.py | 30 ++++++++++++++-------- rma/wizards/rma_add_stock_move.py | 31 ++++++++++++++--------- rma_sale/wizards/rma_add_sale.py | 41 +++++++++++++++++-------------- 6 files changed, 146 insertions(+), 47 deletions(-) diff --git a/rma/models/rma_order.py b/rma/models/rma_order.py index 8a1182710..75eac9cb1 100644 --- a/rma/models/rma_order.py +++ b/rma/models/rma_order.py @@ -121,12 +121,32 @@ def _default_warehouse_id(self): tracking=True, default=lambda self: self.env.uid, ) + in_route_id = fields.Many2one( + "stock.location.route", + string="Inbound Route", + domain=[("rma_selectable", "=", True)], + ) + out_route_id = fields.Many2one( + "stock.location.route", + string="Outbound Route", + domain=[("rma_selectable", "=", True)], + ) in_warehouse_id = fields.Many2one( comodel_name="stock.warehouse", string="Inbound Warehouse", - required=True, + required=False, + default=_default_warehouse_id, + ) + out_warehouse_id = fields.Many2one( + comodel_name="stock.warehouse", + string="Outbound Warehouse", + required=False, default=_default_warehouse_id, ) + location_id = fields.Many2one( + comodel_name="stock.location", + string="Send To This Company Location", + ) customer_to_supplier = fields.Boolean("The customer will send to the supplier") supplier_to_customer = fields.Boolean("The supplier will send to the customer") supplier_address_id = fields.Many2one( @@ -157,6 +177,21 @@ def _default_warehouse_id(self): string="Default Operation Type", ) + @api.onchange( + "operation_default_id", + ) + def _onchange_operation(self): + if self.operation_default_id: + self.in_warehouse_id = self.operation_default_id.in_warehouse_id + self.out_warehouse_id = self.operation_default_id.out_warehouse_id + self.location_id = ( + self.operation_default_id.location_id or self.in_warehouse_id.lot_rma_id + ) + self.customer_to_supplier = self.operation_default_id.customer_to_supplier + self.supplier_to_customer = self.operation_default_id.supplier_to_customer + self.in_route_id = self.operation_default_id.in_route_id + self.out_route_id = self.operation_default_id.out_route_id + @api.constrains("partner_id", "rma_line_ids") def _check_partner_id(self): if self.rma_line_ids and self.partner_id != self.mapped( diff --git a/rma/models/rma_order_line.py b/rma/models/rma_order_line.py index 9ba20f07d..be10aeb41 100644 --- a/rma/models/rma_order_line.py +++ b/rma/models/rma_order_line.py @@ -724,15 +724,25 @@ def _onchange_operation_id(self): return result self.receipt_policy = self.operation_id.receipt_policy self.delivery_policy = self.operation_id.delivery_policy - self.in_warehouse_id = self.operation_id.in_warehouse_id - self.out_warehouse_id = self.operation_id.out_warehouse_id + self.customer_to_supplier = ( + self.rma_id.customer_to_supplier or self.operation_id.customer_to_supplier + ) + self.supplier_to_customer = ( + self.rma_id.supplier_to_customer or self.operation_id.supplier_to_customer + ) + self.in_warehouse_id = ( + self.rma_id.in_warehouse_id or self.operation_id.in_warehouse_id + ) + self.out_warehouse_id = ( + self.rma_id.out_warehouse_id or self.operation_id.out_warehouse_id + ) self.location_id = ( - self.operation_id.location_id or self.in_warehouse_id.lot_rma_id + self.rma_id.location_id + or self.operation_id.location_id + or self.in_warehouse_id.lot_rma_id ) - self.customer_to_supplier = self.operation_id.customer_to_supplier - self.supplier_to_customer = self.operation_id.supplier_to_customer - self.in_route_id = self.operation_id.in_route_id - self.out_route_id = self.operation_id.out_route_id + self.in_route_id = self.rma_id.in_route_id or self.operation_id.in_route_id + self.out_route_id = self.rma_id.out_route_id or self.operation_id.out_route_id return result @api.onchange("customer_to_supplier", "type") diff --git a/rma/views/rma_order_view.xml b/rma/views/rma_order_view.xml index fa1a99d59..49fa17c63 100644 --- a/rma/views/rma_order_view.xml +++ b/rma/views/rma_order_view.xml @@ -126,6 +126,24 @@ name="in_warehouse_id" attrs="{'readonly':[('state', '!=', 'draft')]}" /> + + + + [('type','=','supplier')] + + 1 + + + 1 + + + 0 + + + 0 + diff --git a/rma/wizards/rma_add_serial.py b/rma/wizards/rma_add_serial.py index 6c13aea3e..c935742f8 100644 --- a/rma/wizards/rma_add_serial.py +++ b/rma/wizards/rma_add_serial.py @@ -84,7 +84,11 @@ def _prepare_rma_line_from_lot_vals(self, lot): if not route: raise ValidationError(_("Please define an RMA route")) - if not operation.in_warehouse_id or not operation.out_warehouse_id: + in_warehouse = self.rma_id.in_warehouse_id or operation.in_warehouse_id + in_route = self.rma_id.in_route_id or operation.in_route_id + out_warehouse = self.rma_id.out_warehouse_id or operation.out_warehouse_id + out_route = self.rma_id.out_route_id or operation.out_route_id + if not in_warehouse or not out_warehouse: warehouse = self.env["stock.warehouse"].search( [ ("company_id", "=", self.rma_id.company_id.id), @@ -96,6 +100,16 @@ def _prepare_rma_line_from_lot_vals(self, lot): raise ValidationError( _("Please define a warehouse with a default RMA location") ) + in_warehouse = in_warehouse or warehouse + out_warehouse = out_warehouse or warehouse + location = self.rma_id.location_id + if not location: + location = ( + operation.location_id + or operation.in_warehouse_id.lot_rma_id + or in_warehouse.lot_rma_id + or out_warehouse.lot_rma_id + ) product_qty = 1 # serial if lot.product_id.tracking == "lot": @@ -114,15 +128,11 @@ def _prepare_rma_line_from_lot_vals(self, lot): "rma_id": self.rma_id.id, "receipt_policy": operation.receipt_policy, "delivery_policy": operation.delivery_policy, - "in_warehouse_id": operation.in_warehouse_id.id or warehouse.id, - "out_warehouse_id": operation.out_warehouse_id.id or warehouse.id, - "in_route_id": operation.in_route_id.id or route.id, - "out_route_id": operation.out_route_id.id or route.id, - "location_id": ( - operation.location_id.id - or operation.in_warehouse_id.lot_rma_id.id - or warehouse.lot_rma_id.id - ), + "in_warehouse_id": in_warehouse.id, + "out_warehouse_id": out_warehouse.id, + "in_route_id": in_route.id, + "out_route_id": out_route.id, + "location_id": location.id, } return vals diff --git a/rma/wizards/rma_add_stock_move.py b/rma/wizards/rma_add_stock_move.py index 782610454..170d8b14b 100644 --- a/rma/wizards/rma_add_stock_move.py +++ b/rma/wizards/rma_add_stock_move.py @@ -100,8 +100,11 @@ def _prepare_rma_line_from_stock_move(self, sm, lot=False): ) if not route: raise ValidationError(_("Please define an RMA route")) - - if not operation.in_warehouse_id or not operation.out_warehouse_id: + in_warehouse = self.rma_id.in_warehouse_id or operation.in_warehouse_id + in_route = self.rma_id.in_route_id or operation.in_route_id + out_warehouse = self.rma_id.out_warehouse_id or operation.out_warehouse_id + out_route = self.rma_id.out_route_id or operation.out_route_id + if not in_warehouse or not out_warehouse: warehouse = self.env["stock.warehouse"].search( [ ("company_id", "=", self.rma_id.company_id.id), @@ -113,6 +116,16 @@ def _prepare_rma_line_from_stock_move(self, sm, lot=False): raise ValidationError( _("Please define a warehouse with a default RMA location") ) + in_warehouse = in_warehouse or warehouse + out_warehouse = out_warehouse or warehouse + location = self.rma_id.location_id + if not location: + location = ( + operation.location_id + or operation.in_warehouse_id.lot_rma_id + or in_warehouse.lot_rma_id + or out_warehouse.lot_rma_id + ) product_qty = sm.product_uom_qty if sm.product_id.tracking == "serial": product_qty = 1 @@ -136,15 +149,11 @@ def _prepare_rma_line_from_stock_move(self, sm, lot=False): "rma_id": self.rma_id.id, "receipt_policy": operation.receipt_policy, "delivery_policy": operation.delivery_policy, - "in_warehouse_id": operation.in_warehouse_id.id or warehouse.id, - "out_warehouse_id": operation.out_warehouse_id.id or warehouse.id, - "in_route_id": operation.in_route_id.id or route.id, - "out_route_id": operation.out_route_id.id or route.id, - "location_id": ( - operation.location_id.id - or operation.in_warehouse_id.lot_rma_id.id - or warehouse.lot_rma_id.id - ), + "in_warehouse_id": in_warehouse.id, + "out_warehouse_id": out_warehouse.id, + "in_route_id": in_route.id, + "out_route_id": out_route.id, + "location_id": location.id, } return data diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index ed6815405..0005da5ac 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -102,18 +102,27 @@ def _prepare_rma_line_from_sale_order_line(self, line, lot=None): ) if not route: raise ValidationError(_("Please define an rma route")) - if not operation.in_warehouse_id or not operation.out_warehouse_id: - warehouse = self.env["stock.warehouse"].search( - [ - ("company_id", "=", self.rma_id.company_id.id), - ("lot_rma_id", "!=", False), - ], - limit=1, - ) - if not warehouse: - raise ValidationError( - _("Please define a warehouse with a " "default rma location.") + warehouse = self.rma_id.in_warehouse_id + if not warehouse: + if not operation.in_warehouse_id or not operation.out_warehouse_id: + warehouse = self.env["stock.warehouse"].search( + [ + ("company_id", "=", self.rma_id.company_id.id), + ("lot_rma_id", "!=", False), + ], + limit=1, ) + if not warehouse: + raise ValidationError( + _("Please define a warehouse with a " "default rma location.") + ) + location = self.rma_id.location_id + if not location: + location = ( + operation.location_id + or operation.in_warehouse_id.lot_rma_id + or warehouse.lot_rma_id + ) product_qty = line.product_uom_qty if line.product_id.tracking == "serial": product_qty = 1 @@ -145,15 +154,11 @@ def _prepare_rma_line_from_sale_order_line(self, line, lot=None): "in_route_id": operation.in_route_id.id or route.id, "out_route_id": operation.out_route_id.id or route.id, "receipt_policy": operation.receipt_policy, - "location_id": ( - operation.location_id.id - or operation.in_warehouse_id.lot_rma_id.id - or warehouse.lot_rma_id.id - ), + "location_id": location.id, "refund_policy": operation.refund_policy, "delivery_policy": operation.delivery_policy, - "in_warehouse_id": operation.in_warehouse_id.id or warehouse.id, - "out_warehouse_id": operation.out_warehouse_id.id or warehouse.id, + "in_warehouse_id": warehouse.id or operation.in_warehouse_id.id, + "out_warehouse_id": warehouse.id or operation.out_warehouse_id.id, } return data From f90ddc3ce864583a51f4266bf3facf50f6aab058 Mon Sep 17 00:00:00 2001 From: Christopher Ormaza Date: Tue, 19 Sep 2023 10:41:03 -0500 Subject: [PATCH 3/3] fix: get right price after create rma order line --- rma/wizards/rma_add_serial.py | 1 + rma/wizards/rma_add_stock_move.py | 1 + rma_sale/wizards/rma_add_sale.py | 1 + 3 files changed, 3 insertions(+) diff --git a/rma/wizards/rma_add_serial.py b/rma/wizards/rma_add_serial.py index c935742f8..c09fdf6af 100644 --- a/rma/wizards/rma_add_serial.py +++ b/rma/wizards/rma_add_serial.py @@ -153,4 +153,5 @@ def action_confirm(self): # favor of (pre)computed stored editable fields for all policies # and configuration in the RMA operation. rec._onchange_operation_id() + rec.price_unit = rec._get_price_unit() return {"type": "ir.actions.act_window_close"} diff --git a/rma/wizards/rma_add_stock_move.py b/rma/wizards/rma_add_stock_move.py index 170d8b14b..819255902 100644 --- a/rma/wizards/rma_add_stock_move.py +++ b/rma/wizards/rma_add_stock_move.py @@ -197,4 +197,5 @@ def add_lines(self): # favor of (pre)computed stored editable fields for all policies # and configuration in the RMA operation. rec._onchange_operation_id() + rec.price_unit = rec._get_price_unit() return {"type": "ir.actions.act_window_close"} diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index 0005da5ac..41fc7d778 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -202,6 +202,7 @@ def add_lines(self): # favor of (pre)computed stored editable fields for all policies # and configuration in the RMA operation. rec._onchange_operation_id() + rec.price_unit = rec._get_price_unit() rma = self.rma_id data_rma = self._get_rma_data() rma.write(data_rma)