Skip to content

Commit

Permalink
[FIX] repair_type: Remove duplicated destination location for added p…
Browse files Browse the repository at this point in the history
…arts and add product destination location
  • Loading branch information
ppyczko committed Nov 21, 2024
1 parent b40101b commit 0497317
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 93 deletions.
1 change: 1 addition & 0 deletions repair_type/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"category": "Repair",
"depends": ["repair"],
"data": [
"views/repair_views.xml",
"views/stock_picking_type_views.xml",
],
"installable": True,
Expand Down
54 changes: 36 additions & 18 deletions repair_type/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-06-27 13:31+0000\n"
"PO-Revision-Date: 2024-06-27 13:31+0000\n"
"POT-Creation-Date: 2024-11-21 09:04+0000\n"
"PO-Revision-Date: 2024-11-21 09:04+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: repair_type
#: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_add_location_dest_id
msgid "Default Add Destination Location"
msgstr ""

#. module: repair_type
#: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_add_location_src_id
msgid "Default Add Source Location"
msgstr ""
msgstr "Ubicación de origen por defecto para añadir"

#. module: repair_type
#: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_product_location_dest_id
msgid "Default Product Destination Location"
msgstr "Ubicación de destino del producto por defecto"

#. module: repair_type
#: model:ir.model.fields,field_description:repair_type.field_stock_picking_type__default_recycle_location_src_id
Expand All @@ -39,35 +38,49 @@ msgstr "Ubicación de origen por defecto para eliminar"
#. module: repair_type
#: model:ir.model,name:repair_type.model_stock_picking_type
msgid "Picking Type"
msgstr "Tipo de recolección"
msgstr "Tipo de albarán"

#. module: repair_type
#: model:ir.model.fields,field_description:repair_type.field_repair_order__product_location_dest_id
msgid "Product Destination Location"
msgstr "Ubicación de destino del producto"

#. module: repair_type
#: model:ir.model,name:repair_type.model_repair_order
msgid "Repair Order"
msgstr "Orden de reparación"

#. module: repair_type
#: model:ir.model,name:repair_type.model_stock_move
msgid "Stock Move"
msgstr "Movimiento de stock"

#. module: repair_type
#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_add_location_dest_id
#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_add_location_src_id
msgid ""
"This is the default add destination location when you create a repair order "
"with this operation type."
"This is the default add source location when you create a repair order with "
"this operation type."
msgstr ""
"Esta es la ubicación de origen por defecto para añadir cuando cree una orden"
" de reparación con este tipo de operación."

#. module: repair_type
#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_add_location_src_id
#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_product_location_dest_id
msgid ""
"This is the default add source location when you create a repair order with "
"this operation type."
"This is the default product destination location when you create a repair "
"order with this operation type."
msgstr ""
"Esta es la ubicación de destino del producto por defecto cuando cree una "
"orden de reparación con este tipo de operación."

#. module: repair_type
#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_recycle_location_src_id
msgid ""
"This is the default recycle source location when you create a repair order "
"with this operation type."
msgstr ""
"Esta es la ubicación de origen por defecto para el reciclaje cuando cree una "
"orden de reparación con este tipo de operación."
"Esta es la ubicación de origen por defecto para el reciclaje cuando cree una"
" orden de reparación con este tipo de operación."

#. module: repair_type
#: model:ir.model.fields,help:repair_type.field_stock_picking_type__default_remove_location_src_id
Expand All @@ -77,3 +90,8 @@ msgid ""
msgstr ""
"Esta es la ubicación de origen por defecto para eleminar cuando cree una "
"orden de reparación con este tipo de operación."

