Skip to content

Commit

Permalink
[ADD] product_dimension_net (#298)
Browse files Browse the repository at this point in the history
* [ADD] product_dimension_net
  • Loading branch information
kevinkhao authored May 15, 2024
1 parent 0386c39 commit 5e4a4d9
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 0 deletions.
7 changes: 7 additions & 0 deletions product_dimension_net/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=====================
Product Dimension Net
=====================

Net product dimensions

Refers to product dimension when it is outside of its retail package.
1 change: 1 addition & 0 deletions product_dimension_net/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions product_dimension_net/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Product Dimension Net",
"summary": """
Net product dimensions""",
"version": "16.0.1.0.0",
"license": "AGPL-3",
"author": "Akretion",
"website": "https://github.com/akretion/ak-odoo-incubator",
"depends": ["product_dimension"],
"data": [
"views/product_product.xml",
],
"demo": [],
}
1 change: 1 addition & 0 deletions product_dimension_net/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_product
41 changes: 41 additions & 0 deletions product_dimension_net/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


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

product_length_net = fields.Float(
"Longueur (net)", help="Longueur de l'article en dehors de son emballage"
)
product_height_net = fields.Float(
"Hauteur (net)", help="Hauteur de l'article en dehors de son emballage"
)
product_width_net = fields.Float(
"Largeur (net)", help="Largeur de l'article en dehors de son emballage"
)
volume_net = fields.Float(
string="Volume (net)",
help="Volume de l'article en dehors de son emballage",
compute="_compute_volume_net",
readonly=False,
store=True,
)

@api.depends(
"product_length_net",
"product_height_net",
"product_width_net",
"dimensional_uom_id",
)
def _compute_volume_net(self):
template_obj = self.env["product.template"]
for product in self:
product.volume = template_obj._calc_volume(
product.product_length_net,
product.product_height_net,
product.product_width_net,
product.dimensional_uom_id,
)
36 changes: 36 additions & 0 deletions product_dimension_net/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2023 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

product_length_net = fields.Float(
related="product_variant_ids.product_length_net", readonly=False
)
product_height_net = fields.Float(
related="product_variant_ids.product_height_net", readonly=False
)
product_width_net = fields.Float(
related="product_variant_ids.product_width_net", readonly=False
)
volume_net = fields.Float(
string="Volume (net)",
compute="_compute_volume_net",
readonly=False,
store=True,
)

@api.depends(
"product_length", "product_height", "product_width", "dimensional_uom_id"
)
def _compute_volume_net(self):
for template in self:
template.volume = template._calc_volume(
template.product_length_net,
template.product_height_net,
template.product_width_net,
template.dimensional_uom_id,
)
21 changes: 21 additions & 0 deletions product_dimension_net/views/product_product.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Akretion
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="product_normal_form_view">
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view" />
<field name="arch" type="xml">
<xpath expr="//group[@name='dimensions']" position="after">
<group string="Dimensions (net)" name="dimensions_net" colspan="2">
<field name="product_length_net" />
<field name="product_height_net" />
<field name="product_width_net" />
<field name="volume_net" />
</group>
</xpath>
</field>
</record>

</odoo>
29 changes: 29 additions & 0 deletions product_dimension_net/views/product_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 Akretion
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>

<record model="ir.ui.view" id="product_template_form_view_dimensions">
<field name="model">product.template</field>
<field
name="inherit_id"
ref="product_dimension.product_template_only_form_view"
/>
<field name="arch" type="xml">
<xpath expr="//page[@name='description']" position="inside">
<group
string="Dimensions (net = sans packaging)"
name="dimensions_net"
colspan="2"
attrs="{'invisible': [('product_variant_count', '&gt;', 1)]}"
>
<field name="product_length_net" />
<field name="product_height_net" />
<field name="product_width_net" />
<field name="volume_net" />
</group>
</xpath>
</field>
</record>

</odoo>
6 changes: 6 additions & 0 deletions setup/product_dimension_net/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,
)

0 comments on commit 5e4a4d9

Please sign in to comment.