mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[FIX] rma_scrap: various fixes
This commit is contained in:
committed by
JasminSForgeFlow
parent
a98271f31a
commit
41657b3a83
@@ -36,7 +36,8 @@ Credits
|
|||||||
Contributors
|
Contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* David Jimenez <david.jimenez@ForgeFlow.com>
|
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
|
||||||
|
* David Jimenez <david.jimenez@forgeflow.com>
|
||||||
|
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "RMA Put Away",
|
"name": "RMA Scrap",
|
||||||
"version": "14.0.1.0.0",
|
"version": "14.0.1.0.0",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"category": "RMA",
|
"category": "RMA",
|
||||||
"summary": "Allows to put away the received products in odoo",
|
"summary": "Allows to scrap the received/ordered products in odoo",
|
||||||
"author": "ForgeFlow",
|
"author": "ForgeFlow",
|
||||||
"website": "https://github.com/ForgeFlow/stock-rma",
|
"website": "https://github.com/ForgeFlow/stock-rma",
|
||||||
"depends": ["rma"],
|
"depends": ["rma"],
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
"views/rma_operation_view.xml",
|
"views/rma_operation_view.xml",
|
||||||
"views/rma_order_line_view.xml",
|
"views/rma_order_line_view.xml",
|
||||||
"views/rma_order_view.xml",
|
"views/rma_order_view.xml",
|
||||||
|
"views/stock_scrap_view.xml",
|
||||||
"wizards/rma_scrap_view.xml",
|
"wizards/rma_scrap_view.xml",
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
|
|||||||
@@ -8,12 +8,8 @@ class RmaOrder(models.Model):
|
|||||||
|
|
||||||
def _compute_scrap_count(self):
|
def _compute_scrap_count(self):
|
||||||
for order in self:
|
for order in self:
|
||||||
moves = (
|
scraps = order.mapped("rma_line_ids.scrap_ids")
|
||||||
order.mapped("rma_line_ids.move_ids")
|
order.scrap_count = len(scraps)
|
||||||
.filtered(lambda m: m.is_rma_scrap)
|
|
||||||
.move_line_ids
|
|
||||||
)
|
|
||||||
order.scrap_count = len(moves)
|
|
||||||
|
|
||||||
scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scrap")
|
scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scrap")
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ class RmaOrderLine(models.Model):
|
|||||||
"qty_scrap",
|
"qty_scrap",
|
||||||
"scrap_policy",
|
"scrap_policy",
|
||||||
"product_qty",
|
"product_qty",
|
||||||
|
"scrap_ids",
|
||||||
|
"scrap_ids.state",
|
||||||
|
"scrap_ids.is_rma_scrap",
|
||||||
)
|
)
|
||||||
def _compute_qty_to_scrap(self):
|
def _compute_qty_to_scrap(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@@ -22,18 +25,23 @@ class RmaOrderLine(models.Model):
|
|||||||
elif rec.scrap_policy == "received":
|
elif rec.scrap_policy == "received":
|
||||||
rec.qty_to_scrap = rec.qty_received - rec.qty_scrap
|
rec.qty_to_scrap = rec.qty_received - rec.qty_scrap
|
||||||
|
|
||||||
@api.depends("move_ids", "move_ids.state", "move_ids.is_rma_scrap")
|
@api.depends(
|
||||||
|
"move_ids",
|
||||||
|
"move_ids.state",
|
||||||
|
"move_ids.is_rma_scrap",
|
||||||
|
"scrap_ids",
|
||||||
|
"scrap_ids.state",
|
||||||
|
"scrap_ids.is_rma_scrap",
|
||||||
|
)
|
||||||
def _compute_qty_in_scrap(self):
|
def _compute_qty_in_scrap(self):
|
||||||
product_obj = self.env["uom.uom"]
|
product_obj = self.env["uom.uom"]
|
||||||
for rec in self:
|
for rec in self:
|
||||||
qty = 0.0
|
qty = 0.0
|
||||||
for move in self.env["stock.scrap"].search(
|
for move in self.scrap_ids.filtered(lambda m: m.state in ["draft"]):
|
||||||
[("origin", "=", rec.name), ("state", "=", "draft")]
|
|
||||||
):
|
|
||||||
qty += product_obj._compute_quantity(move.scrap_qty, rec.uom_id)
|
qty += product_obj._compute_quantity(move.scrap_qty, rec.uom_id)
|
||||||
rec.qty_in_scrap = qty
|
rec.qty_in_scrap = qty
|
||||||
|
|
||||||
@api.depends("move_ids", "move_ids.state", "move_ids.is_rma_scrap")
|
@api.depends("scrap_ids", "scrap_ids.state", "scrap_ids.is_rma_scrap")
|
||||||
def _compute_qty_scrap(self):
|
def _compute_qty_scrap(self):
|
||||||
product_obj = self.env["uom.uom"]
|
product_obj = self.env["uom.uom"]
|
||||||
for rec in self:
|
for rec in self:
|
||||||
@@ -46,8 +54,7 @@ class RmaOrderLine(models.Model):
|
|||||||
|
|
||||||
def _compute_scrap_count(self):
|
def _compute_scrap_count(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
scraps = self.env["stock.scrap"].search([("origin", "=", line.name)])
|
line.scrap_count = len(self.scrap_ids)
|
||||||
line.scrap_count = len(scraps)
|
|
||||||
|
|
||||||
qty_to_scrap = fields.Float(
|
qty_to_scrap = fields.Float(
|
||||||
string="Qty To Scrap",
|
string="Qty To Scrap",
|
||||||
@@ -85,6 +92,7 @@ class RmaOrderLine(models.Model):
|
|||||||
readonly=False,
|
readonly=False,
|
||||||
)
|
)
|
||||||
scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scraps")
|
scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scraps")
|
||||||
|
scrap_ids = fields.One2many("stock.scrap", "rma_line_id")
|
||||||
|
|
||||||
@api.onchange("operation_id")
|
@api.onchange("operation_id")
|
||||||
def _onchange_operation_id(self):
|
def _onchange_operation_id(self):
|
||||||
@@ -96,11 +104,10 @@ class RmaOrderLine(models.Model):
|
|||||||
def action_view_scrap_transfers(self):
|
def action_view_scrap_transfers(self):
|
||||||
action = self.env.ref("stock.action_stock_scrap")
|
action = self.env.ref("stock.action_stock_scrap")
|
||||||
result = action.sudo().read()[0]
|
result = action.sudo().read()[0]
|
||||||
scraps = self.env["stock.scrap"].search([("origin", "=", self.name)])
|
if len(self.scrap_ids) > 1:
|
||||||
if len(scraps) > 1:
|
result["domain"] = [("id", "in", self.scrap_ids.ids)]
|
||||||
result["domain"] = [("id", "in", scraps.ids)]
|
elif len(self.scrap_ids) == 1:
|
||||||
elif len(scraps) == 1:
|
|
||||||
res = self.env.ref("stock.stock_scrap_form_view", False)
|
res = self.env.ref("stock.stock_scrap_form_view", False)
|
||||||
result["views"] = [(res and res.id or False, "form")]
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
result["res_id"] = scraps.ids[0]
|
result["res_id"] = self.scrap_ids.ids[0]
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -12,9 +12,3 @@ class StockMove(models.Model):
|
|||||||
copy=False,
|
copy=False,
|
||||||
help="This Stock Move has been created from a Scrap operation in " "the RMA.",
|
help="This Stock Move has been created from a Scrap operation in " "the RMA.",
|
||||||
)
|
)
|
||||||
|
|
||||||
def _is_in_out_rma_move(self, op, states, location_type):
|
|
||||||
res = super(StockMove, self)._is_in_out_rma_move(op, states, location_type)
|
|
||||||
if self.is_rma_scrap:
|
|
||||||
return False
|
|
||||||
return res
|
|
||||||
|
|||||||
@@ -21,3 +21,21 @@ class StockScrap(models.Model):
|
|||||||
if self.is_rma_scrap:
|
if self.is_rma_scrap:
|
||||||
self.move_id.is_rma_scrap = True
|
self.move_id.is_rma_scrap = True
|
||||||
self.rma_line_id.move_ids |= self.move_id
|
self.rma_line_id.move_ids |= self.move_id
|
||||||
|
|
||||||
|
def _prepare_move_values(self):
|
||||||
|
res = super(StockScrap, self)._prepare_move_values()
|
||||||
|
res["rma_line_id"] = self.rma_line_id.id
|
||||||
|
return res
|
||||||
|
|
||||||
|
def action_view_rma_line(self):
|
||||||
|
if self.rma_line_id.type == "customer":
|
||||||
|
action = self.env.ref("rma.action_rma_customer_lines")
|
||||||
|
res = self.env.ref("rma.view_rma_line_form", False)
|
||||||
|
else:
|
||||||
|
action = self.env.ref("rma.action_rma_supplier_lines")
|
||||||
|
res = self.env.ref("rma.view_rma_line_supplier_form", False)
|
||||||
|
result = action.sudo().read()[0]
|
||||||
|
# choose the view_mode accordingly
|
||||||
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
|
result["res_id"] = self.rma_line_id.id
|
||||||
|
return result
|
||||||
|
|||||||
23
rma_scrap/views/stock_scrap_view.xml
Normal file
23
rma_scrap/views/stock_scrap_view.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_stock_scrap_rma_form" model="ir.ui.view">
|
||||||
|
<field name="name">stock.scrap.form - RMA</field>
|
||||||
|
<field name="model">stock.scrap</field>
|
||||||
|
<field name="inherit_id" ref="stock.stock_scrap_form_view" />
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<button name="action_get_stock_move_lines" position="after">
|
||||||
|
<button
|
||||||
|
type="object"
|
||||||
|
name="action_view_rma_line"
|
||||||
|
class="oe_stat_button"
|
||||||
|
icon="fa-eject"
|
||||||
|
string="RMA Line"
|
||||||
|
groups="stock.group_stock_user"
|
||||||
|
attrs="{'invisible': [('rma_line_id', '=', False)]}"
|
||||||
|
>
|
||||||
|
</button>
|
||||||
|
<field name="rma_line_id" invisible="1" />
|
||||||
|
</button>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
@@ -22,6 +22,7 @@ class RmaMakeScrap(models.TransientModel):
|
|||||||
"product_id": line.product_id.id,
|
"product_id": line.product_id.id,
|
||||||
"product_qty": line.product_qty,
|
"product_qty": line.product_qty,
|
||||||
"location_id": line.location_id.id,
|
"location_id": line.location_id.id,
|
||||||
|
"scrap_location_id": line.operation_id.scrap_location_id.id,
|
||||||
"uom_id": line.uom_id.id,
|
"uom_id": line.uom_id.id,
|
||||||
"qty_to_scrap": line.qty_to_scrap,
|
"qty_to_scrap": line.qty_to_scrap,
|
||||||
"line_id": line.id,
|
"line_id": line.id,
|
||||||
@@ -57,11 +58,11 @@ class RmaMakeScrap(models.TransientModel):
|
|||||||
raise ValidationError(_("RMA %s is not approved") % line.name)
|
raise ValidationError(_("RMA %s is not approved") % line.name)
|
||||||
scrap = self._prepare_scrap(item)
|
scrap = self._prepare_scrap(item)
|
||||||
scraps.append(scrap)
|
scraps.append(scrap)
|
||||||
|
item.line_id.scrap_ids |= scrap
|
||||||
return scraps
|
return scraps
|
||||||
|
|
||||||
def action_create_scrap(self):
|
def action_create_scrap(self):
|
||||||
self._create_scrap()
|
self._create_scrap()
|
||||||
self.item_ids[0].line_id._compute_qty_in_scrap()
|
|
||||||
return self.item_ids[0].line_id.action_view_scrap_transfers()
|
return self.item_ids[0].line_id.action_view_scrap_transfers()
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
@@ -74,12 +75,12 @@ class RmaMakeScrap(models.TransientModel):
|
|||||||
"product_id": item.line_id.product_id.id,
|
"product_id": item.line_id.product_id.id,
|
||||||
"scrap_qty": item.qty_to_scrap,
|
"scrap_qty": item.qty_to_scrap,
|
||||||
"product_uom_id": item.line_id.product_id.product_tmpl_id.uom_id.id,
|
"product_uom_id": item.line_id.product_id.product_tmpl_id.uom_id.id,
|
||||||
"scrap_location_id": line.operation_id.scrap_location_id.id,
|
"location_id": item.location_id.id,
|
||||||
|
"scrap_location_id": item.scrap_location_id.id,
|
||||||
"rma_line_id": line.id,
|
"rma_line_id": line.id,
|
||||||
"create_date": fields.Datetime.now(),
|
"create_date": fields.Datetime.now(),
|
||||||
"company_id": line.company_id.id,
|
"company_id": line.company_id.id,
|
||||||
"is_rma_scrap": True,
|
"is_rma_scrap": True,
|
||||||
"location_id": line.location_id.id,
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return scrap
|
return scrap
|
||||||
@@ -91,19 +92,27 @@ class RmaMakeScrapItem(models.TransientModel):
|
|||||||
|
|
||||||
wiz_id = fields.Many2one("rma_make_scrap.wizard", string="Wizard", required=True)
|
wiz_id = fields.Many2one("rma_make_scrap.wizard", string="Wizard", required=True)
|
||||||
line_id = fields.Many2one(
|
line_id = fields.Many2one(
|
||||||
"rma.order.line", string="RMA order Line", ondelete="cascade"
|
"rma.order.line", string="RMA order Line", ondelete="cascade", required=True
|
||||||
)
|
)
|
||||||
rma_id = fields.Many2one("rma.order", related="line_id.rma_id", string="RMA Group")
|
rma_id = fields.Many2one("rma.order", related="line_id.rma_id", string="RMA Group")
|
||||||
product_id = fields.Many2one("product.product", string="Product")
|
product_id = fields.Many2one("product.product", string="Product", required=True)
|
||||||
product_qty = fields.Float(
|
product_qty = fields.Float(
|
||||||
related="line_id.product_qty",
|
related="line_id.product_qty",
|
||||||
string="Quantity Ordered",
|
string="Quantity Ordered",
|
||||||
copy=False,
|
copy=False,
|
||||||
digits="Product Unit of Measure",
|
digits="Product Unit of Measure",
|
||||||
)
|
)
|
||||||
|
company_id = fields.Many2one("res.company", related="line_id.company_id")
|
||||||
location_id = fields.Many2one(
|
location_id = fields.Many2one(
|
||||||
|
"stock.location",
|
||||||
|
string="Source Location",
|
||||||
|
required=True,
|
||||||
|
domain="[('usage', '=', 'internal'), ('company_id', 'in', [company_id, False])]",
|
||||||
|
)
|
||||||
|
scrap_location_id = fields.Many2one(
|
||||||
"stock.location",
|
"stock.location",
|
||||||
string="Scrap Location",
|
string="Scrap Location",
|
||||||
|
required=True,
|
||||||
domain="[('scrap_location', '=', True)]",
|
domain="[('scrap_location', '=', True)]",
|
||||||
)
|
)
|
||||||
qty_to_scrap = fields.Float(
|
qty_to_scrap = fields.Float(
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
<field name="product_qty" />
|
<field name="product_qty" />
|
||||||
<field name="qty_to_scrap" />
|
<field name="qty_to_scrap" />
|
||||||
<field name="location_id" />
|
<field name="location_id" />
|
||||||
|
<field name="scrap_location_id" />
|
||||||
|
<field name="company_id" invisible="1" />
|
||||||
<field name="line_id" invisible="1" />
|
<field name="line_id" invisible="1" />
|
||||||
<field name="uom_id" groups="uom.group_uom" />
|
<field name="uom_id" groups="uom.group_uom" />
|
||||||
</tree>
|
</tree>
|
||||||
|
|||||||
Reference in New Issue
Block a user