diff --git a/stock_pull_list/__init__.py b/stock_pull_list/__init__.py index 5cb1c4914..976591c99 100644 --- a/stock_pull_list/__init__.py +++ b/stock_pull_list/__init__.py @@ -1 +1,2 @@ from . import wizards +from . import models diff --git a/stock_pull_list/__manifest__.py b/stock_pull_list/__manifest__.py index b67d90ce4..778f76b94 100644 --- a/stock_pull_list/__manifest__.py +++ b/stock_pull_list/__manifest__.py @@ -17,6 +17,8 @@ "wizards/stock_pull_list_wizard.xml", "security/ir.model.access.csv", "data/stock_pull_list_sequence_data.xml", + "data/data.xml", + "views/stock_picking_views.xml", ], "installable": True, } diff --git a/stock_pull_list/data/data.xml b/stock_pull_list/data/data.xml new file mode 100644 index 000000000..78cf08c90 --- /dev/null +++ b/stock_pull_list/data/data.xml @@ -0,0 +1,11 @@ + + + Generate Pull List + + + code + + action = records.action_create_pull_list() + + + diff --git a/stock_pull_list/models/__init__.py b/stock_pull_list/models/__init__.py new file mode 100644 index 000000000..ae4c27227 --- /dev/null +++ b/stock_pull_list/models/__init__.py @@ -0,0 +1 @@ +from . import stock_picking diff --git a/stock_pull_list/models/stock_picking.py b/stock_pull_list/models/stock_picking.py new file mode 100644 index 000000000..61d22663b --- /dev/null +++ b/stock_pull_list/models/stock_picking.py @@ -0,0 +1,30 @@ +from odoo import _, fields, models +from odoo.exceptions import UserError + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + def action_create_pull_list(self): + + source_location = fields.first(self).location_id + for record in self: + if source_location != record.location_id: + raise UserError(_("Choose transfers with same source location")) + if not record.picking_type_id.allow_pull_list_server_action: + raise UserError( + f"Operation type of {record.name} transfer did not handle server action" + ) + pull_wizard = self.env["stock.pull.list.wizard"].create( + {"location_id": source_location.id} + ) + res = pull_wizard.action_prepare() + return res + + +class StockPickingType(models.Model): + _inherit = "stock.picking.type" + + allow_pull_list_server_action = fields.Boolean( + string="Allow pull list server action", default=False + ) diff --git a/stock_pull_list/readme/USAGE.rst b/stock_pull_list/readme/USAGE.rst index c46c734d1..dd0c898be 100644 --- a/stock_pull_list/readme/USAGE.rst +++ b/stock_pull_list/readme/USAGE.rst @@ -6,3 +6,8 @@ To use the module follow the next steps: #. Adjust grouping options as needed. This will generate different procurement groups. #. Click on *Procure*. + +Wizard can be also launched through a server action on multiple transfers; this is to allow user to select with ease which transfers to include in the pull list. Please note that: + +#. To select a transfer to be included in pull list through server action, you first need to go to its operation type and enable field "Allow pull list server action". +#. Only transfers with the same Source Location can be selected at one time. diff --git a/stock_pull_list/tests/test_stock_pull_list.py b/stock_pull_list/tests/test_stock_pull_list.py index 7c13bf38f..2473aa229 100644 --- a/stock_pull_list/tests/test_stock_pull_list.py +++ b/stock_pull_list/tests/test_stock_pull_list.py @@ -1,6 +1,8 @@ # Copyright 2020 ForgeFlow, S.L. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo.exceptions import UserError + from .common import TestPullListCommon @@ -41,3 +43,24 @@ class TestStockPullList(TestPullListCommon): wiz.action_prepare() line = wiz.line_ids.filtered(lambda l: l.product_id == self.product_a) self.assertEqual(len(line), 0) + + def test_04_server_action(self): + """Tests work of generate pull list server action + first without allow_pull_list_server_action flag, + after this check Raise of UserError when 2 different locations""" + self._generate_moves() + picking = self.picking_obj.search( + [("location_id", "=", self.warehouse.lot_stock_id.id)] + ) + self.assertRaises(UserError, picking.action_create_pull_list) + picking.picking_type_id.update({"allow_pull_list_server_action": True}) + picking.action_create_pull_list() + wizard = self.env["stock.pull.list.wizard"].search([]) + lines = wizard.line_ids.filtered(lambda l: l.product_id == self.product_a) + self.assertEqual(len(lines), 2) + line_1 = lines.filtered(lambda l: l.date == self.yesterday.date()) + self.assertEqual(line_1.raw_demand_qty, 50) + self.assertEqual(line_1.needed_qty, 50) + self.assertEqual(line_1.stock_rule_id, self.transfer_rule) + picking[0].update({"location_id": self.customer_loc.id}) + self.assertRaises(UserError, picking.action_create_pull_list) diff --git a/stock_pull_list/views/stock_picking_views.xml b/stock_pull_list/views/stock_picking_views.xml new file mode 100644 index 000000000..62c4eccb6 --- /dev/null +++ b/stock_pull_list/views/stock_picking_views.xml @@ -0,0 +1,12 @@ + + + view.picking.type.form + stock.picking.type + + + + + + + +