fix: Se corrige procesamiento de venta al finalizar envío
This commit is contained in:
parent
e79d6d8c8d
commit
d152cd9d53
146
move.py
146
move.py
@ -1,42 +1,63 @@
|
||||
from trytond.model import fields, ModelSQL, ModelView, Workflow, dualmethod
|
||||
from trytond.model import fields, ModelView, Workflow
|
||||
from trytond.modules.company import CompanyReport
|
||||
from trytond.modules.company.model import employee_field, set_employee
|
||||
from trytond.modules.company.model import set_employee
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval, If
|
||||
from trytond.exceptions import UserError
|
||||
from itertools import groupby
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
from trytond.transaction import Transaction, without_check_access
|
||||
|
||||
from functools import wraps
|
||||
|
||||
|
||||
def process_sale(moves_field):
|
||||
def _process_sale(func):
|
||||
@wraps(func)
|
||||
def wrapper(cls, shipments):
|
||||
pool = Pool()
|
||||
Sale = pool.get('sale.sale')
|
||||
transaction = Transaction()
|
||||
context = transaction.context
|
||||
with without_check_access():
|
||||
sales = set(m.sale for s in cls.browse(shipments)
|
||||
for m in getattr(s, moves_field) if m.sale)
|
||||
func(cls, shipments)
|
||||
if sales:
|
||||
with transaction.set_context(
|
||||
queue_batch=context.get('queue_batch', True)):
|
||||
Sale.__queue__.process(sales)
|
||||
return wrapper
|
||||
return _process_sale
|
||||
|
||||
|
||||
class Move(metaclass=PoolMeta):
|
||||
"Stock Move"
|
||||
__name__ = "stock.move"
|
||||
|
||||
|
||||
return_equipment = fields.Boolean("Devolución", states={'invisible': If(~Eval('product_equipment'), True),
|
||||
'readonly': (Eval('state').in_(['cancelled', 'done'])),}
|
||||
'readonly': (Eval('state').in_(['cancelled', 'done'])), }
|
||||
)
|
||||
equipment = fields.Many2One('optical_equipment.equipment', "Equipment",
|
||||
domain=[If(Eval('return_equipment', True),
|
||||
('state', 'in', ['uncontrated','contrated']),
|
||||
('state', 'in', ['uncontrated', 'contrated']),
|
||||
('state', '=', 'registred')),
|
||||
('product','=', Eval('product'))
|
||||
('product', '=', Eval('product'))
|
||||
],
|
||||
states={'invisible': If(~Eval('product_equipment'), True),
|
||||
'readonly': (Eval('state').in_(['cancelled', 'done'])),},
|
||||
'readonly': (Eval('state').in_(['cancelled', 'done'])), },
|
||||
depends=['product_equipment', 'move_type'])
|
||||
equipment_serial = fields.Function(fields.Char('Serial',
|
||||
states={'readonly': True,
|
||||
'invisible': If(~Eval('product_equipment'), True)},
|
||||
depends=['product_equipment']),
|
||||
'get_equipment_serial')
|
||||
product_equipment = fields.Function(fields.Boolean("It Equipment"),'get_product_equipment')
|
||||
product_equipment = fields.Function(fields.Boolean("It Equipment"), 'get_product_equipment')
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(Move, cls).__setup__()
|
||||
cls.origin.states['required']=False
|
||||
|
||||
cls.origin.states['required'] = False
|
||||
|
||||
@fields.depends('product')
|
||||
def get_product_equipment(self, product):
|
||||
if self.product.equipment:
|
||||
@ -50,7 +71,7 @@ class Move(metaclass=PoolMeta):
|
||||
return self.equipment.serial
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
@fields.depends('product', 'equipment', 'uom')
|
||||
def on_change_product(self):
|
||||
if self.product:
|
||||
@ -73,27 +94,28 @@ class ShipmentOut(metaclass=PoolMeta):
|
||||
|
||||
service_maintenance_initial = fields.Boolean('Maintenance Initial', states={'readonly': True})
|
||||
sale_type = fields.Char('Type sale origin')
|
||||
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(ShipmentOut, cls).__setup__()
|
||||
cls._buttons.update({
|
||||
'maintenance_initial': {
|
||||
'invisible': ((Eval('service_maintenance_initial',True))
|
||||
'invisible': ((Eval('service_maintenance_initial', True))
|
||||
| (Eval('sale_type').in_(['maintenance', 'replaces'])))}
|
||||
})
|
||||
|
||||
|
||||
@classmethod
|
||||
def view_attributes(cls):
|
||||
return super(ShipmentOut, cls).view_attributes() + [
|
||||
('//page[@name="inventory_moves"]', 'states', {
|
||||
'invisible': False,
|
||||
}),]
|
||||
}),]
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@Workflow.transition('done')
|
||||
@set_employee('done_by')
|
||||
@process_sale('outgoing_moves')
|
||||
def done(cls, shipments):
|
||||
pool = Pool()
|
||||
Move = pool.get('stock.move')
|
||||
@ -104,25 +126,25 @@ class ShipmentOut(metaclass=PoolMeta):
|
||||
for move in shipment.inventory_moves:
|
||||
count = 0
|
||||
if move.equipment:
|
||||
equipment = move.equipment
|
||||
equipment = move.equipment
|
||||
Id = equipment.id
|
||||
equipment = Equipments.search(['id', '=',Id])[0]
|
||||
equipment = Equipments.search(['id', '=', Id])[0]
|
||||
equipment.propietary = shipment.customer.id
|
||||
equipment.propietary_address= shipment.delivery_address.id
|
||||
equipment.propietary_address = shipment.delivery_address.id
|
||||
equipment.location = Locations.search(['name', '=', 'Cliente'])[0].id
|
||||
equipment.state="uncontrated"
|
||||
equipment.state = "uncontrated"
|
||||
equipment.shipment_destination = shipment
|
||||
equipment.sale_destination = shipment.outgoing_moves[count].origin
|
||||
equipment.propietarys += (shipment.customer,)
|
||||
equipment.maintenance_frequency = "6" if shipment.customer.customer_type == "ips" else "12"
|
||||
count+=1
|
||||
count += 1
|
||||
equipment.save()
|
||||
else:
|
||||
count+=1
|
||||
count += 1
|
||||
|
||||
Move.delete([
|
||||
m for s in shipments for m in s.outgoing_moves
|
||||
if m.state == 'staging'])
|
||||
m for s in shipments for m in s.outgoing_moves
|
||||
if m.state == 'staging'])
|
||||
|
||||
Move.do([m for s in shipments for m in s.outgoing_moves])
|
||||
for company, c_shipments in groupby(
|
||||
@ -130,8 +152,8 @@ class ShipmentOut(metaclass=PoolMeta):
|
||||
with Transaction().set_context(company=company.id):
|
||||
today = Date.today()
|
||||
cls.write([s for s in c_shipments if not s.effective_date], {
|
||||
'effective_date': today,
|
||||
})
|
||||
'effective_date': today,
|
||||
})
|
||||
|
||||
@classmethod
|
||||
@ModelView.button
|
||||
@ -150,20 +172,20 @@ class ShipmentOut(metaclass=PoolMeta):
|
||||
for move in shipment.inventory_moves:
|
||||
if move.product_equipment and move.equipment:
|
||||
serial = True
|
||||
number_equipments +=1
|
||||
number_equipments += 1
|
||||
if move.equipment.product.maintenance_required:
|
||||
maintenance_required +=1
|
||||
maintenance_required += 1
|
||||
elif not move.product_equipment:
|
||||
serial = True
|
||||
else:
|
||||
serial = False
|
||||
|
||||
|
||||
if number_equipments < 1 or maintenance_required < 1:
|
||||
shipment.service_maintenance_initial = True
|
||||
shipment.save()
|
||||
#raise UserError(str("No se generó un mantenimiento inicial dado que los equipos no requiren mantenimiento, ó no se encontró ningún producto de tipo equipo en este envío."))
|
||||
# raise UserError(str("No se generó un mantenimiento inicial dado que los equipos no requiren mantenimiento, ó no se encontró ningún producto de tipo equipo en este envío."))
|
||||
break
|
||||
|
||||
|
||||
sale_origin = shipment.outgoing_moves[0].origin.sale
|
||||
maintenanceService = MaintenanceService.search(['sale_origin', '=', sale_origin])
|
||||
if maintenanceService == []:
|
||||
@ -187,26 +209,27 @@ class ShipmentOut(metaclass=PoolMeta):
|
||||
service_maintenance=maintenanceService.id,
|
||||
maintenance_type='initial',
|
||||
propietary=shipment.customer.id,
|
||||
equipment_calibrate= True if move.equipment.product.calibration else False,
|
||||
equipment_calibrate=True if move.equipment.product.calibration else False,
|
||||
propietary_address=shipment.delivery_address.id,
|
||||
equipment=move.equipment.id,
|
||||
initial_operation = move.equipment.product.initial_operation,
|
||||
check_equipment = move.equipment.product.template.check_equipment,
|
||||
check_electric_system = move.equipment.product.template.check_electric_system,
|
||||
clean_int_ext = move.equipment.product.template.clean_int_ext,
|
||||
clean_eyes = move.equipment.product.template.clean_eyes,
|
||||
check_calibration = move.equipment.product.template.check_calibration,
|
||||
temperature_min = maintenanceService.temperature_min,
|
||||
temperature_max = maintenanceService.temperature_max,
|
||||
temperature_uom = maintenanceService.temperature_uom.id,
|
||||
moisture_min = maintenanceService.moisture_min,
|
||||
moisture_max = maintenanceService.moisture_max,
|
||||
moisture_uom = maintenanceService.moisture_uom.id)
|
||||
initial_operation=move.equipment.product.initial_operation,
|
||||
check_equipment=move.equipment.product.template.check_equipment,
|
||||
check_electric_system=move.equipment.product.template.check_electric_system,
|
||||
clean_int_ext=move.equipment.product.template.clean_int_ext,
|
||||
clean_eyes=move.equipment.product.template.clean_eyes,
|
||||
check_calibration=move.equipment.product.template.check_calibration,
|
||||
temperature_min=maintenanceService.temperature_min,
|
||||
temperature_max=maintenanceService.temperature_max,
|
||||
temperature_uom=maintenanceService.temperature_uom.id,
|
||||
moisture_min=maintenanceService.moisture_min,
|
||||
moisture_max=maintenanceService.moisture_max,
|
||||
moisture_uom=maintenanceService.moisture_uom.id)
|
||||
maintenance.save()
|
||||
shipment.service_maintenance_initial = True
|
||||
shipment.save()
|
||||
else:
|
||||
raise UserError(str('Por favor Primero debe Asignar un serial a todos los Equipos.'))
|
||||
raise UserError(
|
||||
str('Por favor Primero debe Asignar un serial a todos los Equipos.'))
|
||||
|
||||
|
||||
class ShipmentInternal(metaclass=PoolMeta):
|
||||
@ -227,10 +250,10 @@ class ShipmentInternal(metaclass=PoolMeta):
|
||||
if move.equipment:
|
||||
move.equipment.location = shipment.to_location
|
||||
move.equipment.save()
|
||||
|
||||
|
||||
Move.do([m for s in shipments for m in s.incoming_moves])
|
||||
cls.write([s for s in shipments if not s.effective_date], {
|
||||
'effective_date': Date.today(),})
|
||||
'effective_date': Date.today(), })
|
||||
|
||||
|
||||
class ShipmentOutReturn(metaclass=PoolMeta):
|
||||
@ -251,25 +274,26 @@ class ShipmentOutReturn(metaclass=PoolMeta):
|
||||
Move.do([m for s in shipments for m in s.incoming_moves])
|
||||
for s in shipments:
|
||||
for m in s.incoming_moves:
|
||||
if m.equipment:
|
||||
equipment = m.equipment
|
||||
Id = equipment.id
|
||||
equipment = Equipments.search(['id', '=',Id])[0]
|
||||
equipment.propietary = s.company.party.id
|
||||
equipment.propietary_address= s.company.party.addresses[0].id
|
||||
equipment.location = m.to_location.id
|
||||
equipment.state="registred"
|
||||
equipment.save()
|
||||
|
||||
if m.equipment:
|
||||
equipment = m.equipment
|
||||
Id = equipment.id
|
||||
equipment = Equipments.search(['id', '=', Id])[0]
|
||||
equipment.propietary = s.company.party.id
|
||||
equipment.propietary_address = s.company.party.addresses[0].id
|
||||
equipment.location = m.to_location.id
|
||||
equipment.state = "registred"
|
||||
equipment.save()
|
||||
|
||||
cls.create_inventory_moves(shipments)
|
||||
# Set received state to allow done transition
|
||||
cls.write(shipments, {'state': 'received'})
|
||||
to_do = [s for s in shipments
|
||||
if s.warehouse_storage == s.warehouse_input]
|
||||
if s.warehouse_storage == s.warehouse_input]
|
||||
|
||||
|
||||
if to_do:
|
||||
cls.done(to_do)
|
||||
|
||||
|
||||
class PickingListDeliveryReport(CompanyReport):
|
||||
__name__ = 'stock.shipment.out.picking_list1'
|
||||
|
||||
@ -287,7 +311,7 @@ class PickingListDeliveryReport(CompanyReport):
|
||||
|
||||
return context
|
||||
|
||||
|
||||
|
||||
class CapacitationReport(CompanyReport):
|
||||
__name__ = 'stock.shipment.out.capacitation_note'
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user