[ADD] stock_quant_package_move_wizard
This commit is contained in:
1
stock_quant_package_move_wizard/wizards/__init__.py
Normal file
1
stock_quant_package_move_wizard/wizards/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import stock_quant_move_wizard
|
||||
@@ -0,0 +1,114 @@
|
||||
# Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockQuantMoveWizard(models.TransientModel):
|
||||
_name = "stock.quant.move.wizard"
|
||||
_description = "Wizard to Move Quants"
|
||||
_check_company_auto = True
|
||||
|
||||
line_ids = fields.One2many(
|
||||
"stock.quant.move.wizard.line", "wizard_id", string="Lines"
|
||||
)
|
||||
company_id = fields.Many2one("res.company", required=True)
|
||||
location_dest_id = fields.Many2one(
|
||||
"stock.location",
|
||||
string="Destination Location",
|
||||
domain="[('usage', '!=', 'view'), ('company_id', '=', company_id)]",
|
||||
check_company=True,
|
||||
required=True,
|
||||
)
|
||||
picking_type_id = fields.Many2one(
|
||||
"stock.picking.type",
|
||||
domain="[('company_id', '=', company_id)]",
|
||||
check_company=True,
|
||||
)
|
||||
origin = fields.Char(string="Source Document")
|
||||
# Idea : add a bool option 'move even if reserved' (= current behavior)
|
||||
|
||||
@api.onchange("picking_type_id")
|
||||
def picking_type_id_change(self):
|
||||
if self.picking_type_id and self.picking_type_id.default_location_dest_id:
|
||||
self.location_dest_id = self.picking_type_id.default_location_dest_id
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super().default_get(fields_list)
|
||||
assert self._context.get("active_model") == "stock.quant"
|
||||
company_id = self.env.company.id
|
||||
quants_ids = self._context.get("active_ids", [])
|
||||
quants = self.env["stock.quant"].browse(quants_ids)
|
||||
lines = []
|
||||
for quant in quants.filtered(
|
||||
lambda q: not q.package_id and q.company_id.id == company_id
|
||||
):
|
||||
lines.append((0, 0, {"quant_id": quant.id, "quantity": quant.quantity}))
|
||||
picking_type = self.env["stock.picking.type"].search(
|
||||
[("code", "=", "internal"), ("company_id", "=", company_id)], limit=1
|
||||
)
|
||||
res.update(
|
||||
{
|
||||
"line_ids": lines,
|
||||
"company_id": company_id,
|
||||
"picking_type_id": picking_type and picking_type.id or False,
|
||||
}
|
||||
)
|
||||
return res
|
||||
|
||||
def run(self):
|
||||
self.ensure_one()
|
||||
picking_id = False
|
||||
if self.picking_type_id:
|
||||
picking_vals = self.env["stock.quant"]._prepare_move_to_stock_picking(
|
||||
self.location_dest_id, self.picking_type_id, origin=self.origin
|
||||
)
|
||||
picking_id = self.env["stock.picking"].create(picking_vals).id
|
||||
smo = self.env["stock.move"]
|
||||
for line in self.line_ids:
|
||||
quant = line.quant_id
|
||||
assert not quant.package_id
|
||||
vals = quant._prepare_move_to_stock_move(
|
||||
line.quantity, self.location_dest_id, picking_id, origin=self.origin
|
||||
)
|
||||
new_move = smo.create(vals)
|
||||
new_move._action_done()
|
||||
assert new_move.state == "done"
|
||||
action = {}
|
||||
if picking_id and self._context.get("run_show_picking"):
|
||||
action = self.env["ir.actions.actions"]._for_xml_id(
|
||||
"stock.stock_picking_action_picking_type"
|
||||
)
|
||||
action.update(
|
||||
{
|
||||
"res_id": picking_id,
|
||||
"view_mode": "form,tree,pivot",
|
||||
"views": False,
|
||||
"view_id": False,
|
||||
}
|
||||
)
|
||||
return action
|
||||
|
||||
|
||||
class StockQuantMoveWizardLine(models.TransientModel):
|
||||
_name = "stock.quant.move.wizard.line"
|
||||
_description = "Lines of the wizard to move quants"
|
||||
|
||||
wizard_id = fields.Many2one(
|
||||
comodel_name="stock.quant.move.wizard", string="Quant Move", ondelete="cascade"
|
||||
)
|
||||
quant_id = fields.Many2one(
|
||||
comodel_name="stock.quant",
|
||||
string="Quant",
|
||||
required=True,
|
||||
)
|
||||
product_id = fields.Many2one(related="quant_id.product_id")
|
||||
quant_quantity = fields.Float(related="quant_id.quantity", string="On Hand Qty")
|
||||
quantity = fields.Float(string="Qty to Move", digits="Product Unit of Measure")
|
||||
uom_id = fields.Many2one(related="quant_id.product_id.uom_id")
|
||||
lot_id = fields.Many2one(related="quant_id.lot_id")
|
||||
src_location_id = fields.Many2one(
|
||||
related="quant_id.location_id", string="Current Location"
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
-->
|
||||
<odoo>
|
||||
|
||||
|
||||
<record id="stock_quant_move_wizard_form" model="ir.ui.view">
|
||||
<field name="model">stock.quant.move.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group name="main">
|
||||
<field name="company_id" invisible="1" />
|
||||
<field
|
||||
name="picking_type_id"
|
||||
options="{'no_open': True, 'no_create': True}"
|
||||
/>
|
||||
<field
|
||||
name="location_dest_id"
|
||||
options="{'no_open': True, 'no_create': True}"
|
||||
/>
|
||||
<field name="origin" />
|
||||
<field name="line_ids" nolabel="1" colspan="2">
|
||||
<tree editable="bottom" create="0">
|
||||
<field name="quant_id" invisible="1" />
|
||||
<field name="src_location_id" />
|
||||
<field name="product_id" />
|
||||
<field name="lot_id" groups="stock.group_production_lot" />
|
||||
<field name="quant_quantity" sum="1" />
|
||||
<field name="quantity" sum="1" />
|
||||
<field name="uom_id" groups="uom.group_uom" string="Unit" />
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="run" string="Move" type="object" class="btn-primary" />
|
||||
<button string="Cancel" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="stock_quant_move_wizard_action" model="ir.actions.act_window">
|
||||
<field name="name">Move to Another Location</field>
|
||||
<field name="res_model">stock.quant.move.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
<field name="binding_model_id" ref="stock.model_stock_quant" />
|
||||
<field name="binding_view_types">list</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user