Skip to content

Commit

Permalink
Merge PR OCA#608 into 13.0
Browse files Browse the repository at this point in the history
Signed-off-by jgrandguillaume
  • Loading branch information
OCA-git-bot committed May 29, 2020
2 parents 0d3f9a4 + 7d4943b commit e658913
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 0 deletions.
2 changes: 2 additions & 0 deletions oca_dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
product-attribute https://github.com/grindtildeath/product-attribute 13.0-mig-product_packaging_dimension
stock-logistics-workflow https://github.com/grindtildeath/stock-logistics-workflow 13.0-mig-stock_quant_package_product_packaging
6 changes: 6 additions & 0 deletions setup/stock_quant_package_dimension/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions stock_quant_package_dimension/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions stock_quant_package_dimension/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
{
"name": "Stock Quant Package Dimension",
"summary": "Use dimensions on packages",
"version": "13.0.1.0.0",
"development_status": "Alpha",
"category": "Warehouse Management",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"stock",
"product_packaging_dimension",
"stock_quant_package_product_packaging",
],
"data": ["views/stock_quant_package.xml"],
}
1 change: 1 addition & 0 deletions stock_quant_package_dimension/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import stock_quant_package
51 changes: 51 additions & 0 deletions stock_quant_package_dimension/models/stock_quant_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2019 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl)
from odoo import api, fields, models


class StockQuantPackage(models.Model):
_inherit = "stock.quant.package"

pack_weight = fields.Float("Weight (kg)")
# lngth IS NOT A TYPO: https://github.com/odoo/odoo/issues/41353
lngth = fields.Integer("Length (mm)", help="length in millimeters")
width = fields.Integer("Width (mm)", help="width in millimeters")
height = fields.Integer("Height (mm)", help="height in millimeters")
volume = fields.Float(
"Volume (m³)",
digits=(8, 4),
compute="_compute_volume",
readonly=True,
store=False,
help="volume in cubic meters",
)

@api.depends("lngth", "width", "height")
def _compute_volume(self):
for pack in self:
pack.volume = (pack.lngth * pack.width * pack.height) / 1000.0 ** 3

def auto_assign_packaging(self):
self = self.with_context(_auto_assign_packaging=True)
res = super().auto_assign_packaging()
return res

def write(self, vals):
res = super().write(vals)
if self.env.context.get("_auto_assign_packaging") and vals.get(
"product_packaging_id"
):
for package in self:
package.onchange_product_packaging_id()
return res

@api.onchange("product_packaging_id")
def onchange_product_packaging_id(self):
if self.product_packaging_id:
vals = self.product_packaging_id.read(
fields=["lngth", "width", "height", "max_weight"]
)[0]
vals["pack_weight"] = vals["max_weight"]
vals.pop("id")
vals.pop("max_weight")
self.update(vals)
1 change: 1 addition & 0 deletions stock_quant_package_dimension/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Akim Juillerat <akim.juillerat@camptocamp.com>
1 change: 1 addition & 0 deletions stock_quant_package_dimension/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module adds dimension fields on stock packages.
19 changes: 19 additions & 0 deletions stock_quant_package_dimension/views/stock_quant_package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="view_quant_package_form_inherit" model="ir.ui.view">
<field name="name">stock.quant.package.form.inherit</field>
<field name="model">stock.quant.package</field>
<field name="inherit_id" ref="stock.view_quant_package_form" />
<field name="arch" type="xml">
<xpath expr="//group[field[@name='company_id']]" position="after">
<group name="dimensions" string="Dimensions">
<field name="lngth" />
<field name="width" />
<field name="height" />
<field name="pack_weight" />
<field name="volume" />
</group>
</xpath>
</field>
</record>
</odoo>

0 comments on commit e658913

Please sign in to comment.