diff --git a/rma_sale/wizards/rma_add_sale.py b/rma_sale/wizards/rma_add_sale.py index a1d034298..1adcd1f57 100644 --- a/rma_sale/wizards/rma_add_sale.py +++ b/rma_sale/wizards/rma_add_sale.py @@ -83,9 +83,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 @@ -98,18 +100,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 @@ -141,15 +152,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 @@ -193,6 +200,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)