Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][ADD] repair_scrap #37

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added repair_scrap/README.rst
Empty file.
2 changes: 2 additions & 0 deletions repair_scrap/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
23 changes: 23 additions & 0 deletions repair_scrap/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
{
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
{

in main python files

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thank you

"name": "Repair Scrap",
"version": "15.0.1.0.0",
"license": "AGPL-3",
"category": "Repair",
"summary": """To send to scrap components or irreparable components.""",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/repair",
"depends": [
"repair_type",
],
"data": [
"security/ir.model.access.csv",
"views/repair_order_view.xml",
"views/stock_scrap_view.xml",
"views/repair_type_views.xml",
"wizards/repair_scrap_view.xml",
],
"development_status": "Alpha",
"installable": True,
}
5 changes: 5 additions & 0 deletions repair_scrap/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import repair_order
from . import repair_type
from . import stock_move
from . import stock_rule
from . import stock_scrap
29 changes: 29 additions & 0 deletions repair_scrap/models/repair_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class RepairOrder(models.Model):
_inherit = "repair.order"

scrap_count = fields.Integer(compute="_compute_scrap_count", string="# Scrap")

scrap_ids = fields.One2many("stock.scrap", "repair_id")

def _compute_scrap_count(self):
for order in self:
order.scrap_count = len(order.scrap_ids)

def action_view_scrap_transfers(self):
self.ensure_one()
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)]

Check warning on line 24 in repair_scrap/models/repair_order.py

View check run for this annotation

Codecov / codecov/patch

repair_scrap/models/repair_order.py#L24

Added line #L24 was not covered by tests
elif len(scraps) == 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]
return result
13 changes: 13 additions & 0 deletions repair_scrap/models/repair_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class RepairType(models.Model):
_inherit = "repair.type"

scrap_location_id = fields.Many2one(
comodel_name="stock.location",
string="Scrap Destination Location",
)
14 changes: 14 additions & 0 deletions repair_scrap/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class StockMove(models.Model):
_inherit = "stock.move"

is_repair_scrap = fields.Boolean(
string="Is repair Scrap",
copy=False,
help="This Stock Move has been created from a Scrap operation in the Repair.",
)
33 changes: 33 additions & 0 deletions repair_scrap/models/stock_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class StockRule(models.Model):
_inherit = "stock.rule"

def _get_stock_move_values(
self,
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
):
res = super()._get_stock_move_values(

Check warning on line 21 in repair_scrap/models/stock_rule.py

View check run for this annotation

Codecov / codecov/patch

repair_scrap/models/stock_rule.py#L21

Added line #L21 was not covered by tests
product_id,
product_qty,
product_uom,
location_id,
name,
origin,
company_id,
values,
)
if "is_repair_scrap" in values:
res["is_repair_scrap"] = values.get("is_repair_scrap")
return res

Check warning on line 33 in repair_scrap/models/stock_rule.py

View check run for this annotation

Codecov / codecov/patch

repair_scrap/models/stock_rule.py#L32-L33

Added lines #L32 - L33 were not covered by tests
36 changes: 36 additions & 0 deletions repair_scrap/models/stock_scrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


class StockScrap(models.Model):
_inherit = "stock.scrap"

repair_id = fields.Many2one("repair.order", string="Repair order")

is_repair_scrap = fields.Boolean(
default=False,
copy=False,
help="This Stock Move has been created from a Scrap operation in Repair.",
)

def do_scrap(self):
res = super(StockScrap, self).do_scrap()
if self.is_repair_scrap:
self.move_id.is_repair_scrap = True
return res

def _prepare_move_values(self):
res = super(StockScrap, self)._prepare_move_values()
res["repair_id"] = self.repair_id.id
return res

def action_view_repair_order(self):
action = self.env.ref("repair.action_repair_order_tree")
res = self.env.ref("repair.view_repair_order_form", False)
result = action.sudo().read()[0]

Check warning on line 32 in repair_scrap/models/stock_scrap.py

View check run for this annotation

Codecov / codecov/patch

repair_scrap/models/stock_scrap.py#L30-L32

Added lines #L30 - L32 were not covered by tests
# choose the view_mode accordingly
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = self.repair_id.id
return result

Check warning on line 36 in repair_scrap/models/stock_scrap.py

View check run for this annotation

Codecov / codecov/patch

repair_scrap/models/stock_scrap.py#L34-L36

