Allow add quantity with decimals and len > 5 in add product wizard

#162560
This commit is contained in:
Raimon Esteve 2023-10-23 11:24:53 +02:00
parent 6e34aa1157
commit 521bde0c4c

27
sale.py
View file

@ -361,6 +361,15 @@ class WizardAddProduct(Wizard):
self.start.last_product = product
return 'start'
def _product_domain(self, value):
return [
('salable', '=', True),
['OR',
('code','=', value),
('identifiers.code', '=', value),
('name', 'ilike', '%'+value+'%'),
]]
def transition_scan_(self):
pool = Pool()
Product = pool.get('product.product')
@ -371,15 +380,14 @@ class WizardAddProduct(Wizard):
except ValueError:
return False
product = None
value = self.start.input_value
quantity = qty(value)
if len(value) > 4:
quantity = None
if not quantity:
domain = ['OR', ('code','=', value),
('identifiers.code', '=', value),]
if (self.start.last_product and (quantity or quantity == 0.0)
and len(str(int(quantity))) < 5):
product = self.start.last_product
else:
domain = self._product_domain(value)
products = Product.search(domain)
if not products:
return 'start'
@ -389,15 +397,8 @@ class WizardAddProduct(Wizard):
return 'choose'
product, = products
self.start.last_product = product
if quantity and self.start.last_product:
product = self.start.last_product
if not product:
return 'start'
lines = self.add_sale_line(self.start.lines, product, quantity)
self.start.lines = lines
self.add_lines()