Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] stock_picking_volume: Migration to 18.0 #2258

Open
wants to merge 13 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 121 additions & 0 deletions stock_picking_volume/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
====================
Stock Picking Volume
====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:74e1a55b8edd8db012b795a290ba405e3b54488d68f7415afc71b81e36ee69ce
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/17.0/stock_picking_volume
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-warehouse-17-0/stock-logistics-warehouse-17-0-stock_picking_volume
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/stock-logistics-warehouse&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

For some processes, you need to know the volume of your stock picking.
This could be useful for example to know the device to use to process
it. An other use case could be to know how many trucks you need to
deliver your products.

By default, the delivery module from Odoo will compute the picking
weight. Unfortunately, it will not compute the volume. This module will
add the volume computation to the picking and to the stock move. This
information will be stored in the database and will be available on the
picking form view and on the stock move form view.

**Table of contents**

.. contents::
:local:

Usage
=====

In order to have a pertinent value for the computed volume, the
dimension fields must be set on all the products.

The computed volume depends on the move state.

- If the move is done, the volume is the volume for the qty done.
- If the move is cancelled or draft waiting, the volume is the volume
for the qty to do.
- if the move is available or partially available, the volume is the
volume for the reserved quantity.

When the module is installed on an existing database, the volume field
is only computed for the stock moves of pickings not yet processed. The
moves in a cancelled or done picking are not updated to avoid to freeze
the database for a long time during the upgrade process if it contains a
lot of stock moves and pickings.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_picking_volume%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

- Laurent Mignon <[email protected]> (https://www.acsone.eu/)

Other credits
-------------

The development of this module has been financially supported by:

- ACSONE SA/NV
- Alcyon Benelux

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-lmignon| image:: https://github.com/lmignon.png?size=40px
:target: https://github.com/lmignon
:alt: lmignon

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-lmignon|

This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/17.0/stock_picking_volume>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_picking_volume/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import pre_init_hook
24 changes: 24 additions & 0 deletions stock_picking_volume/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Stock Picking Volume",
"summary": """
Compute volume information on stock moves and pickings""",
"version": "18.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"maintainers": ["lmignon"],
"depends": [
"product_dimension",
"stock",
],
"data": [
"views/stock_picking.xml",
"views/stock_move.xml",
],
"demo": [],
"pre_init_hook": "pre_init_hook",
"development_status": "Beta",
}
56 changes: 56 additions & 0 deletions stock_picking_volume/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo.tools.sql import column_exists, create_column

_logger = logging.getLogger(__name__)


def pre_init_hook(env):
"""Pre init create volume column on stock.picking and stock.move"""
if not column_exists(env.cr, "stock_move", "volume"):
create_column(env.cr, "stock_move", "volume", "numeric")
# First we compute the reserved qty by move_id
# the reserved qty is the sum of the reserved qty of the move lines
# linked to the move
# Then we update the volume of the moves not in state done or cancel
# If the move is in state partially available, or assigned, the volume
# is the reserved qty * the product volume
# else the volume is the move quantity * the product volume
env.cr.execute(
"""
UPDATE stock_move
SET volume =
CASE
WHEN state in ('partially_available', 'assigned') THEN
quantity * pp.volume
ELSE
product_uom_qty * pp.volume
END
FROM product_product pp
WHERE state NOT IN ('done', 'cancel') and pp.id = stock_move.product_id
"""
)
_logger.info(f"{env.cr.rowcount} rows updated in stock_move")

if not column_exists(env.cr, "stock_picking", "volume"):
create_column(env.cr, "stock_picking", "volume", "numeric")
# we recompute the volume of the pickings not in state done or cancel
# the volume is the sum of the volume of the moves linked to the picking
# that are not in state done or cancel
env.cr.execute(
"""
update stock_picking
set volume = (
select sum(volume)
from stock_move
where
stock_move.picking_id = stock_picking.id
and state not in ('done', 'cancel')
)
where state not in ('done', 'cancel')
"""
)
_logger.info(f"{env.cr.rowcount} rows updated in stock_picking")
49 changes: 49 additions & 0 deletions stock_picking_volume/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_volume
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-03-06 10:33+0000\n"
"Last-Translator: mymage <[email protected]>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.17\n"

