mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
@@ -1 +1,2 @@
|
||||
from . import models
|
||||
from . import wizard
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
"Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"depends": ["stock"],
|
||||
"data": ["wizard/assign_manual_quants_view.xml", "views/stock_move_view.xml"],
|
||||
"data": [
|
||||
"wizard/assign_manual_quants_view.xml",
|
||||
"views/stock_move_view.xml",
|
||||
"views/stock_picking_type_views.xml",
|
||||
],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
1
stock_quant_manual_assign/models/__init__.py
Normal file
1
stock_quant_manual_assign/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import stock_picking_type
|
||||
14
stock_quant_manual_assign/models/stock_picking_type.py
Normal file
14
stock_quant_manual_assign/models/stock_picking_type.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright 2021 Quartile Limited
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class StockPickingType(models.Model):
|
||||
_inherit = "stock.picking.type"
|
||||
|
||||
auto_fill_qty_done = fields.Boolean(
|
||||
"Auto-fill Quantity Done",
|
||||
help="Select this in case done quantity of the stock move line should "
|
||||
"be auto-filled when quants are manually assigned.",
|
||||
)
|
||||
3
stock_quant_manual_assign/readme/CONFIGURATION.rst
Normal file
3
stock_quant_manual_assign/readme/CONFIGURATION.rst
Normal file
@@ -0,0 +1,3 @@
|
||||
In case you would like to auto-fill the done quantity of the stock move line
|
||||
with manual assignment of a quant, go to *Invenory > Configuration > Warehouse Management > Operation Types*,
|
||||
and select 'Auto-fill Quantity Done' for concerned types.
|
||||
@@ -9,6 +9,7 @@ class TestStockQuantManualAssign(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestStockQuantManualAssign, self).setUp()
|
||||
self.quant_model = self.env["stock.quant"]
|
||||
self.picking_model = self.env["stock.picking"]
|
||||
self.location_model = self.env["stock.location"]
|
||||
self.move_model = self.env["stock.move"]
|
||||
self.quant_assign_wizard = self.env["assign.manual.quants"]
|
||||
@@ -38,6 +39,7 @@ class TestStockQuantManualAssign(TransactionCase):
|
||||
"location_id": self.location_src.id,
|
||||
}
|
||||
)
|
||||
self.picking_type = self.env.ref("stock.picking_type_out")
|
||||
self.quant1 = self.quant_model.sudo().create(
|
||||
{
|
||||
"product_id": self.product.id,
|
||||
@@ -67,6 +69,7 @@ class TestStockQuantManualAssign(TransactionCase):
|
||||
"product_uom": self.product.uom_id.id,
|
||||
"location_id": self.location_src.id,
|
||||
"location_dest_id": self.location_dst.id,
|
||||
"picking_type_id": self.picking_type.id,
|
||||
}
|
||||
)
|
||||
self.move._action_confirm()
|
||||
@@ -134,6 +137,21 @@ class TestStockQuantManualAssign(TransactionCase):
|
||||
self.assertAlmostEqual(
|
||||
len(self.move.move_line_ids), len(wizard.quants_lines.filtered("selected"))
|
||||
)
|
||||
self.assertFalse(self.move.picking_type_id.auto_fill_qty_done)
|
||||
self.assertEqual(sum(self.move.move_line_ids.mapped("qty_done")), 0.0)
|
||||
|
||||
def test_quant_manual_assign_auto_fill_qty_done(self):
|
||||
wizard = self.quant_assign_wizard.with_context(active_id=self.move.id).create(
|
||||
{}
|
||||
)
|
||||
wizard.quants_lines[0].write({"selected": True})
|
||||
wizard.quants_lines[0]._onchange_selected()
|
||||
wizard.quants_lines[1].write({"selected": True, "qty": 50.0})
|
||||
self.assertEqual(wizard.lines_qty, 150.0)
|
||||
self.picking_type.auto_fill_qty_done = True
|
||||
wizard.assign_quants()
|
||||
self.assertTrue(self.move.picking_type_id.auto_fill_qty_done)
|
||||
self.assertEqual(sum(self.move.move_line_ids.mapped("qty_done")), 150.0)
|
||||
|
||||
def test_quant_assign_wizard_after_availability_check(self):
|
||||
self.move._action_assign()
|
||||
|
||||
16
stock_quant_manual_assign/views/stock_picking_type_views.xml
Normal file
16
stock_quant_manual_assign/views/stock_picking_type_views.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record model="ir.ui.view" id="view_picking_type_form">
|
||||
<field name="name">Operation Types</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="auto_fill_qty_done"
|
||||
attrs="{'invisible':[('code','=','incoming')]}"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -58,9 +58,10 @@ class AssignManualQuants(models.TransientModel):
|
||||
move._do_unreserve()
|
||||
for line in self.quants_lines:
|
||||
line._assign_quant_line()
|
||||
# Auto-fill all lines as done
|
||||
for ml in move.move_line_ids:
|
||||
ml.qty_done = ml.product_qty
|
||||
if move.picking_type_id.auto_fill_qty_done:
|
||||
# Auto-fill all lines as done
|
||||
for ml in move.move_line_ids:
|
||||
ml.qty_done = ml.product_qty
|
||||
move._recompute_state()
|
||||
move.mapped("picking_id")._compute_state()
|
||||
return {}
|
||||
@@ -78,32 +79,37 @@ class AssignManualQuants(models.TransientModel):
|
||||
)
|
||||
quants_lines = []
|
||||
for quant in available_quants:
|
||||
line = {
|
||||
"quant_id": quant.id,
|
||||
"on_hand": quant.quantity,
|
||||
"location_id": quant.location_id.id,
|
||||
"lot_id": quant.lot_id.id,
|
||||
"package_id": quant.package_id.id,
|
||||
"owner_id": quant.owner_id.id,
|
||||
"selected": False,
|
||||
}
|
||||
move_lines = move.move_line_ids.filtered(
|
||||
lambda ml: (
|
||||
ml.location_id == quant.location_id
|
||||
and ml.lot_id == quant.lot_id
|
||||
and ml.owner_id == quant.owner_id
|
||||
and ml.package_id == quant.package_id
|
||||
)
|
||||
)
|
||||
line["qty"] = sum(move_lines.mapped("product_uom_qty"))
|
||||
line["selected"] = bool(line["qty"])
|
||||
line["reserved"] = quant.reserved_quantity - line["qty"]
|
||||
line = self._prepare_wizard_line(move, quant)
|
||||
quants_lines.append(line)
|
||||
res.update(
|
||||
{"quants_lines": [(0, 0, x) for x in quants_lines], "move_id": move.id}
|
||||
)
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _prepare_wizard_line(self, move, quant):
|
||||
line = {
|
||||
"quant_id": quant.id,
|
||||
"on_hand": quant.quantity,
|
||||
"location_id": quant.location_id.id,
|
||||
"lot_id": quant.lot_id.id,
|
||||
"package_id": quant.package_id.id,
|
||||
"owner_id": quant.owner_id.id,
|
||||
"selected": False,
|
||||
}
|
||||
move_lines = move.move_line_ids.filtered(
|
||||
lambda ml: (
|
||||
ml.location_id == quant.location_id
|
||||
and ml.lot_id == quant.lot_id
|
||||
and ml.owner_id == quant.owner_id
|
||||
and ml.package_id == quant.package_id
|
||||
)
|
||||
)
|
||||
line["qty"] = sum(move_lines.mapped("product_uom_qty"))
|
||||
line["selected"] = bool(line["qty"])
|
||||
line["reserved"] = quant.reserved_quantity - line["qty"]
|
||||
return line
|
||||
|
||||
|
||||
class AssignManualQuantsLines(models.TransientModel):
|
||||
_name = "assign.manual.quants.lines"
|
||||
|
||||
Reference in New Issue
Block a user