mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
[MIG] rma_scrap: Migration to 16.0
This commit is contained in:
committed by
JasminSForgeFlow
parent
41657b3a83
commit
a94ee424f9
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "RMA Scrap",
|
"name": "RMA Scrap",
|
||||||
"version": "14.0.1.0.0",
|
"version": "16.0.1.0.0",
|
||||||
"license": "LGPL-3",
|
"license": "LGPL-3",
|
||||||
"category": "RMA",
|
"category": "RMA",
|
||||||
"summary": "Allows to scrap the received/ordered products in odoo",
|
"summary": "Allows to scrap the received/ordered products in odoo",
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class RmaOperation(models.Model):
|
|||||||
("ordered", "Based on Ordered Quantities"),
|
("ordered", "Based on Ordered Quantities"),
|
||||||
("received", "Based on Received Quantities"),
|
("received", "Based on Received Quantities"),
|
||||||
],
|
],
|
||||||
string="Scrap Policy",
|
|
||||||
default="no",
|
default="no",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ class RmaOrderLine(models.Model):
|
|||||||
line.scrap_count = len(self.scrap_ids)
|
line.scrap_count = len(self.scrap_ids)
|
||||||
|
|
||||||
qty_to_scrap = fields.Float(
|
qty_to_scrap = fields.Float(
|
||||||
string="Qty To Scrap",
|
|
||||||
copy=False,
|
copy=False,
|
||||||
digits="Product Unit of Measure",
|
digits="Product Unit of Measure",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
@@ -65,7 +64,6 @@ class RmaOrderLine(models.Model):
|
|||||||
store=True,
|
store=True,
|
||||||
)
|
)
|
||||||
qty_in_scrap = fields.Float(
|
qty_in_scrap = fields.Float(
|
||||||
string="Qty In Scrap",
|
|
||||||
copy=False,
|
copy=False,
|
||||||
digits="Product Unit of Measure",
|
digits="Product Unit of Measure",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
@@ -73,7 +71,6 @@ class RmaOrderLine(models.Model):
|
|||||||
store=True,
|
store=True,
|
||||||
)
|
)
|
||||||
qty_scrap = fields.Float(
|
qty_scrap = fields.Float(
|
||||||
string="Qty Scrap",
|
|
||||||
copy=False,
|
copy=False,
|
||||||
digits="Product Unit of Measure",
|
digits="Product Unit of Measure",
|
||||||
readonly=True,
|
readonly=True,
|
||||||
@@ -86,7 +83,6 @@ class RmaOrderLine(models.Model):
|
|||||||
("ordered", "Based on Ordered Quantities"),
|
("ordered", "Based on Ordered Quantities"),
|
||||||
("received", "Based on Received Quantities"),
|
("received", "Based on Received Quantities"),
|
||||||
],
|
],
|
||||||
string="Scrap Policy",
|
|
||||||
default="no",
|
default="no",
|
||||||
required=True,
|
required=True,
|
||||||
readonly=False,
|
readonly=False,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
# Copyright 2022 ForgeFlow S.L.
|
# Copyright 2022 ForgeFlow S.L.
|
||||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.html).
|
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl-3.0.html).
|
||||||
|
|
||||||
from odoo import fields, models
|
from odoo import _, fields, models
|
||||||
|
from odoo.exceptions import UserError
|
||||||
|
from odoo.tools import float_compare, float_is_zero
|
||||||
|
|
||||||
|
|
||||||
class StockScrap(models.Model):
|
class StockScrap(models.Model):
|
||||||
@@ -17,10 +19,11 @@ class StockScrap(models.Model):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def do_scrap(self):
|
def do_scrap(self):
|
||||||
super(StockScrap, self).do_scrap()
|
res = super(StockScrap, self).do_scrap()
|
||||||
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
|
||||||
|
return res
|
||||||
|
|
||||||
def _prepare_move_values(self):
|
def _prepare_move_values(self):
|
||||||
res = super(StockScrap, self)._prepare_move_values()
|
res = super(StockScrap, self)._prepare_move_values()
|
||||||
@@ -39,3 +42,55 @@ class StockScrap(models.Model):
|
|||||||
result["views"] = [(res and res.id or False, "form")]
|
result["views"] = [(res and res.id or False, "form")]
|
||||||
result["res_id"] = self.rma_line_id.id
|
result["res_id"] = self.rma_line_id.id
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def action_validate(self):
|
||||||
|
self.ensure_one()
|
||||||
|
if float_is_zero(
|
||||||
|
self.scrap_qty, precision_rounding=self.product_uom_id.rounding
|
||||||
|
):
|
||||||
|
raise UserError(_("You can only enter positive quantities."))
|
||||||
|
if self.product_id.type != "product":
|
||||||
|
return self.do_scrap()
|
||||||
|
precision = self.env["decimal.precision"].precision_get(
|
||||||
|
"Product Unit of Measure"
|
||||||
|
)
|
||||||
|
available_qty = sum(
|
||||||
|
self.env["stock.quant"]
|
||||||
|
._gather(
|
||||||
|
self.product_id,
|
||||||
|
self.location_id,
|
||||||
|
self.lot_id,
|
||||||
|
self.package_id,
|
||||||
|
self.owner_id,
|
||||||
|
strict=True,
|
||||||
|
)
|
||||||
|
.mapped("quantity")
|
||||||
|
)
|
||||||
|
scrap_qty = self.product_uom_id._compute_quantity(
|
||||||
|
self.scrap_qty, self.product_id.uom_id
|
||||||
|
)
|
||||||
|
if float_compare(available_qty, scrap_qty, precision_digits=precision) >= 0:
|
||||||
|
return self.do_scrap()
|
||||||
|
else:
|
||||||
|
ctx = dict(self.env.context)
|
||||||
|
ctx.update(
|
||||||
|
{
|
||||||
|
"default_product_id": self.product_id.id,
|
||||||
|
"default_location_id": self.location_id.id,
|
||||||
|
"default_scrap_id": self.id,
|
||||||
|
"default_quantity": scrap_qty,
|
||||||
|
"default_product_uom_name": self.product_id.uom_name,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return {
|
||||||
|
"name": self.product_id.display_name
|
||||||
|
+ _(": Insufficient Quantity To Scrap"),
|
||||||
|
"view_mode": "form",
|
||||||
|
"res_model": "stock.warn.insufficient.qty.scrap",
|
||||||
|
"view_id": self.env.ref(
|
||||||
|
"stock.stock_warn_insufficient_qty_scrap_form_view"
|
||||||
|
).id,
|
||||||
|
"type": "ir.actions.act_window",
|
||||||
|
"context": ctx,
|
||||||
|
"target": "new",
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
cls.lot = cls.env["stock.production.lot"].create(
|
cls.lot = cls.env["stock.lot"].create(
|
||||||
{
|
{
|
||||||
"name": "Lot for tests",
|
"name": "Lot for tests",
|
||||||
"product_id": cls.product_2.id,
|
"product_id": cls.product_2.id,
|
||||||
@@ -95,17 +95,29 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
rma._onchange_operation_id()
|
rma._onchange_operation_id()
|
||||||
rma.action_rma_to_approve()
|
rma.action_rma_to_approve()
|
||||||
wizard = self.rma_make_picking.with_context(
|
wizard = self.rma_make_picking.with_context(
|
||||||
{
|
**{
|
||||||
"active_ids": rma.id,
|
"active_ids": rma.id,
|
||||||
"active_model": "rma.order.line",
|
"active_model": "rma.order.line",
|
||||||
"picking_type": "incoming",
|
"picking_type": "incoming",
|
||||||
"active_id": 1,
|
"active_id": 1,
|
||||||
}
|
}
|
||||||
).create({})
|
).create({})
|
||||||
wizard._create_picking()
|
|
||||||
|
self.assertEqual(rma.qty_to_receive, 1.00)
|
||||||
|
self.assertFalse(rma.qty_to_scrap)
|
||||||
|
|
||||||
|
action_picking = wizard.action_create_picking()
|
||||||
|
picking = self.env["stock.picking"].browse([action_picking["res_id"]])
|
||||||
|
picking.move_line_ids[0].qty_done = rma.qty_to_receive
|
||||||
|
|
||||||
|
picking.button_validate()
|
||||||
rma._compute_qty_to_scrap()
|
rma._compute_qty_to_scrap()
|
||||||
|
|
||||||
|
self.assertFalse(rma.qty_to_receive)
|
||||||
|
self.assertEqual(rma.qty_received, 1.00)
|
||||||
|
self.assertEqual(rma.qty_to_scrap, 1.00)
|
||||||
wizard = self.rma_make_scrap_wiz.with_context(
|
wizard = self.rma_make_scrap_wiz.with_context(
|
||||||
{
|
**{
|
||||||
"active_ids": rma.id,
|
"active_ids": rma.id,
|
||||||
"active_model": "rma.order.line",
|
"active_model": "rma.order.line",
|
||||||
"item_ids": [
|
"item_ids": [
|
||||||
@@ -129,6 +141,8 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
scrap.action_validate()
|
scrap.action_validate()
|
||||||
move = scrap.move_id
|
move = scrap.move_id
|
||||||
self.assertEqual(move.product_id.id, self.product_1.id)
|
self.assertEqual(move.product_id.id, self.product_1.id)
|
||||||
|
self.assertFalse(rma.qty_to_scrap)
|
||||||
|
self.assertEqual(rma.qty_scrap, 1.00)
|
||||||
|
|
||||||
def test_02_rma_scrap_ordered(self):
|
def test_02_rma_scrap_ordered(self):
|
||||||
rma = self.rma_line_obj.create(
|
rma = self.rma_line_obj.create(
|
||||||
@@ -147,8 +161,13 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
rma._onchange_operation_id()
|
rma._onchange_operation_id()
|
||||||
rma.action_rma_to_approve()
|
rma.action_rma_to_approve()
|
||||||
rma._compute_qty_to_scrap()
|
rma._compute_qty_to_scrap()
|
||||||
|
|
||||||
|
self.assertEqual(rma.qty_to_receive, 1.00)
|
||||||
|
self.assertEqual(rma.qty_to_scrap, 1.00)
|
||||||
|
self.assertFalse(rma.qty_in_scrap)
|
||||||
|
|
||||||
wizard = self.rma_make_scrap_wiz.with_context(
|
wizard = self.rma_make_scrap_wiz.with_context(
|
||||||
{
|
**{
|
||||||
"active_ids": rma.id,
|
"active_ids": rma.id,
|
||||||
"active_model": "rma.order.line",
|
"active_model": "rma.order.line",
|
||||||
"item_ids": [
|
"item_ids": [
|
||||||
@@ -169,4 +188,8 @@ class TestRmaScrap(common.SingleTransactionCase):
|
|||||||
scrap = self.env["stock.scrap"].browse([action["res_id"]])
|
scrap = self.env["stock.scrap"].browse([action["res_id"]])
|
||||||
self.assertEqual(scrap.location_id.id, self.stock_rma_location.id)
|
self.assertEqual(scrap.location_id.id, self.stock_rma_location.id)
|
||||||
self.assertEqual(scrap.move_id.id, False)
|
self.assertEqual(scrap.move_id.id, False)
|
||||||
self.assertTrue(scrap.action_validate())
|
self.assertEqual(rma.qty_in_scrap, 1.00)
|
||||||
|
res = scrap.action_validate()
|
||||||
|
scrap.do_scrap()
|
||||||
|
self.assertTrue(res)
|
||||||
|
self.assertEqual(rma.qty_scrap, 1.00)
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
</field>
|
</field>
|
||||||
<group name="outbound" position="after">
|
<group name="outbound" position="after">
|
||||||
<group name="scrap" string="Scrap">
|
<group name="scrap" string="Scrap">
|
||||||
|
<field name="company_id" invisible="1" />
|
||||||
<field
|
<field
|
||||||
name="scrap_location_id"
|
name="scrap_location_id"
|
||||||
string="Destination Scrap Location"
|
string="Destination Scrap Location"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
<form string="Select lines for picking" name="lines">
|
<form string="Select lines for picking" name="lines">
|
||||||
<separator string="Select lines for Scrap" />
|
<separator string="Select lines for Scrap" />
|
||||||
<field name="item_ids">
|
<field name="item_ids">
|
||||||
<tree string="RMA Lines" editable="bottom" create="false">
|
<tree editable="bottom" create="false">
|
||||||
<field name="rma_id" groups="rma.group_rma_groups" />
|
<field name="rma_id" groups="rma.group_rma_groups" />
|
||||||
<field name="product_id" />
|
<field name="product_id" />
|
||||||
<field name="product_qty" />
|
<field name="product_qty" />
|
||||||
@@ -45,7 +45,6 @@
|
|||||||
<field name="view_mode">form</field>
|
<field name="view_mode">form</field>
|
||||||
<field name="target">new</field>
|
<field name="target">new</field>
|
||||||
<field name="view_id" ref="view_rma_scrap" />
|
<field name="view_id" ref="view_rma_scrap" />
|
||||||
<field name="groups_id" eval="[(4, ref('stock.group_stock_user'))]" />
|
|
||||||
<field name="binding_model_id" ref="rma.model_rma_order_line" />
|
<field name="binding_model_id" ref="rma.model_rma_order_line" />
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
@@ -61,12 +60,14 @@
|
|||||||
class="oe_highlight"
|
class="oe_highlight"
|
||||||
attrs="{'invisible':['|', ('qty_to_scrap', '=', 0), ('state', '!=', 'approved')]}"
|
attrs="{'invisible':['|', ('qty_to_scrap', '=', 0), ('state', '!=', 'approved')]}"
|
||||||
type="action"
|
type="action"
|
||||||
|
groups="stock.group_stock_user"
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
name="%(action_rma_scrap)d"
|
name="%(action_rma_scrap)d"
|
||||||
string="Scrap"
|
string="Scrap"
|
||||||
attrs="{'invisible':['|', ('qty_to_scrap', '!=', 0), ('state', '!=', 'approved')]}"
|
attrs="{'invisible':['|', ('qty_to_scrap', '!=', 0), ('state', '!=', 'approved')]}"
|
||||||
type="action"
|
type="action"
|
||||||
|
groups="stock.group_stock_user"
|
||||||
/>
|
/>
|
||||||
</header>
|
</header>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user