#. module: stock_picking_volume
#: model_terms:ir.ui.view,arch_db:stock_picking_volume.stock_picking_form_view
msgid "Logistics"
msgstr "Logistica"

#. module: stock_picking_volume
#: model:ir.model,name:stock_picking_volume.model_product_product
msgid "Product Variant"
msgstr "Variante prodotto"

#. module: stock_picking_volume
#: model:ir.model,name:stock_picking_volume.model_stock_move
msgid "Stock Move"
msgstr "Movimento di magazzino"

#. module: stock_picking_volume
#: model:ir.model,name:stock_picking_volume.model_stock_picking
msgid "Transfer"
msgstr "Trasferimento"

#. module: stock_picking_volume
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_move__volume
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_picking__volume
msgid "Volume"
msgstr "Volume"

#. module: stock_picking_volume
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_move__volume_uom_name
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_picking__volume_uom_name
msgid "Volume unit of measure label"
msgstr "Etichetta unità di misura volume"
46 changes: 46 additions & 0 deletions stock_picking_volume/i18n/stock_picking_volume.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_picking_volume
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \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_picking_volume
#: model_terms:ir.ui.view,arch_db:stock_picking_volume.stock_picking_form_view
msgid "Logistics"
msgstr ""

#. module: stock_picking_volume
#: model:ir.model,name:stock_picking_volume.model_product_product
msgid "Product Variant"
msgstr ""

#. module: stock_picking_volume
#: model:ir.model,name:stock_picking_volume.model_stock_move
msgid "Stock Move"
msgstr ""

#. module: stock_picking_volume
#: model:ir.model,name:stock_picking_volume.model_stock_picking
msgid "Transfer"
msgstr ""

#. module: stock_picking_volume
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_move__volume
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_picking__volume
msgid "Volume"
msgstr ""

#. module: stock_picking_volume
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_move__volume_uom_name
#: model:ir.model.fields,field_description:stock_picking_volume.field_stock_picking__volume_uom_name
msgid "Volume unit of measure label"
msgstr ""
3 changes: 3 additions & 0 deletions stock_picking_volume/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import product_product
from . import stock_move
from . import stock_picking
29 changes: 29 additions & 0 deletions stock_picking_volume/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2023 Michael Tietz (MT Software) <[email protected]>
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


class ProductProduct(models.Model):
_inherit = "product.product"

def _get_volume_for_qty(self, qty, from_uom=None):
"""Return the volume for the given qty.

This method is meant to be inherited to change the volume
computation for a specific product.

qty: float quantity to compute the volume for.
from_uom: uom of given qty

An override of this method could take into account the packaging
of the product to compute the volume. (using the volume information
on the packaging provided by the module stock_quant_package_dimension
and the method product_qty_by_packaging on the product provided by the
module stock_packaging_calculator)
"""
if not self:
return 0.0
self.ensure_one()
qty = from_uom and from_uom._compute_quantity(qty, self.uom_id) or qty
return qty * self.volume
35 changes: 35 additions & 0 deletions stock_picking_volume/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2023 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class StockMove(models.Model):
_inherit = "stock.move"

volume = fields.Float(
compute="_compute_volume",
readonly=False,
store=True,
compute_sudo=True,
states={"done": [("readonly", True)], "cancel": [("readonly", True)]},
)

volume_uom_name = fields.Char(
string="Volume unit of measure label", compute="_compute_volume_uom_name"
)

@api.depends("product_id", "product_uom_qty", "state", "quantity")
def _compute_volume(self):
for move in self:
qty = move.product_uom_qty
if move.state in ("partially_available", "assigned"):
qty = move.quantity
new_volume = move.product_id._get_volume_for_qty(qty, move.product_uom)
if move.volume != new_volume:
move.volume = new_volume

def _compute_volume_uom_name(self):
self.volume_uom_name = self.env[
"product.template"
]._get_volume_uom_name_from_ir_config_parameter()
Loading
Loading