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
|
||||
------------
|
||||
|
||||
* David Jimenez <david.jimenez@ForgeFlow.com>
|
||||
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
|
||||
* David Jimenez <david.jimenez@forgeflow.com>
|
||||
|
||||
|
||||
Maintainer
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "RMA Put Away",
|
||||
"name": "RMA Scrap",
|
||||
"version": "14.0.1.0.0",
|
||||
"license": "LGPL-3",
|
||||
"category": "RMA",
|
||||
"summary": "Allows to put away the received products in odoo",
|
||||
"summary": "Allows to scrap the received/ordered products in odoo",
|
||||
"author": "ForgeFlow",
|
||||
"website": "https://github.com/ForgeFlow/stock-rma",
|
||||
"depends": ["rma"],
|
||||
@@ -12,6 +12,7 @@
|
||||
"views/rma_operation_view.xml",
|
||||
"views/rma_order_line_view.xml",
|
||||
"views/rma_order_view.xml",
|
||||
"views/stock_scrap_view.xml",
|
||||
"wizards/rma_scrap_view.xml",
|
||||
],
|
||||
"installable": True,
|
||||
|
||||
@@ -8,12 +8,8 @@ class RmaOrder(models.Model):
|
||||
|
||||
def _compute_scrap_count(self):
|
||||
for order in self:
|
||||
moves = (
|
||||
order.mapped("rma_line_ids.move_ids")
|
||||
.filtered(lambda m: m.is_rma_scrap)
|
||||
.move_line_ids
|
||||
)
|
||||
order.scrap_count = len(moves)
|
||||
scraps = order.mapped("rma_line_ids.scrap_ids")
|
||||
order.scrap_count = len(scraps)
|
||||
|
||||
scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scrap")
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ class RmaOrderLine(models.Model):
|
||||
"qty_scrap",
|
||||
"scrap_policy",
|
||||
"product_qty",
|
||||
"scrap_ids",
|
||||
"scrap_ids.state",
|
||||
"scrap_ids.is_rma_scrap",
|
||||
)
|
||||
def _compute_qty_to_scrap(self):
|
||||
for rec in self:
|
||||
@@ -22,18 +25,23 @@ class RmaOrderLine(models.Model):
|
||||
elif rec.scrap_policy == "received":
|
||||
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):
|
||||
product_obj = self.env["uom.uom"]
|
||||
for rec in self:
|
||||
qty = 0.0
|
||||
for move in self.env["stock.scrap"].search(
|
||||
[("origin", "=", rec.name), ("state", "=", "draft")]
|
||||
):
|
||||
for move in self.scrap_ids.filtered(lambda m: m.state in ["draft"]):
|
||||
qty += product_obj._compute_quantity(move.scrap_qty, rec.uom_id)
|
||||
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):
|
||||
product_obj = self.env["uom.uom"]
|
||||
for rec in self:
|
||||
@@ -46,8 +54,7 @@ class RmaOrderLine(models.Model):
|
||||
|
||||
def _compute_scrap_count(self):
|
||||
for line in self:
|
||||
scraps = self.env["stock.scrap"].search([("origin", "=", line.name)])
|
||||
line.scrap_count = len(scraps)
|
||||
line.scrap_count = len(self.scrap_ids)
|
||||
|
||||
qty_to_scrap = fields.Float(
|
||||
string="Qty To Scrap",
|
||||
@@ -85,6 +92,7 @@ class RmaOrderLine(models.Model):
|
||||
readonly=False,
|
||||
)
|
||||
scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scraps")
|
||||
scrap_ids = fields.One2many("stock.scrap", "rma_line_id")
|
||||
|
||||
@api.onchange("operation_id")
|
||||
def _onchange_operation_id(self):
|
||||
@@ -96,11 +104,10 @@ class RmaOrderLine(models.Model):
|
||||
def action_view_scrap_transfers(self):
|
||||
action = self.env.ref("stock.action_stock_scrap")
|
||||
result = action.sudo().read()[0]
|
||||
scraps = self.env["stock.scrap"].search([("origin", "=", self.name)])
|
||||
if len(scraps) > 1:
|
||||
result["domain"] = [("id", "in", scraps.ids)]
|
||||
elif len(scraps) == 1:
|
||||
if len(self.scrap_ids) > 1:
|
||||
result["domain"] = [("id", "in", self.scrap_ids.ids)]
|
||||
elif len(self.scrap_ids) == 1:
|
||||
res = self.env.ref("stock.stock_scrap_form_view", False)
|
||||
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
|
||||
|
||||
@@ -12,9 +12,3 @@ class StockMove(models.Model):
|
||||
copy=False,
|
||||
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:
|
||||
self.move_id.is_rma_scrap = True
|
||||
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_qty": line.product_qty,
|
||||
"location_id": line.location_id.id,
|
||||
"scrap_location_id": line.operation_id.scrap_location_id.id,
|
||||
"uom_id": line.uom_id.id,
|
||||
"qty_to_scrap": line.qty_to_scrap,
|
||||
"line_id": line.id,
|
||||
@@ -57,11 +58,11 @@ class RmaMakeScrap(models.TransientModel):
|
||||
raise ValidationError(_("RMA %s is not approved") % line.name)
|
||||
scrap = self._prepare_scrap(item)
|
||||
scraps.append(scrap)
|
||||
item.line_id.scrap_ids |= scrap
|
||||
return scraps
|
||||
|
||||
def action_create_scrap(self):
|
||||
self._create_scrap()
|
||||
self.item_ids[0].line_id._compute_qty_in_scrap()
|
||||
return self.item_ids[0].line_id.action_view_scrap_transfers()
|
||||
|
||||
@api.model
|
||||
@@ -74,12 +75,12 @@ class RmaMakeScrap(models.TransientModel):
|
||||
"product_id": item.line_id.product_id.id,
|
||||
"scrap_qty": item.qty_to_scrap,
|
||||
"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,
|
||||
"create_date": fields.Datetime.now(),
|
||||
"company_id": line.company_id.id,
|
||||
"is_rma_scrap": True,
|
||||
"location_id": line.location_id.id,
|
||||
}
|
||||
)
|
||||
return scrap
|
||||
@@ -91,19 +92,27 @@ class RmaMakeScrapItem(models.TransientModel):
|
||||
|
||||
wiz_id = fields.Many2one("rma_make_scrap.wizard", string="Wizard", required=True)
|
||||
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")
|
||||
product_id = fields.Many2one("product.product", string="Product")
|
||||
product_id = fields.Many2one("product.product", string="Product", required=True)
|
||||
product_qty = fields.Float(
|
||||
related="line_id.product_qty",
|
||||
string="Quantity Ordered",
|
||||
copy=False,
|
||||
digits="Product Unit of Measure",
|
||||
)
|
||||
company_id = fields.Many2one("res.company", related="line_id.company_id")
|
||||
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",
|
||||
string="Scrap Location",
|
||||
required=True,
|
||||
domain="[('scrap_location', '=', True)]",
|
||||
)
|
||||
qty_to_scrap = fields.Float(
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
<field name="product_qty" />
|
||||
<field name="qty_to_scrap" />
|
||||
<field name="location_id" />
|
||||
<field name="scrap_location_id" />
|
||||
<field name="company_id" invisible="1" />
|
||||
<field name="line_id" invisible="1" />
|
||||
<field name="uom_id" groups="uom.group_uom" />
|
||||
</tree>
|
||||
|
||||
Reference in New Issue
Block a user