-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9975397
commit da324ea
Showing
23 changed files
with
530 additions
and
0 deletions.
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,21 @@ | ||
{ | ||
"name": "Repair Scrap", | ||
"version": "15.0.1.0.0", | ||
"license": "AGPL-3", | ||
"category": "Repair", | ||
"summary": """Repair Scrap""", | ||
"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,26 @@ | ||
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,10 @@ | ||
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,11 @@ | ||
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,30 @@ | ||
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,33 @@ | ||
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,100 @@ | ||
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" ?> | ||
<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.