mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_pull_list: Add server action for generating pull list
This commit is contained in:
committed by
Lois Rilo
parent
490c3e15e5
commit
9a8d872855
@@ -1 +1,2 @@
|
||||
from . import wizards
|
||||
from . import models
|
||||
|
||||
@@ -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
stock_pull_list/data/data.xml
Normal file
11
stock_pull_list/data/data.xml
Normal file
@@ -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
stock_pull_list/models/__init__.py
Normal file
1
stock_pull_list/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import stock_picking
|
||||
30
stock_pull_list/models/stock_picking.py
Normal file
30
stock_pull_list/models/stock_picking.py
Normal file
@@ -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
|
||||
)
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
12
stock_pull_list/views/stock_picking_views.xml
Normal file
12
stock_pull_list/views/stock_picking_views.xml
Normal file
@@ -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>
|
||||
Reference in New Issue
Block a user