#. module: repair_type
#: model:ir.model.fields,help:repair_type.field_repair_order__product_location_dest_id
msgid "This is the location where the repaired product will be stored."
msgstr "Esta es la ubicación donde se almacenará el producto reparado."
1 change: 1 addition & 0 deletions repair_type/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import repair
from . import stock_move
from . import stock_picking_type
28 changes: 28 additions & 0 deletions repair_type/models/repair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 Patryk Pyczko (APSL-Nagarro)<[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


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

product_location_dest_id = fields.Many2one(
"stock.location",
"Product Destination Location",
compute="_compute_product_location_dest_id",
store=True,
readonly=False,
required=True,
precompute=True,
index=True,
check_company=True,
help="This is the location where the repaired product will be stored.",
)

@api.depends("picking_type_id")
def _compute_product_location_dest_id(self):
for repair in self:
repair.product_location_dest_id = (
repair.picking_type_id.default_product_location_dest_id
)
2 changes: 1 addition & 1 deletion repair_type/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _get_repair_locations(self, repair_line_type, repair_id=False):
):
res = (
self.repair_id.picking_type_id.default_add_location_src_id,
self.repair_id.picking_type_id.default_add_location_dest_id,
res[1],
)
elif (
repair_line_type == "remove"
Expand Down
29 changes: 8 additions & 21 deletions repair_type/models/stock_picking_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ class PickingType(models.Model):
help="This is the default add source location when you create a repair "
"order with this operation type.",
)
default_add_location_dest_id = fields.Many2one(
default_product_location_dest_id = fields.Many2one(
"stock.location",
"Default Add Destination Location",
compute="_compute_default_location_dest_id",
"Default Product Destination Location",
compute="_compute_default_location_src_id",
check_company=True,
store=True,
readonly=False,
precompute=True,
help="This is the default add destination location when you create a repair "
"order with this operation type.",
help="This is the default product destination location when you create a "
"repair order with this operation type.",
)

@api.depends("code")
Expand All @@ -59,20 +59,7 @@ def _compute_default_location_src_id(self):
stock_location = picking_type.warehouse_id.lot_stock_id
if picking_type.code == "repair_operation":
picking_type.default_add_location_src_id = stock_location.id
return res

@api.depends("code")
def _compute_default_location_dest_id(self):
res = super()._compute_default_location_dest_id()
for picking_type in self:
if picking_type.code == "repair_operation":
picking_type.default_add_location_dest_id = (
picking_type.default_location_dest_id.id
)
picking_type.default_remove_location_src_id = (
picking_type.default_location_dest_id.id
)
picking_type.default_recycle_location_src_id = (
picking_type.default_location_dest_id.id
)
picking_type.default_remove_location_src_id = stock_location.id
picking_type.default_recycle_location_src_id = stock_location.id
picking_type.default_product_location_dest_id = stock_location.id
return res
114 changes: 68 additions & 46 deletions repair_type/tests/test_repair_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,90 @@


class TestRepairType(TransactionCase):
def test_get_repair_locations_remove(self):
self.env.ref(
"repair.picking_type_warehouse0_repair"
).default_remove_location_src_id = self.env.ref(
"stock.stock_location_customers"
)
repair = self.env["repair.order"].create(
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.picking_type = cls.env.ref("repair.picking_type_warehouse0_repair")
cls.product_4 = cls.env.ref("product.product_product_4")
cls.product_3 = cls.env.ref("product.product_product_3")
cls.product_11 = cls.env.ref("product.product_product_11")
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
cls.customer_location = cls.env.ref("stock.stock_location_customers")

def _create_repair_order(
self,
picking_type_ref,
product_ref,
repair_line_type,
product_qty,
component_ref,
):
"""Helper method to create a repair order."""
return self.env["repair.order"].create(
{
"picking_type_id": self.env.ref(
"repair.picking_type_warehouse0_repair"
).id,
"product_id": self.env.ref("product.product_product_4").id,
"product_uom": self.env.ref("uom.product_uom_unit").id,
"picking_type_id": picking_type_ref.id,
"product_id": product_ref.id,
"product_uom": self.uom_unit.id,
"move_ids": [
(
0,
0,
{
"name": "Remove Component 1",
"repair_line_type": "remove",
"product_id": self.env.ref("product.product_product_3").id,
"product_uom_qty": 3,
"name": f"{repair_line_type.capitalize()} Component",
"repair_line_type": repair_line_type,
"product_id": component_ref.id,
"product_uom_qty": product_qty,
},
)
],
}
)

def _set_default_location(self, location_field, location_ref):
"""Helper method to set default locations."""
self.picking_type[location_field] = location_ref

def _test_repair_location(
self, repair_line_type, location_field, location_ref, component_ref, product_qty
):
"""Reusable test logic for validating repair locations."""
self._set_default_location(location_field, location_ref)
repair = self._create_repair_order(
self.picking_type,
self.product_4,
repair_line_type,
product_qty,
component_ref,
)
repair._action_repair_confirm()
self.assertEqual(
repair.move_ids.move_line_ids.location_id,
self.env.ref("stock.stock_location_customers"),
location_ref,
)

def test_get_repair_locations_recycle(self):
self.env.ref(
"repair.picking_type_warehouse0_repair"
).default_recycle_location_src_id = self.env.ref(
"stock.stock_location_customers"
def test_get_repair_locations_remove(self):
self._test_repair_location(
repair_line_type="remove",
location_field="default_remove_location_src_id",
location_ref=self.customer_location,
component_ref=self.product_3,
product_qty=3,
)
repair = self.env["repair.order"].create(
{
"picking_type_id": self.env.ref(
"repair.picking_type_warehouse0_repair"
).id,
"product_id": self.env.ref("product.product_product_4").id,
"product_uom": self.env.ref("uom.product_uom_unit").id,
"move_ids": [
(
0,
0,
{
"name": "Recycle Component",
"repair_line_type": "recycle",
"product_uom_qty": 3,
"product_id": self.env.ref("product.product_product_11").id,
},
)
],
}

def test_get_repair_locations_recycle(self):
self._test_repair_location(
repair_line_type="recycle",
location_field="default_recycle_location_src_id",
location_ref=self.customer_location,
component_ref=self.product_11,
product_qty=3,
)
repair._action_repair_confirm()
self.assertEqual(
repair.move_ids.move_line_ids.location_id,
self.env.ref("stock.stock_location_customers"),

def test_get_repair_locations_add(self):
self._test_repair_location(
repair_line_type="add",
location_field="default_add_location_src_id",
location_ref=self.customer_location,
component_ref=self.product_3,
product_qty=5,
)
31 changes: 31 additions & 0 deletions repair_type/views/repair_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="repair_type_view_repair_order_tree_inherit" model="ir.ui.view">
<field name="name">repair.type.repair.order.tree.inherit</field>
<field name="model">repair.order</field>
<field name="inherit_id" ref="repair.view_repair_order_tree" />
<field name="arch" type="xml">
<xpath expr="//field[@name='location_id']" position="after">
<field name="product_location_dest_id" optional="hide" />
</xpath>
</field>
</record>

<record id="repair_type_view_repair_order_form_inherit" model="ir.ui.view">
<field name="name">repair.type.repair.order.form.inherit</field>
<field name="model">repair.order</field>
<field name="inherit_id" ref="repair.view_repair_order_form" />
<field name="arch" type="xml">
<xpath
expr="//group[@name='locations']/field[@name='location_id']"
position="after"
>
<field
name="product_location_dest_id"
readonly="state != 'draft'"
options="{'no_create': True}"
/>
</xpath>
</field>
</record>
</odoo>
Loading

0 comments on commit 0497317

Please sign in to comment.