button 'create_equipments' invisible in case to 'equipments_availables = True'
This commit is contained in:
parent
887ec2eeaa
commit
274a095b72
15
purchase.py
15
purchase.py
@ -2,7 +2,7 @@
|
|||||||
#txhis repository contains the full copyright notices and license terms
|
#txhis repository contains the full copyright notices and license terms
|
||||||
from trytond.pool import Pool, PoolMeta
|
from trytond.pool import Pool, PoolMeta
|
||||||
from trytond.model import ModelView, ModelSQL, fields
|
from trytond.model import ModelView, ModelSQL, fields
|
||||||
from trytond.pyson import Eval
|
from trytond.pyson import Eval, If, Bool
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
from trytond.i18n import gettext
|
from trytond.i18n import gettext
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
@ -18,14 +18,13 @@ class Purchase(metaclass=PoolMeta):
|
|||||||
super(Purchase, cls).__setup__()
|
super(Purchase, cls).__setup__()
|
||||||
cls._buttons.update({
|
cls._buttons.update({
|
||||||
'create_equipments': {
|
'create_equipments': {
|
||||||
'invisible': ~Eval('equipment_avalaible')},
|
'invisible': If(Bool(Eval('equipment_available')), True)},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
def create_equipments(cls, purchases):
|
def create_equipments(cls, purchases):
|
||||||
if len(purhcases) == 1:
|
if len(purchases) == 1:
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Equipment = pool.get('optical_equipment.equipment')
|
Equipment = pool.get('optical_equipment.equipment')
|
||||||
Line = pool.get('purchase.line')
|
Line = pool.get('purchase.line')
|
||||||
@ -33,6 +32,7 @@ class Purchase(metaclass=PoolMeta):
|
|||||||
purchase = purchases[0]
|
purchase = purchases[0]
|
||||||
|
|
||||||
for line in purchase.lines:
|
for line in purchase.lines:
|
||||||
|
if line.product.equipment:
|
||||||
equipment = Equipment(
|
equipment = Equipment(
|
||||||
company=line.company,
|
company=line.company,
|
||||||
equipment_type=line.product.equipment_type,
|
equipment_type=line.product.equipment_type,
|
||||||
@ -45,15 +45,20 @@ class Purchase(metaclass=PoolMeta):
|
|||||||
refurbish=line.refurbish,
|
refurbish=line.refurbish,
|
||||||
serial=line.serial_equipment,
|
serial=line.serial_equipment,
|
||||||
software_version=line.product.software_version)
|
software_version=line.product.software_version)
|
||||||
|
|
||||||
equipment.save()
|
equipment.save()
|
||||||
|
else:
|
||||||
|
continue
|
||||||
purchase.equipment_available = True
|
purchase.equipment_available = True
|
||||||
cls.save(purchases)
|
cls.save(purchases)
|
||||||
|
#raise UserError(str(purchase.equipment_available))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise InvalidNumberPurchases(
|
raise InvalidNumberPurchases(
|
||||||
gettext('purchase.msg_invalid_number_purchases'))
|
gettext('purchase.msg_invalid_number_purchases'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
|
Loading…
Reference in New Issue
Block a user