Added lines #L34 - L36 were not covered by tests
1 change: 1 addition & 0 deletions repair_scrap/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Thiago Mulero <[email protected]>
1 change: 1 addition & 0 deletions repair_scrap/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manage repair scraps
3 changes: 3 additions & 0 deletions repair_scrap/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_repair_scrap_wizard,Wizard repair scrap user,model_repair_make_scrap_wizard,stock.group_stock_user,1,1,1,1
access_repair_scrap_wizard_item,Wizard item repair scrap user,model_repair_make_scrap_item_wizard,stock.group_stock_user,1,1,1,1
Binary file added repair_scrap/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions repair_scrap/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_repair_scrap
103 changes: 103 additions & 0 deletions repair_scrap/tests/test_repair_scrap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2024 ForgeFlow S.L. (http://www.forgeflow.com)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo.tests.common import TransactionCase


class TestRepair(TransactionCase):
def setUp(self, *args, **kwargs):
super().setUp(*args, **kwargs)
self.repair_obj = self.env["repair.order"]
self.company = self.env.ref("base.main_company")
self.product = self.env.ref("product.product_product_4")
self.stock_location_stock = self.env.ref("stock.stock_location_stock")
self.repair_make_scrap_wiz = self.env["repair_make_scrap.wizard"]
self.wh = self.env.ref("stock.warehouse0")
self.scrap_loc = self.env["stock.location"].create(
{
"name": "WH Scrap Location",
"location_id": self.wh.view_location_id.id,
"scrap_location": True,
}
)
self.repair_type = self.env["repair.type"].create(
{
"name": "Scrap Repair",
"scrap_location_id": self.scrap_loc.id,
}
)
self.lot = self.env["stock.production.lot"].create(
{
"name": "lot test",
"product_id": self.product.id,
"company_id": self.company.id,
}
)
self._update_product_stock(1, self.lot.id)

def _update_product_stock(self, qty, lot_id=False, location=None):
quant = self.env["stock.quant"].create(
{
"product_id": self.product.id,
"location_id": (location.id if location else self.wh.lot_stock_id.id),
"lot_id": lot_id,
"inventory_quantity": qty,
}
)
quant.action_apply_inventory()

def test_01_repair_scrap(self):
repair = self.repair_obj.create(
{
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"repair_type_id": self.repair_type.id,
"location_id": self.stock_location_stock.id,
"lot_id": self.lot.id,
"operations": [
(
0,
0,
{
"name": "TEST",
"location_id": self.stock_location_stock.id,
"location_dest_id": self.product.property_stock_production.id,
"product_id": self.product.id,
"product_uom": self.product.uom_id.id,
"product_uom_qty": 1.0,
"price_unit": 50.0,
"state": "draft",
"type": "add",
"company_id": self.company.id,
"lot_id": self.lot.id,
},
)
],
}
)
repair.action_validate()
wizard = self.repair_make_scrap_wiz.with_context(
**{
"active_ids": repair.id,
"active_model": "repair.order",
"item_ids": [
0,
0,
{
"line_id": repair.id,
"product_id": repair.product_id.id,
"product_qty": repair.product_qty,
"location_id": repair.location_id,
"uom_id": repair.product_id.uom_id.id,
},
],
}
).create({})
action = wizard.action_create_scrap()
scrap = self.env["stock.scrap"].browse([action["res_id"]])
self.assertEqual(scrap.location_id.id, self.stock_location_stock.id)
self.assertEqual(scrap.scrap_location_id.id, self.scrap_loc.id)
self.assertEqual(scrap.move_id.id, False)
self.assertEqual(scrap.lot_id.id, self.lot.id)
scrap.action_validate()
self.assertEqual(scrap.move_id.product_id.id, self.product.id)
22 changes: 22 additions & 0 deletions repair_scrap/views/repair_order_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_repair_order_form_scrap" model="ir.ui.view">
<field name="name">repair.form - Scrap</field>
<field name="model">repair.order</field>
<field name="inherit_id" ref="repair.view_repair_order_form" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
type="object"
name="action_view_scrap_transfers"
class="oe_stat_button"
icon="fa-truck"
groups="stock.group_stock_user"
attrs="{'invisible': [('scrap_count', '=', 0)]}"
>
<field name="scrap_count" widget="statinfo" string="Scraps" />
</button>
</div>
</field>
</record>
</odoo>
26 changes: 26 additions & 0 deletions repair_scrap/views/repair_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="repair_type_view_tree_scrap" model="ir.ui.view">
<field name="name">Repair Types List - Scrap</field>
<field name="model">repair.type</field>
<field name="inherit_id" ref="repair_type.repair_type_view_tree" />
<field name="arch" type="xml">
<field name="destination_location_remove_part_id" position="after">
<field name="scrap_location_id" string="Destination Scrap Location" />
</field>
</field>
</record>

<record id="repair_type_view_form_scrap" model="ir.ui.view">
<field name="name">Repair Types Form - Scrap</field>
<field name="model">repair.type</field>
<field name="inherit_id" ref="repair_type.repair_type_view_form" />
<field name="arch" type="xml">
<field name="destination_location_remove_part_id" position="after">
<field name="scrap_location_id" string="Destination Scrap Location" />
</field>
</field>
</record>

</odoo>
23 changes: 23 additions & 0 deletions repair_scrap/views/stock_scrap_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="stock_scrap_form_view_repair" model="ir.ui.view">
<field name="name">stock.scrap.form - Repair</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_repair_order"
class="oe_stat_button"
icon="fa-eject"
string="Repair Order"
groups="stock.group_stock_user"
attrs="{'invisible': [('repair_id', '=', False)]}"
>
</button>
<field name="repair_id" invisible="1" />
</button>
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions repair_scrap/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import repair_make_scrap
Loading
Loading