Skip to content

Commit

Permalink
Merge PR #1855 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by LoisRForgeFlow
  • Loading branch information
OCA-git-bot committed Oct 9, 2023
2 parents e51a349 + a3f5a9e commit 77a02d9
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_pull_list/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import wizards
from . import models
2 changes: 2 additions & 0 deletions stock_pull_list/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
11 changes: 11 additions & 0 deletions stock_pull_list/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<odoo>
<record model="ir.actions.server" id="stock_generate_pull_list">
<field name="name">Generate Pull List</field>
<field name="model_id" ref="stock.model_stock_picking" />
<field name="binding_model_id" ref="stock.model_stock_picking" />
<field name="state">code</field>
<field name="code">
action = records.action_create_pull_list()
</field>
</record>
</odoo>
1 change: 1 addition & 0 deletions stock_pull_list/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_picking
30 changes: 30 additions & 0 deletions stock_pull_list/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -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
)
5 changes: 5 additions & 0 deletions stock_pull_list/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
23 changes: 23 additions & 0 deletions stock_pull_list/tests/test_stock_pull_list.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -41,3 +43,24 @@ def test_03_no_needed_qty(self):
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)
12 changes: 12 additions & 0 deletions stock_pull_list/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<odoo>
<record id="view_picking_type_form" model="ir.ui.view">
<field name="name">view.picking.type.form</field>
<field name="model">stock.picking.type</field>
<field name="inherit_id" ref="stock.view_picking_type_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='show_reserved']" position="after">
<field name="allow_pull_list_server_action" />
</xpath>
</field>
</record>
</odoo>

0 comments on commit 77a02d9

Please sign in to comment.