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 27, 2023
1 parent d7278b4 commit 667c87d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 20 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,30 @@ def _default_customer_location_id(self):
def _default_supplier_location_id(self):
return self.env.ref("stock.stock_location_suppliers") or False

@api.onchange("warehouse_id")
def onchange_warehouse_id(self):
warehouse = self.warehouse_id
if not warehouse:
return
op_type = self.env.context.get("default_type")
if op_type == "customer" and warehouse.rma_customer_pull_id:
self.in_route_id = warehouse.rma_customer_pull_id
self.out_route_id = warehouse.rma_customer_pull_id
elif op_type == "supplier" and warehouse.rma_supplier_pull_id:
self.in_route_id = warehouse.rma_customer_pull_id
self.out_route_id = warehouse.rma_customer_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
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

0 comments on commit 667c87d

Please sign in to comment.