-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import models | ||
from . import wizards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). | ||
{ | ||
"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, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
# choose the view_mode accordingly | ||
result["views"] = [(res and res.id or False, "form")] | ||
result["res_id"] = self.repair_id.id | ||
return result | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Thiago Mulero <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Manage repair scraps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_repair_scrap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import repair_make_scrap |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in main python files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, thank you