Skip to content

Commit

Permalink
[IMP] rma: default warehouse and routes in rma operation
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronHForgeFlow committed Oct 30, 2023
1 parent d7278b4 commit 3e70189
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
26 changes: 23 additions & 3 deletions rma/models/rma_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class RmaOperation(models.Model):
def _default_warehouse_id(self):
company_id = self.env.user.company_id.id
warehouse = self.env["stock.warehouse"].search(
[("company_id", "=", company_id)], limit=1
[("company_id", "=", company_id)], order="sequence asc", limit=1
)
return warehouse

Expand All @@ -24,13 +24,33 @@ def _default_customer_location_id(self):
def _default_supplier_location_id(self):
return self.env.ref("stock.stock_location_suppliers") or False

@api.onchange("in_warehouse_id")
def onchange_warehouse_id(self):
op_type = self.env.context.get("default_type")
if op_type == "customer":
warehouse = self.in_warehouse_id
if not warehouse or not warehouse.rma_customer_pull_id:
return
self.in_route_id = warehouse.rma_customer_pull_id
self.out_route_id = warehouse.rma_customer_pull_id
elif op_type == "supplier":
warehouse = self.out_warehouse_id
if not warehouse or not warehouse.rma_supplier_pull_id:
return
self.in_route_id = warehouse.rma_supplier_pull_id
self.out_route_id = warehouse.rma_supplier_pull_id

@api.model
def _default_routes(self):
company_id = self.env.user.company_id.id
warehouse = self.env["stock.warehouse"].search(
[("company_id", "=", company_id)], limit=1
)
op_type = self.env.context.get("default_type")
if op_type == "customer":
return self.env.ref("rma.route_rma_customer")
return warehouse.rma_customer_pull_id.id
elif op_type == "supplier":
return self.env.ref("rma.route_rma_supplier")
return warehouse.rma_supplier_pull_id.id

name = fields.Char("Description", required=True)
code = fields.Char("Code", required=True)
Expand Down
7 changes: 5 additions & 2 deletions rma/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ def _get_default_type(self):
@api.model
def _default_warehouse_id(self):
rma_id = self.env.context.get("default_rma_id", False)
warehouse = self.env["stock.warehouse"]
company_id = self.env.user.company_id.id
warehouse = self.env["stock.warehouse"].search(
[("company_id", "=", company_id)], order="sequence asc", limit=1
)
if rma_id:
rma = self.env["rma.order"].browse(rma_id)
warehouse = self.env["stock.warehouse"].search(
[("company_id", "=", rma.company_id.id)], limit=1
[("company_id", "=", rma.company_id.id)], order="sequence asc", limit=1
)
return warehouse

Expand Down
4 changes: 2 additions & 2 deletions rma/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def write(self, vals):
if r_type:
r_type.active = False
# Unlink rules:
self.mapped("rma_customer_pull_id").unlink()
self.mapped("rma_supplier_pull_id").unlink()
self.mapped("rma_customer_pull_id").active = False
self.mapped("rma_supplier_pull_id").active = False
return super(StockWarehouse, self).write(vals)

def _create_rma_picking_types(self):
Expand Down
18 changes: 10 additions & 8 deletions rma/tests/test_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def setUpClass(cls):
cls.rma_cust_replace_op_id = cls.env.ref("rma.rma_operation_customer_replace")
cls.rma_sup_replace_op_id = cls.env.ref("rma.rma_operation_supplier_replace")
cls.rma_ds_replace_op_id = cls.env.ref("rma.rma_operation_ds_replace")
cls.customer_route = cls.env.ref("rma.route_rma_customer")
cls.input_location = cls.env.ref("stock.stock_location_company")
cls.output_location = cls.env.ref("stock.stock_location_output")
cls.category = cls._create_product_category(
Expand All @@ -44,7 +43,10 @@ def setUpClass(cls):
cls.partner_id = cls.env.ref("base.res_partner_2")
cls.stock_location = cls.env.ref("stock.stock_location_stock")
cls.wh = cls.env.ref("stock.warehouse0")
cls.wh.rma_in_this_wh = False
cls.wh.rma_in_this_wh = True
cls.stock_rma_location = cls.wh.lot_rma_id
cls.customer_route = cls.wh.rma_customer_pull_id
cls.customer_location = cls.env.ref("stock.stock_location_customers")
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers")
cls.product_uom_id = cls.env.ref("uom.product_uom_unit")
Expand Down Expand Up @@ -380,9 +382,7 @@ def test_01_rma_order_line(self):
# check assert if call reference_move_id onchange
self.assertEqual(line.product_id, line.reference_move_id.product_id)
self.assertEqual(line.product_qty, line.reference_move_id.product_uom_qty)
self.assertEqual(
line.location_id.location_id, line.reference_move_id.location_id
)
self.assertEqual(line.location_id, line.in_warehouse_id.lot_rma_id)
self.assertEqual(line.origin, line.reference_move_id.picking_id.name)
self.assertEqual(
line.delivery_address_id, line.reference_move_id.picking_partner_id
Expand Down Expand Up @@ -1087,8 +1087,10 @@ def test_08_customer_rma_multi_step(self):
"""
# Alter the customer RMA route to make it multi-step
# Get rid of the duplicated rule
self.env.ref("rma.rule_rma_customer_out_pull").active = False
self.env.ref("rma.rule_rma_customer_in_pull").active = False
self.customer_route.rule_ids.active = False
# to be able to receive in in WH
self.wh.reception_steps = "two_steps"
self.wh.delivery_steps = "pick_ship"
cust_in_pull_rule = self.customer_route.rule_ids.filtered(
lambda r: r.location_id == self.stock_rma_location
)
Expand All @@ -1103,7 +1105,7 @@ def test_08_customer_rma_multi_step(self):
"name": "RMA->Output",
"action": "pull",
"warehouse_id": self.wh.id,
"location_src_id": self.env.ref("rma.location_rma").id,
"location_src_id": self.wh.lot_rma_id.id,
"location_id": self.output_location.id,
"procure_method": "make_to_stock",
"route_id": self.customer_route.id,
Expand Down Expand Up @@ -1140,7 +1142,7 @@ def test_08_customer_rma_multi_step(self):
"action": "pull",
"warehouse_id": self.wh.id,
"location_src_id": self.input_location.id,
"location_id": self.env.ref("rma.location_rma").id,
"location_id": self.wh.lot_rma_id.id,
"procure_method": "make_to_order",
"route_id": self.customer_route.id,
"picking_type_id": self.env.ref("stock.picking_type_internal").id,
Expand Down
3 changes: 3 additions & 0 deletions rma/views/stock_warehouse.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
</xpath>
<field name="resupply_wh_ids" position="after">
<field name="rma_in_this_wh" />
<field name="rma_customer_pull_id" />
<field name="rma_supplier_pull_id" />

</field>
<xpath expr="//field[@name='out_type_id']" position="after">
<field name="rma_cust_in_type_id" />
Expand Down
2 changes: 1 addition & 1 deletion rma/wizards/rma_order_line_make_supplier_rma.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def _prepare_supplier_rma_line(self, rma, item):
"location_id": (
operation.location_id.id
or operation.in_warehouse_id.lot_rma_id.id
or warehouse.lot_rma_id.id
or item.line_id.in_warehouse_id.lot_rma_id.id
),
}
return data
Expand Down

0 comments on commit 3e70189

Please sign in to comment.