mirror of
https://github.com/NaN-tic/trytond-stock_number_of_packages.git
synced 2023-12-14 07:52:52 +01:00
Allow to have quantity not computed from number of packages in outgoing shipments
This commit is contained in:
parent
9d48761f91
commit
c0af2aaa2f
14
move.py
14
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,
|
||||
|
|
30
package.py
30
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
|
||||
|
|
Loading…
Reference in a new issue