Merge multiple dimensions on package and package type

Closes #12139
This commit is contained in:
Cédric Krier
2023-03-14 16:38:06 +01:00
parent 8a0c3f12c7
commit cb93430699
11 changed files with 65 additions and 189 deletions
+1
View File
@@ -1,3 +1,4 @@
* Remove packaging prefix from dimensions
* Remove support for Python 3.7
* Add support for Python 3.11
+34 -42
View File
@@ -80,54 +80,49 @@ class ConfigurationSequence(metaclass=PoolMeta):
class MeasurementsMixin:
__slots__ = ()
packaging_length = fields.Float(
"Packaging Length", digits='packaging_length_uom',
length = fields.Float(
"Length", digits='length_uom',
help="The length of the package.")
packaging_length_uom = fields.Many2One(
'product.uom', "Packaging Length UOM",
length_uom = fields.Many2One(
'product.uom', "Length UOM",
domain=[('category', '=', Id('product', 'uom_cat_length'))],
states={
'required': Bool(Eval('packaging_length')),
},
depends=['packaging_length'])
packaging_height = fields.Float(
"Packaging Height", digits='packaging_height_uom',
'required': Bool(Eval('length')),
})
height = fields.Float(
"Height", digits='height_uom',
help="The height of the package.")
packaging_height_uom = fields.Many2One(
'product.uom', "Packaging Height UOM",
height_uom = fields.Many2One(
'product.uom', "Height UOM",
domain=[('category', '=', Id('product', 'uom_cat_length'))],
states={
'required': Bool(Eval('packaging_height')),
},
depends=['packaging_height'])
packaging_width = fields.Float(
"Packaging Width", digits='packaging_width_uom',
'required': Bool(Eval('height')),
})
width = fields.Float(
"Width", digits='width_uom',
help="The width of the package.")
packaging_width_uom = fields.Many2One(
'product.uom', "Packaging Width UOM",
width_uom = fields.Many2One(
'product.uom', "Width UOM",
domain=[('category', '=', Id('product', 'uom_cat_length'))],
states={
'required': Bool(Eval('packaging_width')),
},
depends=['packaging_width'])
'required': Bool(Eval('width')),
})
packaging_volume = fields.Float(
"Packaging Volume", digits='packaging_volume_uom',
states={
'readonly': (
Bool(Eval('packaging_length'))
& Bool(Eval('packaging_height'))
& Bool(Eval('packaging_width'))),
Bool(Eval('length'))
& Bool(Eval('height'))
& Bool(Eval('width'))),
},
depends=['packaging_length', 'packaging_height', 'packaging_width'],
help="The volume of the package.")
packaging_volume_uom = fields.Many2One(
'product.uom', "Packaging Volume UOM",
domain=[('category', '=', Id('product', 'uom_cat_volume'))],
states={
'required': Bool(Eval('packaging_volume')),
},
depends=['packaging_volume'])
})
packaging_weight = fields.Float(
"Packaging Weight", digits='packaging_weight_uom',
@@ -141,22 +136,22 @@ class MeasurementsMixin:
@fields.depends(
'packaging_volume', 'packaging_volume_uom',
'packaging_length', 'packaging_length_uom',
'packaging_height', 'packaging_height_uom',
'packaging_width', 'packaging_width_uom')
'length', 'length_uom',
'height', 'height_uom',
'width', 'width_uom')
def on_change_with_packaging_volume(self):
pool = Pool()
ModelData = pool.get('ir.model.data')
Uom = pool.get('product.uom')
if not all([self.packaging_volume_uom,
self.packaging_length, self.packaging_length_uom,
self.packaging_height, self.packaging_height_uom,
self.packaging_width, self.packaging_width_uom]):
self.length, self.length_uom,
self.height, self.height_uom,
self.width, self.width_uom]):
if all([
self.packaging_length,
self.packaging_height,
self.packaging_width]):
self.length,
self.height,
self.width]):
return
return self.packaging_volume
@@ -164,14 +159,11 @@ class MeasurementsMixin:
cubic_meter = Uom(ModelData.get_id('product', 'uom_cubic_meter'))
length = Uom.compute_qty(
self.packaging_length_uom, self.packaging_length, meter,
round=False)
self.length_uom, self.length, meter, round=False)
height = Uom.compute_qty(
self.packaging_height_uom, self.packaging_height, meter,
round=False)
self.height_uom, self.height, meter, round=False)
width = Uom.compute_qty(
self.packaging_width_uom, self.packaging_width, meter,
round=False)
self.width_uom, self.width, meter, round=False)
return Uom.compute_qty(
cubic_meter, length * height * width, self.packaging_volume_uom)
@@ -86,22 +86,22 @@ Package products::
>>> PackageType = Model.get('stock.package.type')
>>> box = PackageType(name='box')
>>> box.packaging_length = 80
>>> box.packaging_length_uom, = ProductUom.find([('name', '=', "Centimeter")])
>>> box.packaging_width = 1
>>> box.packaging_width_uom, = ProductUom.find([('name', '=', "Meter")])
>>> box.packaging_height_uom = box.packaging_length_uom
>>> box.length = 80
>>> box.length_uom, = ProductUom.find([('name', '=', "Centimeter")])
>>> box.width = 1
>>> box.width_uom, = ProductUom.find([('name', '=', "Meter")])
>>> box.height_uom = box.length_uom
>>> box.packaging_volume
>>> box.packaging_volume_uom, = ProductUom.find([('name', '=', "Cubic meter")])
>>> box.save()
>>> package1 = shipment_out.packages.new(type=box)
>>> package1.packaging_length
>>> package1.length
80.0
>>> package1.packaging_height = 50
>>> package1.height = 50
>>> package1.packaging_volume
0.4
>>> package_child = package1.children.new(shipment=shipment_out, type=box)
>>> package_child.packaging_height = 100
>>> package_child.height = 100
>>> moves = package_child.moves.find()
>>> len(moves)
2
@@ -112,7 +112,7 @@ Package products::
...
PackageValidationError: ...
>>> package1.packaging_height = 120
>>> package1.height = 120
>>> package1.packaging_volume
0.96
+9 -9
View File
@@ -20,17 +20,17 @@ this repository contains the full copyright notices and license terms. -->
<field name="children" colspan="4"/>
</page>
<page string="Measurements" col="3" id="measurements">
<label name="packaging_length"/>
<field name="packaging_length"/>
<field name="packaging_length_uom" widget="selection"/>
<label name="length"/>
<field name="length"/>
<field name="length_uom" widget="selection"/>
<label name="packaging_height"/>
<field name="packaging_height"/>
<field name="packaging_height_uom" widget="selection"/>
<label name="height"/>
<field name="height"/>
<field name="height_uom" widget="selection"/>
<label name="packaging_width"/>
<field name="packaging_width"/>
<field name="packaging_width_uom" widget="selection"/>
<label name="width"/>
<field name="width"/>
<field name="width_uom" widget="selection"/>
<label name="packaging_volume"/>
<field name="packaging_volume"/>
@@ -8,17 +8,17 @@ this repository contains the full copyright notices and license terms. -->
<field name="active"/>
<notebook colspan="4">
<page string="Measurements" col="3" id="measurements">
<label name="packaging_length"/>
<field name="packaging_length"/>
<field name="packaging_length_uom" widget="selection"/>
<label name="length"/>
<field name="length"/>
<field name="length_uom" widget="selection"/>
<label name="packaging_height"/>
<field name="packaging_height"/>
<field name="packaging_height_uom" widget="selection"/>
<label name="height"/>
<field name="height"/>
<field name="height_uom" widget="selection"/>
<label name="packaging_width"/>
<field name="packaging_width"/>
<field name="packaging_width_uom" widget="selection"/>
<label name="width"/>
<field name="width"/>
<field name="width_uom" widget="selection"/>
<label name="packaging_volume"/>
<field name="packaging_volume"/>
+1
View File
@@ -1,3 +1,4 @@
* Move dimensions definition to stock_package module
* Remove support for Python 3.7
* Add support for Python 3.11
@@ -8,7 +8,6 @@ from . import carrier, stock
def register():
Pool.register(
stock.PackageType,
stock.Package,
stock.ShipmentOut,
stock.ShipmentInReturn,
+2 -82
View File
@@ -9,7 +9,7 @@ from trytond.i18n import gettext
from trytond.model import ModelView, Workflow, fields
from trytond.model.exceptions import AccessError
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Bool, Eval, Id
from trytond.pyson import Eval
from trytond.report import Report
from trytond.transaction import Transaction
from trytond.wizard import StateAction, StateTransition, Wizard
@@ -24,76 +24,7 @@ else:
file_id = store_prefix = None
class DimensionsMixin(object):
__slots__ = ()
length = fields.Float('Length', digits=(16, Eval('length_digits', 2)))
length_uom = fields.Many2One('product.uom', 'Length Unit',
domain=[
('category', '=', Id('product', 'uom_cat_length')),
],
states={
'required': Bool(Eval('length')),
},
depends={'length_digits'})
length_digits = fields.Function(fields.Integer('Length Digits'),
'on_change_with_length_digits')
height = fields.Float('Height', digits=(16, Eval('height_digits', 2)))
height_uom = fields.Many2One('product.uom', 'Height Unit',
domain=[
('category', '=', Id('product', 'uom_cat_length')),
],
states={
'required': Bool(Eval('height')),
},
depends={'height_digits'})
height_digits = fields.Function(fields.Integer('Height Digits'),
'on_change_with_height_digits')
width = fields.Float('Width', digits=(16, Eval('width_digits', 2)))
width_uom = fields.Many2One('product.uom', 'Width Unit',
domain=[
('category', '=', Id('product', 'uom_cat_length')),
],
states={
'required': Bool(Eval('width')),
},
depends={'width_digits'})
width_digits = fields.Function(fields.Integer('Width Digits'),
'on_change_with_width_digits')
@fields.depends('length_uom')
def on_change_with_length_digits(self, name=None):
return (self.length_uom.digits if self.length_uom
else self.default_length_digits())
@fields.depends('height_uom')
def on_change_with_height_digits(self, name=None):
return (self.height_uom.digits if self.height_uom
else self.default_height_digits())
@fields.depends('width_uom')
def on_change_with_width_digits(self, name=None):
return (self.width_uom.digits if self.width_uom
else self.default_width_digits())
@classmethod
def default_length_digits(cls):
return 2
@classmethod
def default_height_digits(cls):
return 2
@classmethod
def default_width_digits(cls):
return 2
class PackageType(DimensionsMixin, metaclass=PoolMeta):
__name__ = 'stock.package.type'
class Package(DimensionsMixin, metaclass=PoolMeta):
class Package(metaclass=PoolMeta):
__name__ = 'stock.package'
shipping_reference = fields.Char('Shipping Reference',
@@ -170,17 +101,6 @@ class Package(DimensionsMixin, metaclass=PoolMeta):
('shipping_reference', *clause[1:]),
]
@fields.depends('type')
def on_change_type(self):
super().on_change_type()
if self.type:
self.length = self.type.length
self.length_uom = self.type.length_uom
self.height = self.type.height
self.height_uom = self.type.height_uom
self.width = self.type.width
self.width_uom = self.type.width_uom
@classmethod
def copy(cls, packages, default=None):
if default is None:
-6
View File
@@ -4,12 +4,6 @@ this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="package_type_view_form">
<field name="model">stock.package.type</field>
<field name="inherit" ref="stock_package.package_type_view_form"/>
<field name="name">package_type_form</field>
</record>
<record model="ir.ui.view" id="package_view_form">
<field name="model">stock.package</field>
<field name="inherit" ref="stock_package.package_view_form"/>
@@ -2,19 +2,6 @@
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//page[@id='measurements']" position="inside">
<label name="length"/>
<field name="length"/>
<field name="length_uom"/>
<label name="height"/>
<field name="height"/>
<field name="height_uom"/>
<label name="width"/>
<field name="width"/>
<field name="width_uom"/>
</xpath>
<xpath expr="//field[@name='shipment']" position="after">
<label name="shipping_reference"/>
<group col="-1" id="shipping_reference">
@@ -1,18 +0,0 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of
this repository contains the full copyright notices and license terms. -->
<data>
<xpath expr="//page[@id='measurements']" position="inside">
<label name="length"/>
<field name="length"/>
<field name="length_uom"/>
<label name="height"/>
<field name="height"/>
<field name="height_uom"/>
<label name="width"/>
<field name="width"/>
<field name="width_uom"/>
</xpath>
</data>