Skip to content
Open
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
14 changes: 14 additions & 0 deletions repair_quality_control/models/qc_inspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ def action_view_qc_repair_order(self):
"res_model": "repair.order",
"res_id": self.repair_id.id,
}

def action_repair(self):
self.ensure_one()
if self.picking_id:
action = self.picking_id.action_repair_return()
action["context"].update(
{
"default_product_id": self.product_id.id,
"default_lot_id": self.lot_id.id,
"default_move_id": self.object_id.id,
"default_inspection_ids": [self.id],
}
)
return action
4 changes: 2 additions & 2 deletions repair_quality_control/models/repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
action["context"] = {
"default_qty": self.product_qty,
"default_repair_id": self.id,
"default_object_id": f"product.product,{self.product_id.id}",
"default_object_id": f"product.product, {self.product_id.id}",
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes doesn't seem right.
Maybe I'm missing something.. Why are you adding this space here?

}
if self.lot_id:
action["context"]["default_object_id"] = f"stock.lot,{self.lot_id.id}"
action["context"]["default_object_id"] = f"stock.lot, {self.lot_id.id}"

Check warning on line 32 in repair_quality_control/models/repair.py

View check run for this annotation

Codecov / codecov/patch

repair_quality_control/models/repair.py#L32

Added line #L32 was not covered by tests
return action

def action_view_repair_inspections(self):
Expand Down
48 changes: 44 additions & 4 deletions repair_quality_control/tests/test_repair_quality_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ class RepairQualityControlTest(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()

cls.product = cls.env.ref("product.product_product_27")
cls.lot = cls.env.ref("stock.lot_product_27")

cls.repair_order = cls.env["repair.order"].create(
{
"product_id": cls.env.ref("product.product_product_27").id,
"lot_id": cls.env.ref("stock.lot_product_27").id,
"product_id": cls.product.id,
"lot_id": cls.lot.id,
}
)

def test_create_inspection_from_repair_order(self):
inspect_form = Form(
self.env["qc.inspection"].with_context(
default_repair_id=self.repair_order.id,
default_object_id=f"product.product,{self.repair_order.product_id.id}",
default_object_id=f"product.product, {self.repair_order.product_id.id}",
)
)
qc_inspection = inspect_form.save()
Expand All @@ -31,7 +35,7 @@ def test_create_inspection_from_repair_order(self):
inspect_form = Form(
self.env["qc.inspection"].with_context(
default_repair_id=self.repair_order.id,
default_object_id=f"stock.lot,{self.repair_order.lot_id.id}",
default_object_id=f"stock.lot, {self.repair_order.lot_id.id}",
)
)
qc_inspection = inspect_form.save()
Expand All @@ -42,3 +46,39 @@ def test_create_inspection_from_repair_order(self):
self.assertEqual(
self.repair_order.inspection_ids[1].lot_id, qc_inspection.lot_id
)

def test_create_repair_order_from_inspection(self):
picking = self.env["stock.picking"].create(
{
"picking_type_id": self.env.ref("stock.picking_type_in").id,
"location_id": self.env.ref("stock.stock_location_customers").id,
"location_dest_id": self.env.ref("stock.stock_location_stock").id,
}
)
move = self.env["stock.move"].create(
{
"name": "Test Move",
"product_id": self.product.id,
"product_uom_qty": 1,
"product_uom": self.product.uom_id.id,
"picking_id": picking.id,
"location_id": picking.location_id.id,
"location_dest_id": picking.location_dest_id.id,
}
)
qc_inspection = self.env["qc.inspection"].create(
{
"picking_id": picking.id,
"object_id": f"stock.move, {move.id}",
"product_id": self.product.id,
"lot_id": self.lot.id,
}
)
repair = qc_inspection.action_repair()
repair_form = Form(
self.env[(repair.get("res_model"))].with_context(**repair["context"])
)
repair = repair_form.save()
self.assertEqual(repair.move_id, move)
self.assertEqual(repair.lot_id, qc_inspection.lot_id)
self.assertEqual(repair.product_id, qc_inspection.product_id)
9 changes: 9 additions & 0 deletions repair_quality_control/views/qc_inspection_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
</div>
</button>
</xpath>
<xpath expr="//header" position="inside">
<button
name="action_repair"
string="Repair"
type="object"
class="oe_highlight"
attrs="{'invisible': ['|', ('state', 'not in', ['waiting', 'failed']), ('picking_id', '=', False)]}"
/>
</xpath>
</field>
</record>
</odoo>
8 changes: 7 additions & 1 deletion repair_quality_control/views/repair_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@
/>
</xpath>
<xpath expr="//button[@name='action_created_invoice']" position="after">
<field name="inspection_ids" readonly="1" invisible="1" />
<field
name="inspection_ids"
readonly="1"
invisible="1"
groups="quality_control_oca.group_quality_control_user"
/>
<button
class="oe_stat_button"
name="action_view_repair_inspections"
type="object"
icon="fa-list-ul"
attrs="{'invisible': [('inspection_ids', '=', [])]}"
groups="quality_control_oca.group_quality_control_user"
>
<div class="o_field_widget o_stat_info">
<span class="o_stat_text">Inspections</span>
Expand Down