mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[14.0][IMP] added default operation on rma group, easy setup before rma 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
This commit is contained in:
committed by
JasminSForgeFlow
parent
f8879a51ac
commit
7d979ebc60
@@ -124,12 +124,32 @@ class RmaOrder(models.Model):
|
|||||||
tracking=True,
|
tracking=True,
|
||||||
default=lambda self: self.env.uid,
|
default=lambda self: self.env.uid,
|
||||||
)
|
)
|
||||||
|
in_route_id = fields.Many2one(
|
||||||
|
"stock.route",
|
||||||
|
string="Inbound Route",
|
||||||
|
domain=[("rma_selectable", "=", True)],
|
||||||
|
)
|
||||||
|
out_route_id = fields.Many2one(
|
||||||
|
"stock.route",
|
||||||
|
string="Outbound Route",
|
||||||
|
domain=[("rma_selectable", "=", True)],
|
||||||
|
)
|
||||||
in_warehouse_id = fields.Many2one(
|
in_warehouse_id = fields.Many2one(
|
||||||
comodel_name="stock.warehouse",
|
comodel_name="stock.warehouse",
|
||||||
string="Inbound Warehouse",
|
string="Inbound Warehouse",
|
||||||
required=True,
|
required=False,
|
||||||
default=_default_warehouse_id,
|
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")
|
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_to_customer = fields.Boolean("The supplier will send to the customer")
|
||||||
supplier_address_id = fields.Many2one(
|
supplier_address_id = fields.Many2one(
|
||||||
@@ -153,6 +173,26 @@ class RmaOrder(models.Model):
|
|||||||
default="draft",
|
default="draft",
|
||||||
store=True,
|
store=True,
|
||||||
)
|
)
|
||||||
|
operation_default_id = fields.Many2one(
|
||||||
|
comodel_name="rma.operation",
|
||||||
|
required=False,
|
||||||
|
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.depends("rma_line_ids.date_rma")
|
@api.depends("rma_line_ids.date_rma")
|
||||||
def _compute_date_rma(self):
|
def _compute_date_rma(self):
|
||||||
|
|||||||
@@ -739,13 +739,25 @@ class RmaOrderLine(models.Model):
|
|||||||
return result
|
return result
|
||||||
self.receipt_policy = self.operation_id.receipt_policy
|
self.receipt_policy = self.operation_id.receipt_policy
|
||||||
self.delivery_policy = self.operation_id.delivery_policy
|
self.delivery_policy = self.operation_id.delivery_policy
|
||||||
self.in_warehouse_id = self.operation_id.in_warehouse_id
|
self.customer_to_supplier = (
|
||||||
self.out_warehouse_id = self.operation_id.out_warehouse_id
|
self.rma_id.customer_to_supplier or self.operation_id.customer_to_supplier
|
||||||
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.supplier_to_customer = self.operation_id.supplier_to_customer
|
self.rma_id.supplier_to_customer or self.operation_id.supplier_to_customer
|
||||||
|
)
|
||||||
|
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
|
return result
|
||||||
|
|
||||||
@api.depends("operation_id")
|
@api.depends("operation_id")
|
||||||
|
|||||||
@@ -117,10 +117,32 @@
|
|||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<group name="inbound_route" string="Inbound">
|
<group name="inbound_route" string="Inbound">
|
||||||
|
<field
|
||||||
|
name="operation_default_id"
|
||||||
|
domain="[('type','=','customer')]"
|
||||||
|
/>
|
||||||
<field
|
<field
|
||||||
name="in_warehouse_id"
|
name="in_warehouse_id"
|
||||||
attrs="{'readonly':[('state', '!=', 'draft')]}"
|
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
|
<field
|
||||||
name="customer_to_supplier"
|
name="customer_to_supplier"
|
||||||
attrs="{'readonly':[('state', '!=', 'draft')],
|
attrs="{'readonly':[('state', '!=', 'draft')],
|
||||||
@@ -247,6 +269,21 @@
|
|||||||
'hide_title': True}
|
'hide_title': True}
|
||||||
</attribute>
|
</attribute>
|
||||||
</field>
|
</field>
|
||||||
|
<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>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
|||||||
@@ -58,16 +58,18 @@ class RmaAddSerialWiz(models.TransientModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def _prepare_rma_line_from_lot_vals(self, lot):
|
def _prepare_rma_line_from_lot_vals(self, lot):
|
||||||
if self.env.context.get("customer"):
|
operation = self.rma_id.operation_default_id
|
||||||
operation = (
|
if not operation:
|
||||||
lot.product_id.rma_customer_operation_id
|
if self.env.context.get("customer"):
|
||||||
or lot.product_id.categ_id.rma_customer_operation_id
|
operation = (
|
||||||
)
|
lot.product_id.rma_customer_operation_id
|
||||||
else:
|
or lot.product_id.categ_id.rma_customer_operation_id
|
||||||
operation = (
|
)
|
||||||
lot.product_id.rma_supplier_operation_id
|
else:
|
||||||
or lot.product_id.categ_id.rma_supplier_operation_id
|
operation = (
|
||||||
)
|
lot.product_id.rma_supplier_operation_id
|
||||||
|
or lot.product_id.categ_id.rma_supplier_operation_id
|
||||||
|
)
|
||||||
if not operation:
|
if not operation:
|
||||||
operation = self.env["rma.operation"].search(
|
operation = self.env["rma.operation"].search(
|
||||||
[("type", "=", self.rma_id.type)], limit=1
|
[("type", "=", self.rma_id.type)], limit=1
|
||||||
@@ -82,7 +84,11 @@ class RmaAddSerialWiz(models.TransientModel):
|
|||||||
if not route:
|
if not route:
|
||||||
raise ValidationError(_("Please define an RMA 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(
|
warehouse = self.env["stock.warehouse"].search(
|
||||||
[
|
[
|
||||||
("company_id", "=", self.rma_id.company_id.id),
|
("company_id", "=", self.rma_id.company_id.id),
|
||||||
@@ -94,6 +100,16 @@ class RmaAddSerialWiz(models.TransientModel):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Please define a warehouse with a default RMA location")
|
_("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
|
product_qty = 1 # serial
|
||||||
if lot.product_id.tracking == "lot":
|
if lot.product_id.tracking == "lot":
|
||||||
@@ -112,15 +128,11 @@ class RmaAddSerialWiz(models.TransientModel):
|
|||||||
"rma_id": self.rma_id.id,
|
"rma_id": self.rma_id.id,
|
||||||
"receipt_policy": operation.receipt_policy,
|
"receipt_policy": operation.receipt_policy,
|
||||||
"delivery_policy": operation.delivery_policy,
|
"delivery_policy": operation.delivery_policy,
|
||||||
"in_warehouse_id": operation.in_warehouse_id.id or warehouse.id,
|
"in_warehouse_id": in_warehouse.id,
|
||||||
"out_warehouse_id": operation.out_warehouse_id.id or warehouse.id,
|
"out_warehouse_id": out_warehouse.id,
|
||||||
"in_route_id": operation.in_route_id.id or route.id,
|
"in_route_id": in_route.id,
|
||||||
"out_route_id": operation.out_route_id.id or route.id,
|
"out_route_id": out_route.id,
|
||||||
"location_id": (
|
"location_id": location.id,
|
||||||
operation.location_id.id
|
|
||||||
or operation.in_warehouse_id.lot_rma_id.id
|
|
||||||
or warehouse.lot_rma_id.id
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
@@ -141,4 +153,5 @@ class RmaAddSerialWiz(models.TransientModel):
|
|||||||
# favor of (pre)computed stored editable fields for all policies
|
# favor of (pre)computed stored editable fields for all policies
|
||||||
# and configuration in the RMA operation.
|
# and configuration in the RMA operation.
|
||||||
rec._onchange_operation_id()
|
rec._onchange_operation_id()
|
||||||
|
rec.price_unit = rec._get_price_unit()
|
||||||
return {"type": "ir.actions.act_window_close"}
|
return {"type": "ir.actions.act_window_close"}
|
||||||
|
|||||||
@@ -73,16 +73,18 @@ class RmaAddStockMove(models.TransientModel):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
|
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
|
||||||
if self.env.context.get("customer"):
|
operation = self.rma_id.operation_default_id
|
||||||
operation = (
|
if not operation:
|
||||||
sm.product_id.rma_customer_operation_id
|
if self.env.context.get("customer"):
|
||||||
or sm.product_id.categ_id.rma_customer_operation_id
|
operation = (
|
||||||
)
|
sm.product_id.rma_customer_operation_id
|
||||||
else:
|
or sm.product_id.categ_id.rma_customer_operation_id
|
||||||
operation = (
|
)
|
||||||
sm.product_id.rma_supplier_operation_id
|
else:
|
||||||
or sm.product_id.categ_id.rma_supplier_operation_id
|
operation = (
|
||||||
)
|
sm.product_id.rma_supplier_operation_id
|
||||||
|
or sm.product_id.categ_id.rma_supplier_operation_id
|
||||||
|
)
|
||||||
if not operation:
|
if not operation:
|
||||||
operation = self.env["rma.operation"].search(
|
operation = self.env["rma.operation"].search(
|
||||||
[("type", "=", self.rma_id.type)], limit=1
|
[("type", "=", self.rma_id.type)], limit=1
|
||||||
@@ -96,8 +98,11 @@ class RmaAddStockMove(models.TransientModel):
|
|||||||
)
|
)
|
||||||
if not route:
|
if not route:
|
||||||
raise ValidationError(_("Please define an RMA route"))
|
raise ValidationError(_("Please define an RMA route"))
|
||||||
|
in_warehouse = self.rma_id.in_warehouse_id or operation.in_warehouse_id
|
||||||
if not operation.in_warehouse_id or not operation.out_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(
|
warehouse = self.env["stock.warehouse"].search(
|
||||||
[
|
[
|
||||||
("company_id", "=", self.rma_id.company_id.id),
|
("company_id", "=", self.rma_id.company_id.id),
|
||||||
@@ -109,6 +114,16 @@ class RmaAddStockMove(models.TransientModel):
|
|||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
_("Please define a warehouse with a default RMA location")
|
_("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
|
product_qty = sm.product_uom_qty
|
||||||
if sm.product_id.tracking == "serial":
|
if sm.product_id.tracking == "serial":
|
||||||
product_qty = 1
|
product_qty = 1
|
||||||
@@ -132,15 +147,11 @@ class RmaAddStockMove(models.TransientModel):
|
|||||||
"rma_id": self.rma_id.id,
|
"rma_id": self.rma_id.id,
|
||||||
"receipt_policy": operation.receipt_policy,
|
"receipt_policy": operation.receipt_policy,
|
||||||
"delivery_policy": operation.delivery_policy,
|
"delivery_policy": operation.delivery_policy,
|
||||||
"in_warehouse_id": operation.in_warehouse_id.id or warehouse.id,
|
"in_warehouse_id": in_warehouse.id,
|
||||||
"out_warehouse_id": operation.out_warehouse_id.id or warehouse.id,
|
"out_warehouse_id": out_warehouse.id,
|
||||||
"in_route_id": operation.in_route_id.id or route.id,
|
"in_route_id": in_route.id,
|
||||||
"out_route_id": operation.out_route_id.id or route.id,
|
"out_route_id": out_route.id,
|
||||||
"location_id": (
|
"location_id": location.id,
|
||||||
operation.location_id.id
|
|
||||||
or operation.in_warehouse_id.lot_rma_id.id
|
|
||||||
or warehouse.lot_rma_id.id
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@@ -184,4 +195,5 @@ class RmaAddStockMove(models.TransientModel):
|
|||||||
# favor of (pre)computed stored editable fields for all policies
|
# favor of (pre)computed stored editable fields for all policies
|
||||||
# and configuration in the RMA operation.
|
# and configuration in the RMA operation.
|
||||||
rec._onchange_operation_id()
|
rec._onchange_operation_id()
|
||||||
|
rec.price_unit = rec._get_price_unit()
|
||||||
return {"type": "ir.actions.act_window_close"}
|
return {"type": "ir.actions.act_window_close"}
|
||||||
|
|||||||
Reference in New Issue
Block a user