Allow updating dimensions on package
issue9846 review304891002
This commit is contained in:
1 parent
d320c6bc94
commit
0975fca0c2
4 files changed
+65
-5
No files matched your search
@@ -1,3 +1,4 @@
|
||||
* Allow updating dimensions on package
|
||||
* Add configuration option to store label in filestore
|
||||
* Manage supplier shipment returns
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ else:
|
||||
if local_version:
|
||||
version += '+' + '.'.join(local_version)
|
||||
|
||||
requires = []
|
||||
requires = ['python-sql >= 0.4']
|
||||
for dep in info.get('depends', []):
|
||||
if not re.match(r'(ir|res)(\W|$)', dep):
|
||||
requires.append(get_require_version('trytond_%s' % dep))
|
||||
|
||||
@@ -1,5 +1,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.
|
||||
from sql import Column
|
||||
|
||||
from trytond.config import config
|
||||
from trytond.i18n import gettext
|
||||
@@ -20,8 +21,8 @@ else:
|
||||
file_id = store_prefix = None
|
||||
|
||||
|
||||
class PackageType(metaclass=PoolMeta):
|
||||
__name__ = 'stock.package.type'
|
||||
class DimensionsMixin(object):
|
||||
__slots__ = ()
|
||||
|
||||
length = fields.Float('Length', digits=(16, Eval('length_digits', 2)),
|
||||
depends=['length_digits'])
|
||||
@@ -88,7 +89,11 @@ class PackageType(metaclass=PoolMeta):
|
||||
return 2
|
||||
|
||||
|
||||
class Package(metaclass=PoolMeta):
|
||||
class PackageType(DimensionsMixin, metaclass=PoolMeta):
|
||||
__name__ = 'stock.package.type'
|
||||
|
||||
|
||||
class Package(DimensionsMixin, metaclass=PoolMeta):
|
||||
__name__ = 'stock.package'
|
||||
|
||||
shipping_reference = fields.Char('Shipping Reference',
|
||||
@@ -100,6 +105,36 @@ class Package(metaclass=PoolMeta):
|
||||
file_id=file_id, store_prefix=store_prefix)
|
||||
shipping_label_id = fields.Char("Shipping Label ID", readonly=True)
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
pool = Pool()
|
||||
PackageType = pool.get('stock.package.type')
|
||||
cursor = Transaction().connection.cursor()
|
||||
table = cls.__table__()
|
||||
package_type = PackageType.__table__()
|
||||
table_h = cls.__table_handler__(module_name)
|
||||
dimension_columns = [
|
||||
'length', 'length_uom',
|
||||
'height', 'height_uom',
|
||||
'width', 'width_uom']
|
||||
dimension_exists = any(
|
||||
table_h.column_exist(c) for c in dimension_columns)
|
||||
|
||||
super().__register__(module_name)
|
||||
|
||||
# Migration from 5.8: Update dimensions on package from package_type
|
||||
if not dimension_exists:
|
||||
columns = []
|
||||
values = []
|
||||
for c in dimension_columns:
|
||||
columns.append(Column(table, c))
|
||||
values.append(package_type.select(
|
||||
Column(package_type, c),
|
||||
where=package_type.id == table.type))
|
||||
cursor.execute(*table.update(
|
||||
columns=columns,
|
||||
values=values))
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
domain = super(Package, cls).search_rec_name(name, clause)
|
||||
@@ -107,6 +142,16 @@ class Package(metaclass=PoolMeta):
|
||||
('shipping_reference',) + tuple(clause[1:]),
|
||||
]
|
||||
|
||||
@fields.depends('type')
|
||||
def on_change_type(self):
|
||||
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:
|
||||
|
||||
+15
-1
@@ -2,7 +2,21 @@
|
||||
<!-- 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="/form/field[@name='children']" position="after">
|
||||
<xpath expr="//field[@name='children']" position="after">
|
||||
<separator string="Dimensions" id="dimensions" colspan="4"/>
|
||||
<label name="length"/>
|
||||
<field name="length"/>
|
||||
<label name="length_uom"/>
|
||||
<field name="length_uom"/>
|
||||
<label name="height"/>
|
||||
<field name="height"/>
|
||||
<label name="height_uom"/>
|
||||
<field name="height_uom"/>
|
||||
<label name="width"/>
|
||||
<field name="width"/>
|
||||
<label name="width_uom"/>
|
||||
<field name="width_uom"/>
|
||||
<separator string="Shipping" id="shipping" colspan="4"/>
|
||||
<label name="shipping_reference"/>
|
||||
<field name="shipping_reference"/>
|
||||
<label name="shipping_label"/>
|
||||
|
||||
Reference in new issue
Block a user