Move package weight to stock_shipment_measurements module
issue6157 review32961002
This commit is contained in:
1 parent
4e4d6eaf45
commit
4d106cc2ac
4 files changed
+6
-91
No files matched your search
@@ -1,2 +1,4 @@
|
||||
* Move package weight to stock_shipment_measurements module
|
||||
|
||||
Version 4.2.0 - 2016-11-28
|
||||
* Initial release
|
||||
* Initial release
|
||||
@@ -2,7 +2,7 @@
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.model import Workflow, ModelView, fields
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pyson import Eval, Bool, Id
|
||||
from trytond.wizard import Wizard, StateTransition
|
||||
|
||||
@@ -87,10 +87,6 @@ class Package:
|
||||
'readonly': Eval('_parent_shipment', {}).get('carrier', False),
|
||||
})
|
||||
shipping_label = fields.Binary('Shipping Label', readonly=True)
|
||||
weight = fields.Function(
|
||||
fields.Float('Weight', digits=None,
|
||||
help="The total weight of the package's moves in kg."),
|
||||
'get_weight')
|
||||
|
||||
@classmethod
|
||||
def search_rec_name(cls, name, clause):
|
||||
@@ -99,35 +95,6 @@ class Package:
|
||||
('shipping_reference',) + tuple(clause[:1]),
|
||||
]
|
||||
|
||||
def get_weight(self, name):
|
||||
pool = Pool()
|
||||
UoM = pool.get('product.uom')
|
||||
UoMCategory = pool.get('product.uom.category')
|
||||
ModelData = pool.get('ir.model.data')
|
||||
|
||||
weight_category = UoMCategory(
|
||||
ModelData.get_id('product', 'uom_cat_weight'))
|
||||
kg = UoM(ModelData.get_id('product', 'uom_kilogram'))
|
||||
|
||||
weight = 0
|
||||
for move in self.moves:
|
||||
# Use first the weight from product_measurements as it could
|
||||
# include some handling weight
|
||||
if move.product.weight is not None:
|
||||
weight += UoM.compute_qty(
|
||||
move.product.weight_uom,
|
||||
move.internal_quantity * move.product.weight,
|
||||
kg, round=False)
|
||||
elif move.product.default_uom.category == weight_category:
|
||||
weight += UoM.compute_qty(
|
||||
move.product.default_uom,
|
||||
move.internal_quantity,
|
||||
kg, round=False)
|
||||
else:
|
||||
weight = None
|
||||
break
|
||||
return weight
|
||||
|
||||
|
||||
class ShipmentOut:
|
||||
__metaclass__ = PoolMeta
|
||||
|
||||
+1
-56
@@ -3,69 +3,14 @@
|
||||
|
||||
import unittest
|
||||
|
||||
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
from trytond.tests.test_tryton import suite as test_suite
|
||||
from trytond.pool import Pool
|
||||
|
||||
|
||||
class StockPackageShippingTestCase(ModuleTestCase):
|
||||
'Test Stock Package Shipping module'
|
||||
module = 'stock_package_shipping'
|
||||
|
||||
@with_transaction()
|
||||
def test_package_weight(self):
|
||||
'Test package weight'
|
||||
pool = Pool()
|
||||
UoM = pool.get('product.uom')
|
||||
Template = pool.get('product.template')
|
||||
Product = pool.get('product.product')
|
||||
Move = pool.get('stock.move')
|
||||
Package = pool.get('stock.package')
|
||||
|
||||
u, = UoM.search([('symbol', '=', 'u')])
|
||||
g, = UoM.search([('symbol', '=', 'g')])
|
||||
|
||||
template_u = Template(
|
||||
name='Product Unit',
|
||||
type='goods',
|
||||
list_price=0,
|
||||
cost_price=0,
|
||||
default_uom=u,
|
||||
weight=500,
|
||||
weight_uom=g,
|
||||
)
|
||||
template_u.save()
|
||||
product_u = Product(template=template_u)
|
||||
product_u.save()
|
||||
|
||||
template_g = Template(
|
||||
name='Product Gram',
|
||||
type='goods',
|
||||
list_price=0,
|
||||
cost_price=0,
|
||||
default_uom=g,
|
||||
)
|
||||
template_g.save()
|
||||
product_g = Product(template=template_g)
|
||||
product_g.save()
|
||||
|
||||
move1 = Move(
|
||||
product=product_u,
|
||||
uom=u,
|
||||
quantity=1,
|
||||
internal_quantity=1,
|
||||
)
|
||||
move2 = Move(
|
||||
product=product_g,
|
||||
uom=g,
|
||||
quantity=200,
|
||||
internal_quantity=200,
|
||||
)
|
||||
|
||||
package = Package()
|
||||
package.moves = [move1, move2]
|
||||
self.assertEqual(package.get_weight('weight'), 0.7)
|
||||
|
||||
|
||||
def suite():
|
||||
suite = test_suite()
|
||||
|
||||
@@ -7,6 +7,7 @@ depends:
|
||||
product
|
||||
stock
|
||||
stock_package
|
||||
stock_shipment_measurements
|
||||
sale_shipment_cost
|
||||
product_measurements
|
||||
xml:
|
||||
|
||||
Reference in new issue
Block a user