Skip to content

Commit

Permalink
[ADD] rma_repair_put_away: glue module between rma_repair & rma_put_away
Browse files Browse the repository at this point in the history
When not using rma_put_away you can define push rules anyway to move the products
to the repair location, and those transfers count as rma repair transfers

if you install and use rma_put_away then the rma repair transfers are the ones
from the putaway moves

Before this commit there is a dependency issue because the rma_repair code
is using a field declared in the rma_put_away, this commit fixes that issue
  • Loading branch information
AaronHForgeFlow committed Aug 1, 2024
1 parent f83a0de commit c5e3619
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rma_repair/models/rma_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def _compute_repair_transfer_count(self):
for order in self:
pickings = (
order.mapped("rma_line_ids.move_ids")
.filtered(lambda m: m.is_rma_put_away)
.filtered(lambda m: m.is_rma_repair_transfer)
.mapped("picking_id")
)
order.repair_transfer_count = len(pickings)
Expand Down
6 changes: 5 additions & 1 deletion rma_repair/wizards/rma_order_line_make_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def default_get(self, fields_list):
res["item_ids"] = items
return res

def create_repair_procurement_condition_applies(self, rma_line, repair):
return rma_line.location_id != repair.location_id

def make_repair_order(self):
self.ensure_one()
res = []
Expand All @@ -58,10 +61,11 @@ def make_repair_order(self):
data = item._prepare_repair_order(rma_line)
repair = repair_obj.create(data)
res.append(repair.id)
if rma_line.location_id != repair.location_id:
if self.create_repair_procurement_condition_applies(rma_line, repair):
item._run_procurement(
rma_line.operation_id.repair_route_id, repair.location_id
)

return {
"domain": [("id", "in", res)],
"name": _("Repairs"),
Expand Down
31 changes: 31 additions & 0 deletions rma_repair_put_away/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License LGPL-3

===================
RMA Repair Put Away
===================

Glue module between rma_repair & rma_put_away

When not using rma_put_away you can define push rules anyway to move the products
to the repair location, and those transfers count as rma repair transfers

If you install and use rma_put_away then the rma repair transfers are the ones
from the putaway moves


Credits
=======

Contributors
------------

* Jordi Ballester Alomar <[email protected]>
* David Jimenez <[email protected]>
* Aaron Henriquez <[email protected]>


Maintainer
----------

This module is maintained by ForgeFlow
2 changes: 2 additions & 0 deletions rma_repair_put_away/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
12 changes: 12 additions & 0 deletions rma_repair_put_away/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "RMA Repair Put Away",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"category": "RMA",
"summary": "RMA repairs with Put away",
"author": "ForgeFlow",
"website": "https://github.com/ForgeFlow/stock-rma",
"depends": ["rma_repair", "rma_put_away"],
"installable": True,
"auto_install": True,
}
2 changes: 2 additions & 0 deletions rma_repair_put_away/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import rma_order
from . import rma_order_line
31 changes: 31 additions & 0 deletions rma_repair_put_away/models/rma_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2024 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class RmaOrder(models.Model):
_inherit = "rma.order"

def _compute_repair_transfer_count(self):
res = super()._compute_repair_transfer_count()
for order in self:
pickings = (
order.mapped("rma_line_ids.move_ids")
.filtered(lambda m: m.is_rma_put_away)
.mapped("picking_id")
)
order.repair_transfer_count = len(pickings)
return res

def action_view_repair_transfers(self):
super()._compute_repair_transfer_count()
self.ensure_one()
action = self.env.ref("stock.action_picking_tree_all")
result = action.sudo().read()[0]
pickings = self.env["stock.picking"]
for line in self.rma_line_ids:
pickings |= line.move_ids.filtered(lambda m: m.is_rma_put_away).mapped(
"picking_id"
)
return self._view_shipments(result, pickings)
33 changes: 33 additions & 0 deletions rma_repair_put_away/models/rma_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2024 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class RmaOrderLine(models.Model):
_inherit = "rma.order.line"

def _compute_repair_transfer_count(self):
for line in self:
pickings = line.move_ids.filtered(lambda m: m.is_rma_put_away).mapped(
"picking_id"
)
line.repair_transfer_count = len(pickings)

def action_view_repair_transfers(self):
super().action_view_repair_transfers()
action = self.env.ref("stock.action_picking_tree_all")
result = action.sudo().read()[0]
pickings = self.env["stock.picking"]
for line in self:
pickings |= line.move_ids.filtered(lambda m: m.is_rma_put_away).mapped(
"picking_id"
)
# choose the view_mode accordingly
if len(pickings) != 1:
result["domain"] = "[('id', 'in', " + str(pickings.ids) + ")]"
elif len(pickings) == 1:
res = self.env.ref("stock.view_picking_form", False)
result["views"] = [(res and res.id or False, "form")]
result["res_id"] = pickings.ids[0]
return result
1 change: 1 addition & 0 deletions rma_repair_put_away/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import rma_order_line_make_repair
14 changes: 14 additions & 0 deletions rma_repair_put_away/wizards/rma_order_line_make_repair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2024 ForgeFlow S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class RmaLineMakeRepair(models.TransientModel):
_inherit = "rma.order.line.make.repair"

def create_repair_procurement_condition_applies(self, rma_line, repair):
res = super().create_repair_procurement_condition_applies(rma_line, repair)
if rma_line.operation_id.put_away_location_id:
return rma_line.operation_id.put_away_location_id != repair.location_id
return res
1 change: 1 addition & 0 deletions setup/rma_repair_put_away/odoo/addons/rma_repair_put_away
6 changes: 6 additions & 0 deletions setup/rma_repair_put_away/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit c5e3619

Please sign in to comment.