Add module stock_quant_package_move_wizard

This commit is contained in:
Alexis de Lattre
2023-02-21 15:10:38 +01:00
parent 9026660416
commit b48db5492d
12 changed files with 816 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
Module Stock Quant Package Moving Wizard
=========================================
This module provides a **super fast** and **super easy** way of moving a quant to another stock location.
Usage
=====
1. Select one or several quants
2. Click on the *Move* button
3. Follow the instructions on the wizard: select a picking type (or a destination stock location) and, if you don't want to move the full quant, edit the quantity to move.
4. Validate the wizard
Contributors
============
* Alexis de Lattre <alexis.delattre@akretion.com>
* Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>
* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Ana Juaristi <ajuaristio@gmail.com>

View File

@@ -0,0 +1,2 @@
from . import models
from . import wizards

View File

@@ -0,0 +1,29 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
{
"name": "Quant & Package moving wizard",
"summary": "Select a quant Move quants to another location in a few clicks",
"category": "Inventory/Inventory",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"depends": ["stock"],
"author": "AvanzOSC, "
"Serv. Tecnol. Avanzados - Pedro M. Baeza, "
"Akretion",
"maintainers": ["alexis-via"],
"website": "https://github.com/akretion/odoo-usability",
"contributors": [
"Oihane Crucelaegui <oihanecrucelaegi@avanzosc.es>",
"Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>",
"Ana Juaristi <ajuaristio@gmail.com>",
"Alexis de Lattre <alexis.delattre@akretion.com>",
],
"data": [
# "wizards/quants_move_wizard_view.xml",
"security/ir.model.access.csv",
"wizards/stock_quant_move_wizard_view.xml",
"views/stock_quant.xml",
# "views/stock_quant_package.xml",
],
"installable": True,
}

View File

