From c0af2aaa2f3d073b19430cb00b4e9a7f363f1f75 Mon Sep 17 00:00:00 2001 From: Guillem Barba Date: Tue, 1 Dec 2015 13:32:16 +0100 Subject: [PATCH] Allow to have quantity not computed from number of packages in outgoing shipments --- move.py | 14 +++++++++++--- package.py | 30 +----------------------------- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/move.py b/move.py index f51a9fb..5778824 100644 --- a/move.py +++ b/move.py @@ -133,11 +133,19 @@ class Move(StockPackagedMixin): @classmethod def validate(cls, records): super(Move, cls).validate(records) + pool = Pool() + InventoryLine = pool.get('stock.inventory.line') + ShipmentOut = pool.get('stock.shipment.out') + for move in records: + check = (isinstance(move.shipment, ShipmentOut) or + isinstance(move.origin, InventoryLine)) if move.state in ('assigned', 'done'): - move.check_package( - move._get_internal_quantity(move.quantity, move.uom, - move.product)) + with Transaction().set_context( + no_check_quantity_number_of_packages=check): + move.check_package( + move._get_internal_quantity(move.quantity, move.uom, + move.product)) @classmethod def compute_quantities_query(cls, location_ids, with_childs=False, diff --git a/package.py b/package.py index e026ed4..13d6f85 100644 --- a/package.py +++ b/package.py @@ -54,7 +54,7 @@ class PackagedMixin: return { 'quantity': self.number_of_packages * package_qty } - return self.on_change_quantity() + return {} @fields.depends('package', 'number_of_packages') def on_change_number_of_packages(self): @@ -74,34 +74,6 @@ class PackagedMixin: 'quantity': package_qty * self.number_of_packages, } - @fields.depends('quantity', 'product', 'package') - def on_change_quantity(self): - if hasattr(self, 'lot') and getattr(self, 'lot', None): - package_qty = self.lot.package_qty - elif self.package and self.package.qty: - package_qty = self.package.qty - else: - package_qty = None - - if self.quantity and package_qty != None: - quantize = Decimal(str(self.product.default_uom.rounding)) - self.number_of_packages = int( - math.ceil(Decimal(str(self.quantity)).quantize(quantize) - / Decimal(str(package_qty)).quantize(quantize))) - self.quantity = self.number_of_packages * package_qty - else: - self.number_of_packages = None - - try: - res = super(PackagedMixin, self).on_change_quantity() - except AttributeError: - res = {} - res.update({ - 'number_of_packages': self.number_of_packages, - 'quantity': self.quantity, - }) - return res - def check_package(self, quantity): """ Check if package is required and all realted data is exists, and