Skip to content

Commit

Permalink
[IMP] added fields for default route created by wizard on rma group
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisOForgeFlow committed Sep 7, 2023
1 parent ca8557d commit 347e44f
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 47 deletions.
37 changes: 36 additions & 1 deletion rma/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 13 additions & 7 deletions rma/models/rma_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,15 +724,21 @@ 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.location_id = (
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_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.rma_id.location_id
or self.operation_id.location_id
or self.in_warehouse_id.lot_rma_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")
Expand Down
30 changes: 30 additions & 0 deletions rma/views/rma_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,24 @@
name="in_warehouse_id"
attrs="{'readonly':[('state', '!=', 'draft')]}"
/>
<field
name="in_route_id"
attrs="{'readonly':[('state', '!=', 'draft')]}"
/>
<field
name="out_warehouse_id"
invisible="1"
attrs="{'readonly':[('state', '!=', 'draft')]}"
/>
<field
name="location_id"
attrs="{'readonly':[('state', '!=', 'draft')]}"
/>
<field
name="out_route_id"
invisible="1"
attrs="{'readonly':[('state', '!=', 'draft')]}"
/>
<field
name="customer_to_supplier"
attrs="{'readonly':[('state', '!=', 'draft')],
Expand Down Expand Up @@ -256,6 +274,18 @@
<field name="operation_default_id" position="attributes">
<attribute name="domain">[('type','=','supplier')]</attribute>
</field>
<field name="in_warehouse_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="out_warehouse_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="in_route_id" position="attributes">
<attribute name="invisible">0</attribute>
</field>
<field name="out_route_id" position="attributes">
<attribute name="invisible">0</attribute>
</field>
</field>
</record>

Expand Down
30 changes: 20 additions & 10 deletions rma/wizards/rma_add_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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":
Expand All @@ -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

Expand Down
31 changes: 20 additions & 11 deletions rma/wizards/rma_add_stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand All @@ -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

Expand Down
41 changes: 23 additions & 18 deletions rma_sale/wizards/rma_add_sale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 347e44f

Please sign in to comment.