@@ -0,0 +1,223 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_quant_package_move_wizard
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-02-13 21:59+0000\n"
"PO-Revision-Date: 2023-02-13 21:59+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: stock_quant_package_move_wizard
#: model_terms:ir.ui.view,arch_db:stock_quant_package_move_wizard.stock_quant_move_wizard_form
msgid "Cancel"
msgstr "Annuler"
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid "Cannot move to '%s' which is a view location."
msgstr "Impossible de déplacer vers '%s' qui est un emplacement de type Vue."
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__company_id
msgid "Company"
msgstr "Société"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__create_uid
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__create_uid
msgid "Created by"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__create_date
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__create_date
msgid "Created on"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__src_location_id
msgid "Current Location"
msgstr "Emplacement actuel"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,help:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__uom_id
msgid "Default unit of measure used for all stock operations."
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__location_dest_id
msgid "Destination Location"
msgstr "Emplacement destination"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__display_name
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__display_name
msgid "Display Name"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__id
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__id
msgid "ID"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard____last_update
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line____last_update
msgid "Last Modified on"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__write_uid
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__write_uid
msgid "Last Updated by"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__write_date
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__write_date
msgid "Last Updated on"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__line_ids
msgid "Lines"
msgstr "Lignes"
#. module: stock_quant_package_move_wizard
#: model:ir.model,name:stock_quant_package_move_wizard.model_stock_quant_move_wizard_line
msgid "Lines of the wizard to move quants"
msgstr "Lignes de l'assistant de déplacement des quants"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__lot_id
msgid "Lot/Serial Number"
msgstr "Lot/numéro de série"
#. module: stock_quant_package_move_wizard
#: model_terms:ir.ui.view,arch_db:stock_quant_package_move_wizard.stock_quant_move_wizard_form
msgid "Move"
msgstr "Déplacer"
#. module: stock_quant_package_move_wizard
#: model:ir.actions.act_window,name:stock_quant_package_move_wizard.stock_quant_move_wizard_action
msgid "Move to Another Location"
msgstr "Déplacer vers un autre emplacement"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quant_quantity
msgid "On Hand Qty"
msgstr "Qté en stock"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__picking_type_id
msgid "Picking Type"
msgstr "Type d'opération"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__product_id
msgid "Product"
msgstr "Article"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quantity
msgid "Qty to Move"
msgstr "Qté à déplacer"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quant_id
msgid "Quant"
msgstr "Quant"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__wizard_id
msgid "Quant Move"
msgstr "Déplacer Quant"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,help:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quant_quantity
msgid ""
"Quantity of products in this quant, in the default unit of measure of the "
"product"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model,name:stock_quant_package_move_wizard.model_stock_quant
msgid "Quants"
msgstr "Quants"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__origin
msgid "Source Document"
msgstr "Document source"
#. module: stock_quant_package_move_wizard
#: model_terms:ir.ui.view,arch_db:stock_quant_package_move_wizard.stock_quant_move_wizard_form
msgid "Unit"
msgstr "Unité"
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__uom_id
msgid "Unit of Measure"
msgstr "Unité de mesure"
#. module: stock_quant_package_move_wizard
#: model:ir.model,name:stock_quant_package_move_wizard.model_stock_quant_move_wizard
msgid "Wizard to Move Quants"
msgstr "Assistant de déplacement de quants"
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s that has a quantity of %(quant_quantity)s %(uom)s."
msgstr ""
"Vous essayez de déplacer %(qty)s %(uom)s d'un quant de l'article "
"%(product_name)s dont la quantité est de %(quant_quantity)s %(uom)s."
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s to %(dest_location)s, but it is already on that location!"
msgstr ""
"Vous essayez de déplacer %(qty)s %(uom)s d'un quant de l'article "
"%(product_name)s vers %(dest_location)s, mais il est déjà sur cet emplacement !"
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s, but that quant has a negative quantity (%(quant_quantity)s"
" %(uom)s)."
msgstr ""
"Vous essayez de déplacer %(qty)s %(uom)s d'un quant de l'article "
"%(product_name)s, mais ce quant est en quantité négative (%(quant_quantity)s"
" %(uom)s)."
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s: the quantity to move must be strictly positive."
msgstr ""
"Vous essayez de déplacer %(qty)s %(uom)s d'un quant de l'article "
"%(product_name)s : la quantité à déplacer doit être strictement positive."

View File

@@ -0,0 +1,214 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_quant_package_move_wizard
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-02-13 21:58+0000\n"
"PO-Revision-Date: 2023-02-13 21:58+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: stock_quant_package_move_wizard
#: model_terms:ir.ui.view,arch_db:stock_quant_package_move_wizard.stock_quant_move_wizard_form
msgid "Cancel"
msgstr ""
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid "Cannot move to '%s' which is a view location."
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__company_id
msgid "Company"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__create_uid
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__create_uid
msgid "Created by"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__create_date
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__create_date
msgid "Created on"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__src_location_id
msgid "Current Location"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,help:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__uom_id
msgid "Default unit of measure used for all stock operations."
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__location_dest_id
msgid "Destination Location"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__display_name
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__display_name
msgid "Display Name"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__id
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__id
msgid "ID"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard____last_update
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line____last_update
msgid "Last Modified on"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__write_uid
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__write_uid
msgid "Last Updated by"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__write_date
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__write_date
msgid "Last Updated on"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__line_ids
msgid "Lines"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model,name:stock_quant_package_move_wizard.model_stock_quant_move_wizard_line
msgid "Lines of the wizard to move quants"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__lot_id
msgid "Lot/Serial Number"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model_terms:ir.ui.view,arch_db:stock_quant_package_move_wizard.stock_quant_move_wizard_form
msgid "Move"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.actions.act_window,name:stock_quant_package_move_wizard.stock_quant_move_wizard_action
msgid "Move to Another Location"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quant_quantity
msgid "On Hand Qty"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__picking_type_id
msgid "Picking Type"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__product_id
msgid "Product"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quantity
msgid "Qty to Move"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quant_id
msgid "Quant"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__wizard_id
msgid "Quant Move"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,help:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__quant_quantity
msgid ""
"Quantity of products in this quant, in the default unit of measure of the "
"product"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model,name:stock_quant_package_move_wizard.model_stock_quant
msgid "Quants"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard__origin
msgid "Source Document"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model_terms:ir.ui.view,arch_db:stock_quant_package_move_wizard.stock_quant_move_wizard_form
msgid "Unit"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model.fields,field_description:stock_quant_package_move_wizard.field_stock_quant_move_wizard_line__uom_id
msgid "Unit of Measure"
msgstr ""
#. module: stock_quant_package_move_wizard
#: model:ir.model,name:stock_quant_package_move_wizard.model_stock_quant_move_wizard
msgid "Wizard to Move Quants"
msgstr ""
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s that has a quantity of %(quant_quantity)s %(uom)s."
msgstr ""
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s to %(dest_location)s, but it is already on that location!"
msgstr ""
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s, but that quant has a negative quantity (%(quant_quantity)s"
" %(uom)s)."
msgstr ""
#. module: stock_quant_package_move_wizard
#. odoo-python
#: code:addons/stock_quant_package_move_wizard/models/stock_quant.py:0
#, python-format
msgid ""
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s: the quantity to move must be strictly positive."
msgstr ""

View File

@@ -0,0 +1 @@
from . import stock_quant

View File

@@ -0,0 +1,127 @@
# 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 _, models
from odoo.exceptions import UserError
from odoo.tools import float_compare
from odoo.tools.misc import formatLang
class StockQuant(models.Model):
_inherit = "stock.quant"
def _prepare_move_to_stock_move(self, qty, dest_location, picking_id, origin=False):
# qty is in the product's uom_id
self.ensure_one()
if dest_location.usage == "view":
raise UserError(
_("Cannot move to '%s' which is a view location.")
% dest_location.display_name
)
prec = self.env["decimal.precision"].precision_get("Product Unit of Measure")
raise_dict = {
"qty": formatLang(self.env, qty, digits=prec),
"uom": self.product_id.uom_id.display_name,
"product_name": self.product_id.display_name,
"dest_location": dest_location.display_name,
"quant_quantity": formatLang(self.env, self.quantity, digits=prec),
}
if self.location_id == dest_location:
raise UserError(
_(
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s to %(dest_location)s, but it is already on "
"that location!"
)
% raise_dict
)
if float_compare(qty, self.quantity, precision_digits=prec) > 0:
raise UserError(
_(
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s that has a quantity of "
"%(quant_quantity)s %(uom)s."
)
% raise_dict
)
if float_compare(self.quantity, 0, precision_digits=prec) <= 0:
raise UserError(
_(
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s, but that quant has a negative quantity "
"(%(quant_quantity)s %(uom)s)."
)
% raise_dict
)
if float_compare(qty, 0, precision_digits=prec) <= 0:
raise UserError(
_(
"You are trying to move %(qty)s %(uom)s of a quant of product "
"%(product_name)s: the quantity to move must be strictly positive."
)
% raise_dict
)
product_id = self.product_id.id
location_id = self.location_id.id
location_dest_id = dest_location.id
uom_id = self.product_id.uom_id.id
vals = {
"picking_id": picking_id,
"name": "%s: Move to %s"
% (self.product_id.display_name, dest_location.display_name),
"product_id": product_id,
"location_id": location_id,
"location_dest_id": location_dest_id,
"product_uom_qty": qty,
"product_uom": uom_id,
"origin": origin,
"move_line_ids": [
(
0,
0,
{
"product_id": product_id,
"product_uom_id": uom_id,
"qty_done": qty,
"location_id": location_id,
"location_dest_id": location_dest_id,
"lot_id": self.lot_id.id or False,
},
)
],
}
return vals
def _prepare_move_to_stock_picking(self, dest_location, picking_type, origin=False):
vals = {
"picking_type_id": picking_type.id,
"location_dest_id": dest_location.id,
"location_id": picking_type.default_location_src_id.id,
"origin": origin,
}
return vals
def move_full_quant_to(self, dest_location, picking_type=False, origin=False):
assert dest_location
picking_id = False
if picking_type:
picking_vals = self._prepare_move_to_stock_picking(
dest_location, picking_type, origin=origin
)
picking_id = self.env["stock.picking"].create(picking_vals).id
smo = self.env["stock.move"]
stock_move_ids = []
for quant in self:
vals = quant._prepare_move_to_stock_move(
quant.quantity, dest_location, picking_id, origin=origin
)
new_move = smo.create(vals)
# No group has write access on stock.quant -> we need sudo()
new_move._action_done()
assert new_move.state == "done"
stock_move_ids.append(new_move.id)
return {
"picking_id": picking_id,
"stock_move_ids": stock_move_ids,
}

View File

@@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_stock_quant_move_wizard,Full access on stock.quant.move.wizard,model_stock_quant_move_wizard,stock.group_stock_user,1,1,1,1
access_stock_quant_move_wizard_line,Full access on stock.quant.move.wizard.line,model_stock_quant_move_wizard_line,stock.group_stock_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
2 access_stock_quant_move_wizard Full access on stock.quant.move.wizard model_stock_quant_move_wizard stock.group_stock_user 1 1 1 1
3 access_stock_quant_move_wizard_line Full access on stock.quant.move.wizard.line model_stock_quant_move_wizard_line stock.group_stock_user 1 1 1 1

View File

@@ -0,0 +1,28 @@
<?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>
<!-- Maybe it's not a good idea to put a button on tree view of quants
from product form view, because all the direct-access buttons on this tree
view are for inventory, so it may be hard for users to understand that
this button has nothing to do with inventory
<record id="view_stock_quant_tree_inventory_editable" model="ir.ui.view">
<field name="model">stock.quant</field>
<field name="inherit_id" ref="stock.view_stock_quant_tree_inventory_editable" />
<field name="arch" type="xml">
<button name="stock.action_stock_inventory_adjustement_name" position="before">
<button
type="action"
name="%(stock_quant_move_wizard_action)d"
string="Move"
/>
</button>
</field>
</record>
-->
</odoo>

View File

@@ -0,0 +1 @@
from . import stock_quant_move_wizard

View File

@@ -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"
)

View File

@@ -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>