mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
@@ -0,0 +1 @@
|
||||
../../../../stock_packaging_calculator
|
||||
6
setup/stock_packaging_calculator/setup.py
Normal file
6
setup/stock_packaging_calculator/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
126
stock_packaging_calculator/README.rst
Normal file
126
stock_packaging_calculator/README.rst
Normal file
@@ -0,0 +1,126 @@
|
||||
==========================
|
||||
Stock packaging calculator
|
||||
==========================
|
||||
|
||||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
|
||||
:target: https://odoo-community.org/page/development-status
|
||||
:alt: Alpha
|
||||
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
|
||||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
:alt: License: LGPL-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/13.0/stock_packaging_calculator
|
||||
: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-13-0/stock-logistics-warehouse-13-0-stock_packaging_calculator
|
||||
:alt: Translate me on Weblate
|
||||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||
:target: https://runbot.odoo-community.org/runbot/153/13.0
|
||||
:alt: Try me on Runbot
|
||||
|
||||
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||
|
||||
Basic module providing an helper method to calculate the quantity of product by packaging.
|
||||
|
||||
.. IMPORTANT::
|
||||
This is an alpha version, the data model and design can change at any time without warning.
|
||||
Only for development or testing purpose, do not use in production.
|
||||
`More details on development status <https://odoo-community.org/page/development-status>`_
|
||||
|
||||
**Table of contents**
|
||||
|
||||
.. contents::
|
||||
:local:
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Imagine you have the following packagings:
|
||||
|
||||
* Pallet: 1000 Units
|
||||
* Big box: 500 Units
|
||||
* Box: 50 Units
|
||||
|
||||
and you have to pick from your warehouse 2860 Units.
|
||||
|
||||
Then you can do:
|
||||
|
||||
.. code-block::
|
||||
|
||||
>>> product.product_qty_by_packaging(2860)
|
||||
|
||||
[
|
||||
{"id": 1, "qty": 2, "name": "Pallet"},
|
||||
{"id": 2, "qty": 1, "name": "Big box"},
|
||||
{"id": 3, "qty": 7, "name": "Box"},
|
||||
{"id": 100, "qty": 10, "name": "Units"},
|
||||
]
|
||||
|
||||
With this you can show a proper message to warehouse operators to quickly pick the quantity they need.
|
||||
|
||||
Optionally you can get contained packaging by passing `with_contained` flag:
|
||||
|
||||
|
||||
.. code-block::
|
||||
|
||||
>>> product.product_qty_by_packaging(2860, with_contained=True)
|
||||
|
||||
[
|
||||
{"id": 1, "qty": 2, "name": "Pallet", "contained": [{"id": 2, "qty": 2, "name": "Big box"}]},
|
||||
{"id": 2, "qty": 1, "name": "Big box", "contained": [{"id": 3, "qty": 10, "name": "Box"}]},
|
||||
{"id": 3, "qty": 7, "name": "Box", "contained": [{"id": 100, "qty": 50, "name": "Units"}]},
|
||||
{"id": 100, "qty": 10, "name": "Units", "contained": []},},
|
||||
]
|
||||
|
||||
Known issues / Roadmap
|
||||
======================
|
||||
|
||||
TODO
|
||||
|
||||
1. Fractional quantities (eg: 0.5 Kg) are lost when counting units
|
||||
2. Maybe rely on `packaging_uom`
|
||||
|
||||
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 smashing it by providing a detailed and welcomed
|
||||
`feedback <https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_packaging_calculator%0Aversion:%2013.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
|
||||
~~~~~~~
|
||||
|
||||
* Camptocamp
|
||||
|
||||
Contributors
|
||||
~~~~~~~~~~~~
|
||||
|
||||
* Simone Orsi <simahawk@gmail.com>
|
||||
|
||||
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.
|
||||
|
||||
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_packaging_calculator>`_ project on GitHub.
|
||||
|
||||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||
1
stock_packaging_calculator/__init__.py
Normal file
1
stock_packaging_calculator/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
||||
15
stock_packaging_calculator/__manifest__.py
Normal file
15
stock_packaging_calculator/__manifest__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
# Copyright 2020 Camptocamp SA
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
|
||||
{
|
||||
"name": "Stock packaging calculator",
|
||||
"summary": "Compute product quantity to pick by packaging",
|
||||
"version": "14.0.1.0.0",
|
||||
"development_status": "Alpha",
|
||||
"category": "Warehouse Management",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"author": "Camptocamp, Odoo Community Association (OCA)",
|
||||
"license": "LGPL-3",
|
||||
"application": False,
|
||||
"installable": True,
|
||||
"depends": ["product"],
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
# Translation of Odoo Server.
|
||||
# This file contains the translation of the following modules:
|
||||
# * stock_packaging_calculator
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: Odoo Server 13.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_packaging_calculator
|
||||
#: model:ir.model.fields,field_description:stock_packaging_calculator.field_product_product__packaging_contained_mapping
|
||||
msgid "Packaging Contained Mapping"
|
||||
msgstr ""
|
||||
|
||||
#. module: stock_packaging_calculator
|
||||
#: model:ir.model,name:stock_packaging_calculator.model_product_product
|
||||
msgid "Product"
|
||||
msgstr ""
|
||||
|
||||
#. module: stock_packaging_calculator
|
||||
#: model:ir.model.fields,help:stock_packaging_calculator.field_product_product__packaging_contained_mapping
|
||||
msgid "Technical field to store contained packaging. "
|
||||
msgstr ""
|
||||
1
stock_packaging_calculator/models/__init__.py
Normal file
1
stock_packaging_calculator/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import product
|
||||
143
stock_packaging_calculator/models/product.py
Normal file
143
stock_packaging_calculator/models/product.py
Normal file
@@ -0,0 +1,143 @@
|
||||
# Copyright 2020 Camptocamp SA
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from odoo import api, models
|
||||
from odoo.tools import float_compare
|
||||
|
||||
from odoo.addons.base_sparse_field.models.fields import Serialized
|
||||
|
||||
# Unify records as we mix up w/ UoM
|
||||
Packaging = namedtuple("Packaging", "id name qty is_unit")
|
||||
|
||||
|
||||
class Product(models.Model):
|
||||
_inherit = "product.product"
|
||||
|
||||
packaging_contained_mapping = Serialized(
|
||||
compute="_compute_packaging_contained_mapping",
|
||||
help="Technical field to store contained packaging. ",
|
||||
)
|
||||
|
||||
@api.depends("packaging_ids.qty")
|
||||
def _compute_packaging_contained_mapping(self):
|
||||
for rec in self:
|
||||
rec.packaging_contained_mapping = rec._packaging_contained_mapping()
|
||||
|
||||
def _packaging_contained_mapping(self):
|
||||
"""Produce a mapping of packaging and contained packagings.
|
||||
|
||||
Used mainly for `product_qty_by_packaging` but can be used
|
||||
to display info as you prefer.
|
||||
|
||||
:returns: a dictionary in the form {pkg.id: [contained packages]}
|
||||
"""
|
||||
res = {}
|
||||
packaging = self._ordered_packaging()
|
||||
for i, pkg in enumerate(packaging):
|
||||
if pkg.is_unit:
|
||||
# skip minimal unit
|
||||
continue
|
||||
res[pkg.id] = self._product_qty_by_packaging(packaging[i + 1 :], pkg.qty)
|
||||
return res
|
||||
|
||||
def product_qty_by_packaging(self, prod_qty, with_contained=False):
|
||||
"""Calculate quantity by packaging.
|
||||
|
||||
The minimal quantity is always represented by the UoM of the product.
|
||||
|
||||
Limitation: fractional quantities are lost.
|
||||
|
||||
:prod_qty: total qty to satisfy.
|
||||
:with_contained: include calculation of contained packagings.
|
||||
|
||||
eg: 1 pallet contains 4 big boxes and 6 little boxes.
|
||||
|
||||
:returns: list of dict in the form
|
||||
|
||||
[{id: 1, qty: qty_per_package, name: package_name}]
|
||||
|
||||
If `with_contained` is passed, each element will include
|
||||
the quantity of smaller packaging, like:
|
||||
|
||||
{contained: [{id: 1, qty: 4, name: "Big box"}]}
|
||||
"""
|
||||
self.ensure_one()
|
||||
return self._product_qty_by_packaging(
|
||||
self._ordered_packaging(),
|
||||
prod_qty,
|
||||
with_contained=with_contained,
|
||||
)
|
||||
|
||||
def _ordered_packaging(self):
|
||||
"""Prepare packaging ordered by qty and exclude empty ones.
|
||||
|
||||
Use ctx key `_packaging_filter` to pass a function to filter packaging
|
||||
to be considered.
|
||||
|
||||
Use ctx key `_packaging_name_getter` to pass a function to change
|
||||
the display name of the packaging.
|
||||
"""
|
||||
custom_filter = self.env.context.get("_packaging_filter", lambda x: x)
|
||||
name_getter = self.env.context.get("_packaging_name_getter", lambda x: x.name)
|
||||
packagings = sorted(
|
||||
[
|
||||
Packaging(x.id, name_getter(x), x.qty, False)
|
||||
for x in self.packaging_ids.filtered(custom_filter)
|
||||
# Exclude the ones w/ zero qty as they are useless for the math
|
||||
if x.qty
|
||||
],
|
||||
reverse=True,
|
||||
key=lambda x: x.qty,
|
||||
)
|
||||
# Add minimal unit
|
||||
packagings.append(
|
||||
# NOTE: the ID here could clash w/ one of the packaging's.
|
||||
# If you create a mapping based on IDs, keep this in mind.
|
||||
# You can use `is_unit` to check this.
|
||||
Packaging(self.uom_id.id, self.uom_id.name, self.uom_id.factor, True)
|
||||
)
|
||||
return packagings
|
||||
|
||||
def _product_qty_by_packaging(self, pkg_by_qty, qty, with_contained=False):
|
||||
"""Produce a list of dictionaries of packaging info."""
|
||||
# TODO: refactor to handle fractional quantities (eg: 0.5 Kg)
|
||||
res = []
|
||||
prepare_values = self.env.context.get(
|
||||
"_packaging_values_handler", self._prepare_qty_by_packaging_values
|
||||
)
|
||||
for pkg in pkg_by_qty:
|
||||
qty_per_pkg, qty = self._qty_by_pkg(pkg.qty, qty)
|
||||
if qty_per_pkg:
|
||||
value = prepare_values(pkg, qty_per_pkg)
|
||||
if with_contained:
|
||||
contained = None
|
||||
if not pkg.is_unit:
|
||||
mapping = self.packaging_contained_mapping
|
||||
# integer keys are serialized as strings :/
|
||||
contained = mapping.get(str(pkg.id))
|
||||
value["contained"] = contained
|
||||
res.append(value)
|
||||
if not qty:
|
||||
break
|
||||
return res
|
||||
|
||||
def _qty_by_pkg(self, pkg_qty, qty):
|
||||
"""Calculate qty needed for given package qty."""
|
||||
qty_per_pkg = 0
|
||||
while (
|
||||
float_compare(qty - pkg_qty, 0.0, precision_digits=self.uom_id.rounding)
|
||||
>= 0.0
|
||||
):
|
||||
qty -= pkg_qty
|
||||
qty_per_pkg += 1
|
||||
return qty_per_pkg, qty
|
||||
|
||||
def _prepare_qty_by_packaging_values(self, packaging, qty_per_pkg):
|
||||
return {
|
||||
"id": packaging.id,
|
||||
"qty": qty_per_pkg,
|
||||
"name": packaging.name,
|
||||
"is_unit": packaging.is_unit,
|
||||
}
|
||||
1
stock_packaging_calculator/readme/CONTRIBUTORS.rst
Normal file
1
stock_packaging_calculator/readme/CONTRIBUTORS.rst
Normal file
@@ -0,0 +1 @@
|
||||
* Simone Orsi <simahawk@gmail.com>
|
||||
1
stock_packaging_calculator/readme/DESCRIPTION.rst
Normal file
1
stock_packaging_calculator/readme/DESCRIPTION.rst
Normal file
@@ -0,0 +1 @@
|
||||
Basic module providing an helper method to calculate the quantity of product by packaging.
|
||||
4
stock_packaging_calculator/readme/ROADMAP.rst
Normal file
4
stock_packaging_calculator/readme/ROADMAP.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
TODO
|
||||
|
||||
1. Fractional quantities (eg: 0.5 Kg) are lost when counting units
|
||||
2. Maybe rely on `packaging_uom`
|
||||
36
stock_packaging_calculator/readme/USAGE.rst
Normal file
36
stock_packaging_calculator/readme/USAGE.rst
Normal file
@@ -0,0 +1,36 @@
|
||||
Imagine you have the following packagings:
|
||||
|
||||
* Pallet: 1000 Units
|
||||
* Big box: 500 Units
|
||||
* Box: 50 Units
|
||||
|
||||
and you have to pick from your warehouse 2860 Units.
|
||||
|
||||
Then you can do:
|
||||
|
||||
.. code-block::
|
||||
|
||||
>>> product.product_qty_by_packaging(2860)
|
||||
|
||||
[
|
||||
{"id": 1, "qty": 2, "name": "Pallet"},
|
||||
{"id": 2, "qty": 1, "name": "Big box"},
|
||||
{"id": 3, "qty": 7, "name": "Box"},
|
||||
{"id": 100, "qty": 10, "name": "Units"},
|
||||
]
|
||||
|
||||
With this you can show a proper message to warehouse operators to quickly pick the quantity they need.
|
||||
|
||||
Optionally you can get contained packaging by passing `with_contained` flag:
|
||||
|
||||
|
||||
.. code-block::
|
||||
|
||||
>>> product.product_qty_by_packaging(2860, with_contained=True)
|
||||
|
||||
[
|
||||
{"id": 1, "qty": 2, "name": "Pallet", "contained": [{"id": 2, "qty": 2, "name": "Big box"}]},
|
||||
{"id": 2, "qty": 1, "name": "Big box", "contained": [{"id": 3, "qty": 10, "name": "Box"}]},
|
||||
{"id": 3, "qty": 7, "name": "Box", "contained": [{"id": 100, "qty": 50, "name": "Units"}]},
|
||||
{"id": 100, "qty": 10, "name": "Units", "contained": []},},
|
||||
]
|
||||
BIN
stock_packaging_calculator/static/description/icon.png
Normal file
BIN
stock_packaging_calculator/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
472
stock_packaging_calculator/static/description/index.html
Normal file
472
stock_packaging_calculator/static/description/index.html
Normal file
@@ -0,0 +1,472 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
|
||||
<title>Stock packaging calculator</title>
|
||||
<style type="text/css">
|
||||
|
||||
/*
|
||||
:Author: David Goodger (goodger@python.org)
|
||||
:Id: $Id: html4css1.css 7952 2016-07-26 18:15:59Z milde $
|
||||
:Copyright: This stylesheet has been placed in the public domain.
|
||||
|
||||
Default cascading style sheet for the HTML output of Docutils.
|
||||
|
||||
See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
|
||||
customize this style sheet.
|
||||
*/
|
||||
|
||||
/* used to remove borders from tables and images */
|
||||
.borderless, table.borderless td, table.borderless th {
|
||||
border: 0 }
|
||||
|
||||
table.borderless td, table.borderless th {
|
||||
/* Override padding for "table.docutils td" with "! important".
|
||||
The right padding separates the table cells. */
|
||||
padding: 0 0.5em 0 0 ! important }
|
||||
|
||||
.first {
|
||||
/* Override more specific margin styles with "! important". */
|
||||
margin-top: 0 ! important }
|
||||
|
||||
.last, .with-subtitle {
|
||||
margin-bottom: 0 ! important }
|
||||
|
||||
.hidden {
|
||||
display: none }
|
||||
|
||||
.subscript {
|
||||
vertical-align: sub;
|
||||
font-size: smaller }
|
||||
|
||||
.superscript {
|
||||
vertical-align: super;
|
||||
font-size: smaller }
|
||||
|
||||
a.toc-backref {
|
||||
text-decoration: none ;
|
||||
color: black }
|
||||
|
||||
blockquote.epigraph {
|
||||
margin: 2em 5em ; }
|
||||
|
||||
dl.docutils dd {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Uncomment (and remove this text!) to get bold-faced definition list terms
|
||||
dl.docutils dt {
|
||||
font-weight: bold }
|
||||
*/
|
||||
|
||||
div.abstract {
|
||||
margin: 2em 5em }
|
||||
|
||||
div.abstract p.topic-title {
|
||||
font-weight: bold ;
|
||||
text-align: center }
|
||||
|
||||
div.admonition, div.attention, div.caution, div.danger, div.error,
|
||||
div.hint, div.important, div.note, div.tip, div.warning {
|
||||
margin: 2em ;
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.admonition p.admonition-title, div.hint p.admonition-title,
|
||||
div.important p.admonition-title, div.note p.admonition-title,
|
||||
div.tip p.admonition-title {
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
div.attention p.admonition-title, div.caution p.admonition-title,
|
||||
div.danger p.admonition-title, div.error p.admonition-title,
|
||||
div.warning p.admonition-title, .code .error {
|
||||
color: red ;
|
||||
font-weight: bold ;
|
||||
font-family: sans-serif }
|
||||
|
||||
/* Uncomment (and remove this text!) to get reduced vertical space in
|
||||
compound paragraphs.
|
||||
div.compound .compound-first, div.compound .compound-middle {
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
div.compound .compound-last, div.compound .compound-middle {
|
||||
margin-top: 0.5em }
|
||||
*/
|
||||
|
||||
div.dedication {
|
||||
margin: 2em 5em ;
|
||||
text-align: center ;
|
||||
font-style: italic }
|
||||
|
||||
div.dedication p.topic-title {
|
||||
font-weight: bold ;
|
||||
font-style: normal }
|
||||
|
||||
div.figure {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
div.footer, div.header {
|
||||
clear: both;
|
||||
font-size: smaller }
|
||||
|
||||
div.line-block {
|
||||
display: block ;
|
||||
margin-top: 1em ;
|
||||
margin-bottom: 1em }
|
||||
|
||||
div.line-block div.line-block {
|
||||
margin-top: 0 ;
|
||||
margin-bottom: 0 ;
|
||||
margin-left: 1.5em }
|
||||
|
||||
div.sidebar {
|
||||
margin: 0 0 0.5em 1em ;
|
||||
border: medium outset ;
|
||||
padding: 1em ;
|
||||
background-color: #ffffee ;
|
||||
width: 40% ;
|
||||
float: right ;
|
||||
clear: right }
|
||||
|
||||
div.sidebar p.rubric {
|
||||
font-family: sans-serif ;
|
||||
font-size: medium }
|
||||
|
||||
div.system-messages {
|
||||
margin: 5em }
|
||||
|
||||
div.system-messages h1 {
|
||||
color: red }
|
||||
|
||||
div.system-message {
|
||||
border: medium outset ;
|
||||
padding: 1em }
|
||||
|
||||
div.system-message p.system-message-title {
|
||||
color: red ;
|
||||
font-weight: bold }
|
||||
|
||||
div.topic {
|
||||
margin: 2em }
|
||||
|
||||
h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
|
||||
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
|
||||
margin-top: 0.4em }
|
||||
|
||||
h1.title {
|
||||
text-align: center }
|
||||
|
||||
h2.subtitle {
|
||||
text-align: center }
|
||||
|
||||
hr.docutils {
|
||||
width: 75% }
|
||||
|
||||
img.align-left, .figure.align-left, object.align-left, table.align-left {
|
||||
clear: left ;
|
||||
float: left ;
|
||||
margin-right: 1em }
|
||||
|
||||
img.align-right, .figure.align-right, object.align-right, table.align-right {
|
||||
clear: right ;
|
||||
float: right ;
|
||||
margin-left: 1em }
|
||||
|
||||
img.align-center, .figure.align-center, object.align-center {
|
||||
display: block;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
table.align-center {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
|
||||
.align-left {
|
||||
text-align: left }
|
||||
|
||||
.align-center {
|
||||
clear: both ;
|
||||
text-align: center }
|
||||
|
||||
.align-right {
|
||||
text-align: right }
|
||||
|
||||
/* reset inner alignment in figures */
|
||||
div.align-right {
|
||||
text-align: inherit }
|
||||
|
||||
/* div.align-center * { */
|
||||
/* text-align: left } */
|
||||
|
||||
.align-top {
|
||||
vertical-align: top }
|
||||
|
||||
.align-middle {
|
||||
vertical-align: middle }
|
||||
|
||||
.align-bottom {
|
||||
vertical-align: bottom }
|
||||
|
||||
ol.simple, ul.simple {
|
||||
margin-bottom: 1em }
|
||||
|
||||
ol.arabic {
|
||||
list-style: decimal }
|
||||
|
||||
ol.loweralpha {
|
||||
list-style: lower-alpha }
|
||||
|
||||
ol.upperalpha {
|
||||
list-style: upper-alpha }
|
||||
|
||||
ol.lowerroman {
|
||||
list-style: lower-roman }
|
||||
|
||||
ol.upperroman {
|
||||
list-style: upper-roman }
|
||||
|
||||
p.attribution {
|
||||
text-align: right ;
|
||||
margin-left: 50% }
|
||||
|
||||
p.caption {
|
||||
font-style: italic }
|
||||
|
||||
p.credits {
|
||||
font-style: italic ;
|
||||
font-size: smaller }
|
||||
|
||||
p.label {
|
||||
white-space: nowrap }
|
||||
|
||||
p.rubric {
|
||||
font-weight: bold ;
|
||||
font-size: larger ;
|
||||
color: maroon ;
|
||||
text-align: center }
|
||||
|
||||
p.sidebar-title {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold ;
|
||||
font-size: larger }
|
||||
|
||||
p.sidebar-subtitle {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
p.topic-title {
|
||||
font-weight: bold }
|
||||
|
||||
pre.address {
|
||||
margin-bottom: 0 ;
|
||||
margin-top: 0 ;
|
||||
font: inherit }
|
||||
|
||||
pre.literal-block, pre.doctest-block, pre.math, pre.code {
|
||||
margin-left: 2em ;
|
||||
margin-right: 2em }
|
||||
|
||||
pre.code .ln { color: grey; } /* line numbers */
|
||||
pre.code, code { background-color: #eeeeee }
|
||||
pre.code .comment, code .comment { color: #5C6576 }
|
||||
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
|
||||
pre.code .literal.string, code .literal.string { color: #0C5404 }
|
||||
pre.code .name.builtin, code .name.builtin { color: #352B84 }
|
||||
pre.code .deleted, code .deleted { background-color: #DEB0A1}
|
||||
pre.code .inserted, code .inserted { background-color: #A3D289}
|
||||
|
||||
span.classifier {
|
||||
font-family: sans-serif ;
|
||||
font-style: oblique }
|
||||
|
||||
span.classifier-delimiter {
|
||||
font-family: sans-serif ;
|
||||
font-weight: bold }
|
||||
|
||||
span.interpreted {
|
||||
font-family: sans-serif }
|
||||
|
||||
span.option {
|
||||
white-space: nowrap }
|
||||
|
||||
span.pre {
|
||||
white-space: pre }
|
||||
|
||||
span.problematic {
|
||||
color: red }
|
||||
|
||||
span.section-subtitle {
|
||||
/* font-size relative to parent (h1..h6 element) */
|
||||
font-size: 80% }
|
||||
|
||||
table.citation {
|
||||
border-left: solid 1px gray;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docinfo {
|
||||
margin: 2em 4em }
|
||||
|
||||
table.docutils {
|
||||
margin-top: 0.5em ;
|
||||
margin-bottom: 0.5em }
|
||||
|
||||
table.footnote {
|
||||
border-left: solid 1px black;
|
||||
margin-left: 1px }
|
||||
|
||||
table.docutils td, table.docutils th,
|
||||
table.docinfo td, table.docinfo th {
|
||||
padding-left: 0.5em ;
|
||||
padding-right: 0.5em ;
|
||||
vertical-align: top }
|
||||
|
||||
table.docutils th.field-name, table.docinfo th.docinfo-name {
|
||||
font-weight: bold ;
|
||||
text-align: left ;
|
||||
white-space: nowrap ;
|
||||
padding-left: 0 }
|
||||
|
||||
/* "booktabs" style (no vertical lines) */
|
||||
table.docutils.booktabs {
|
||||
border: 0px;
|
||||
border-top: 2px solid;
|
||||
border-bottom: 2px solid;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table.docutils.booktabs * {
|
||||
border: 0px;
|
||||
}
|
||||
table.docutils.booktabs th {
|
||||
border-bottom: thin solid;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
|
||||
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
|
||||
font-size: 100% }
|
||||
|
||||
ul.auto-toc {
|
||||
list-style-type: none }
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="document" id="stock-packaging-calculator">
|
||||
<h1 class="title">Stock packaging calculator</h1>
|
||||
|
||||
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_packaging_calculator"><img alt="OCA/stock-logistics-warehouse" src="https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/stock-logistics-warehouse-13-0/stock-logistics-warehouse-13-0-stock_packaging_calculator"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/153/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
|
||||
<p>Basic module providing an helper method to calculate the quantity of product by packaging.</p>
|
||||
<div class="admonition important">
|
||||
<p class="first admonition-title">Important</p>
|
||||
<p class="last">This is an alpha version, the data model and design can change at any time without warning.
|
||||
Only for development or testing purpose, do not use in production.
|
||||
<a class="reference external" href="https://odoo-community.org/page/development-status">More details on development status</a></p>
|
||||
</div>
|
||||
<p><strong>Table of contents</strong></p>
|
||||
<div class="contents local topic" id="contents">
|
||||
<ul class="simple">
|
||||
<li><a class="reference internal" href="#usage" id="id1">Usage</a></li>
|
||||
<li><a class="reference internal" href="#known-issues-roadmap" id="id2">Known issues / Roadmap</a></li>
|
||||
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
|
||||
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
|
||||
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
|
||||
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
|
||||
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="usage">
|
||||
<h1><a class="toc-backref" href="#id1">Usage</a></h1>
|
||||
<p>Imagine you have the following packagings:</p>
|
||||
<ul class="simple">
|
||||
<li>Pallet: 1000 Units</li>
|
||||
<li>Big box: 500 Units</li>
|
||||
<li>Box: 50 Units</li>
|
||||
</ul>
|
||||
<p>and you have to pick from your warehouse 2860 Units.</p>
|
||||
<p>Then you can do:</p>
|
||||
<blockquote>
|
||||
<pre class="code literal-block">
|
||||
>>> product.product_qty_by_packaging(2860)
|
||||
|
||||
[
|
||||
{"id": 1, "qty": 2, "name": "Pallet"},
|
||||
{"id": 2, "qty": 1, "name": "Big box"},
|
||||
{"id": 3, "qty": 7, "name": "Box"},
|
||||
{"id": 100, "qty": 10, "name": "Units"},
|
||||
]
|
||||
</pre>
|
||||
</blockquote>
|
||||
<p>With this you can show a proper message to warehouse operators to quickly pick the quantity they need.</p>
|
||||
<p>Optionally you can get contained packaging by passing <cite>with_contained</cite> flag:</p>
|
||||
<blockquote>
|
||||
<pre class="code literal-block">
|
||||
>>> product.product_qty_by_packaging(2860, with_contained=True)
|
||||
|
||||
[
|
||||
{"id": 1, "qty": 2, "name": "Pallet", "contained": [{"id": 2, "qty": 2, "name": "Big box"}]},
|
||||
{"id": 2, "qty": 1, "name": "Big box", "contained": [{"id": 3, "qty": 10, "name": "Box"}]},
|
||||
{"id": 3, "qty": 7, "name": "Box", "contained": [{"id": 100, "qty": 50, "name": "Units"}]},
|
||||
{"id": 100, "qty": 10, "name": "Units", "contained": []},},
|
||||
]
|
||||
</pre>
|
||||
</blockquote>
|
||||
</div>
|
||||
<div class="section" id="known-issues-roadmap">
|
||||
<h1><a class="toc-backref" href="#id2">Known issues / Roadmap</a></h1>
|
||||
<p>TODO</p>
|
||||
<ol class="arabic simple">
|
||||
<li>Fractional quantities (eg: 0.5 Kg) are lost when counting units</li>
|
||||
<li>Maybe rely on <cite>packaging_uom</cite></li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="section" id="bug-tracker">
|
||||
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
|
||||
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues">GitHub Issues</a>.
|
||||
In case of trouble, please check there if your issue has already been reported.
|
||||
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||
<a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/issues/new?body=module:%20stock_packaging_calculator%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
|
||||
<p>Do not contact contributors directly about support or help with technical issues.</p>
|
||||
</div>
|
||||
<div class="section" id="credits">
|
||||
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
|
||||
<div class="section" id="authors">
|
||||
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Camptocamp</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="contributors">
|
||||
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
|
||||
<ul class="simple">
|
||||
<li>Simone Orsi <<a class="reference external" href="mailto:simahawk@gmail.com">simahawk@gmail.com</a>></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="maintainers">
|
||||
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
|
||||
<p>This module is maintained by the OCA.</p>
|
||||
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
|
||||
<p>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.</p>
|
||||
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/stock-logistics-warehouse/tree/13.0/stock_packaging_calculator">OCA/stock-logistics-warehouse</a> project on GitHub.</p>
|
||||
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
1
stock_packaging_calculator/tests/__init__.py
Normal file
1
stock_packaging_calculator/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_packaging_calc
|
||||
376
stock_packaging_calculator/tests/test_packaging_calc.py
Normal file
376
stock_packaging_calculator/tests/test_packaging_calc.py
Normal file
@@ -0,0 +1,376 @@
|
||||
# Copyright 2020 Camptocamp SA
|
||||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl)
|
||||
from odoo.tests import SavepointCase
|
||||
|
||||
|
||||
class TestCalc(SavepointCase):
|
||||
|
||||
at_install = False
|
||||
post_install = True
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
|
||||
cls.uom_unit = cls.env.ref("uom.product_uom_unit")
|
||||
cls.product_a = cls.env["product.product"].create(
|
||||
{
|
||||
"name": "Product A",
|
||||
"uom_id": cls.uom_unit.id,
|
||||
"uom_po_id": cls.uom_unit.id,
|
||||
}
|
||||
)
|
||||
cls.pkg_box = cls.env["product.packaging"].create(
|
||||
{"name": "Box", "product_id": cls.product_a.id, "qty": 50}
|
||||
)
|
||||
cls.pkg_big_box = cls.env["product.packaging"].create(
|
||||
{"name": "Big Box", "product_id": cls.product_a.id, "qty": 200}
|
||||
)
|
||||
cls.pkg_pallet = cls.env["product.packaging"].create(
|
||||
{"name": "Pallet", "product_id": cls.product_a.id, "qty": 2000}
|
||||
)
|
||||
|
||||
def test_contained_mapping(self):
|
||||
self.assertEqual(
|
||||
self.product_a.packaging_contained_mapping,
|
||||
{
|
||||
str(self.pkg_pallet.id): [
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 10,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
],
|
||||
str(self.pkg_big_box.id): [
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 4,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
],
|
||||
str(self.pkg_box.id): [
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 50,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
# Update pkg qty
|
||||
self.pkg_pallet.qty = 4000
|
||||
self.assertEqual(
|
||||
self.product_a.packaging_contained_mapping,
|
||||
{
|
||||
str(self.pkg_pallet.id): [
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 20,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
],
|
||||
str(self.pkg_big_box.id): [
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 4,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
],
|
||||
str(self.pkg_box.id): [
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 50,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
)
|
||||
|
||||
def test_calc_1(self):
|
||||
"""Test easy behavior 1."""
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_pallet.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_pallet.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 3,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 5,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
]
|
||||
self.assertEqual(self.product_a.product_qty_by_packaging(2655), expected)
|
||||
|
||||
def test_calc_2(self):
|
||||
"""Test easy behavior 2."""
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 3,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
]
|
||||
self.assertEqual(self.product_a.product_qty_by_packaging(350), expected)
|
||||
|
||||
def test_calc_3(self):
|
||||
"""Test easy behavior 3."""
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 30,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
]
|
||||
self.assertEqual(self.product_a.product_qty_by_packaging(80), expected)
|
||||
|
||||
def test_calc_6(self):
|
||||
"""Test fractional qty is lost."""
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
]
|
||||
self.assertEqual(self.product_a.product_qty_by_packaging(50.5), expected)
|
||||
|
||||
def test_calc_filter(self):
|
||||
"""Test packaging filter."""
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 13,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 5,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
]
|
||||
self.assertEqual(
|
||||
self.product_a.with_context(
|
||||
_packaging_filter=lambda x: x != self.pkg_pallet
|
||||
).product_qty_by_packaging(2655),
|
||||
expected,
|
||||
)
|
||||
|
||||
def test_calc_name_get(self):
|
||||
"""Test custom name getter."""
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_pallet.id,
|
||||
"qty": 1,
|
||||
"name": "FOO " + self.pkg_pallet.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 3,
|
||||
"name": "FOO " + self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 1,
|
||||
"name": "FOO " + self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 5,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
]
|
||||
self.assertEqual(
|
||||
self.product_a.with_context(
|
||||
_packaging_name_getter=lambda x: "FOO " + x.name
|
||||
).product_qty_by_packaging(2655),
|
||||
expected,
|
||||
)
|
||||
|
||||
def test_calc_custom_values(self):
|
||||
"""Test custom values handler."""
|
||||
expected = [
|
||||
{"my_qty": 1, "foo": self.pkg_pallet.name},
|
||||
{"my_qty": 3, "foo": self.pkg_big_box.name},
|
||||
{"my_qty": 1, "foo": self.pkg_box.name},
|
||||
{"my_qty": 5, "foo": self.uom_unit.name},
|
||||
]
|
||||
self.assertEqual(
|
||||
self.product_a.with_context(
|
||||
_packaging_values_handler=lambda pkg, qty_per_pkg: {
|
||||
"my_qty": qty_per_pkg,
|
||||
"foo": pkg.name,
|
||||
}
|
||||
).product_qty_by_packaging(2655),
|
||||
expected,
|
||||
)
|
||||
|
||||
def test_calc_sub1(self):
|
||||
"""Test contained packaging behavior 1."""
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_pallet.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_pallet.name,
|
||||
"is_unit": False,
|
||||
"contained": [
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 10,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 3,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
"contained": [
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 4,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
"contained": [
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 50,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 5,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
"contained": None,
|
||||
},
|
||||
]
|
||||
self.assertEqual(
|
||||
self.product_a.product_qty_by_packaging(2655, with_contained=True),
|
||||
expected,
|
||||
)
|
||||
|
||||
def test_calc_sub2(self):
|
||||
"""Test contained packaging behavior 1."""
|
||||
self.pkg_box.qty = 30
|
||||
expected = [
|
||||
{
|
||||
"id": self.pkg_pallet.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_pallet.name,
|
||||
"is_unit": False,
|
||||
"contained": [
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 10,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": self.pkg_big_box.id,
|
||||
"qty": 3,
|
||||
"name": self.pkg_big_box.name,
|
||||
"is_unit": False,
|
||||
"contained": [
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 6,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
},
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 20,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": self.pkg_box.id,
|
||||
"qty": 1,
|
||||
"name": self.pkg_box.name,
|
||||
"is_unit": False,
|
||||
"contained": [
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 30,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"id": self.uom_unit.id,
|
||||
"qty": 25,
|
||||
"name": self.uom_unit.name,
|
||||
"is_unit": True,
|
||||
"contained": None,
|
||||
},
|
||||
]
|
||||
self.assertEqual(
|
||||
self.product_a.product_qty_by_packaging(2655, with_contained=True),
|
||||
expected,
|
||||
)
|
||||
Reference in New Issue
Block a user