Skip to content

Commit

Permalink
[14.0][IMP] added default operation on rma group, easy setup before r…
Browse files Browse the repository at this point in the history
…ma lines created (#452)

* [14.0][IMP] added default operation on rma group, easy setup before rma lines created

* [IMP] added fields for default route created by wizard on rma group

* fix: get right price after create rma order line
  • Loading branch information
ChrisOForgeFlow authored and JasminSForgeFlow committed Nov 28, 2024
1 parent a1d0572 commit c4f9467
Showing 1 changed file with 28 additions and 20 deletions.
48 changes: 28 additions & 20 deletions rma_sale/wizards/rma_add_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c4f9467

Please sign in to comment.