Dear comunity
I have an issue on a implementation done on Tryton 5.0 related to stock quantity by wharehouse. The implementation was done on a SaleLine Class implementation, and the issue is related to performance.
The use case is on sales, on each sale, when the user add a line, he / her needs to know the current stock in order to know wich is the max item to sell. Yes, when the sale is done, the sale verifies the stocks, but usually the user sell more than 36 lines, and more than 10 item per lines, then wait to know the stock ant the end of sale is not a good idea. Coder implements the way on verify items number on each line adding, the problem is the performance, response is too slow on _get_quantity method. Ihave tried to improve it on a database level, but was not enough.
Any suggestabout it?
Bests
class SaleLine(metaclass=PoolMeta):
__name__ = 'sale.line'
...
def get_warehouse_qty(self, name=None):
if self.sale:
if not self.sale.warehouse:
self.raise_user_error('La venta necesita un almacén seleccionado')
else:
if self.product:
Product = Pool().get('product.product')
location_ids = [self.sale.warehouse.id]
product_quantity = Product._get_quantity([self.product], 'quantity', location_ids)
qty = product_quantity[self.product.id]
return Decimal(qty)
return Decimal('0')