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 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.pool import Pool, PoolMeta
|
||||||
from trytond.pyson import Eval, If
|
from trytond.pyson import Eval, If
|
||||||
from trytond.exceptions import UserError
|
from trytond.exceptions import UserError
|
||||||
from itertools import groupby
|
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):
|
class Move(metaclass=PoolMeta):
|
||||||
"Stock Move"
|
"Stock Move"
|
||||||
__name__ = "stock.move"
|
__name__ = "stock.move"
|
||||||
|
|
||||||
|
|
||||||
return_equipment = fields.Boolean("Devolución", states={'invisible': If(~Eval('product_equipment'), True),
|
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",
|
equipment = fields.Many2One('optical_equipment.equipment', "Equipment",
|
||||||
domain=[If(Eval('return_equipment', True),
|
domain=[If(Eval('return_equipment', True),
|
||||||
('state', 'in', ['uncontrated','contrated']),
|
('state', 'in', ['uncontrated', 'contrated']),
|
||||||
('state', '=', 'registred')),
|
('state', '=', 'registred')),
|
||||||
('product','=', Eval('product'))
|
('product', '=', Eval('product'))
|
||||||
],
|
],
|
||||||
states={'invisible': If(~Eval('product_equipment'), True),
|
states={'invisible': If(~Eval('product_equipment'), True),
|
||||||
'readonly': (Eval('state').in_(['cancelled', 'done'])),},
|
'readonly': (Eval('state').in_(['cancelled', 'done'])), },
|
||||||
depends=['product_equipment', 'move_type'])
|
depends=['product_equipment', 'move_type'])
|
||||||
equipment_serial = fields.Function(fields.Char('Serial',
|
equipment_serial = fields.Function(fields.Char('Serial',
|
||||||
states={'readonly': True,
|
states={'readonly': True,
|
||||||
'invisible': If(~Eval('product_equipment'), True)},
|
'invisible': If(~Eval('product_equipment'), True)},
|
||||||
depends=['product_equipment']),
|
depends=['product_equipment']),
|
||||||
'get_equipment_serial')
|
'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
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
super(Move, cls).__setup__()
|
super(Move, cls).__setup__()
|
||||||
cls.origin.states['required']=False
|
cls.origin.states['required'] = False
|
||||||
|
|
||||||
@fields.depends('product')
|
@fields.depends('product')
|
||||||
def get_product_equipment(self, product):
|
def get_product_equipment(self, product):
|
||||||
if self.product.equipment:
|
if self.product.equipment:
|
||||||
@ -50,7 +71,7 @@ class Move(metaclass=PoolMeta):
|
|||||||
return self.equipment.serial
|
return self.equipment.serial
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@fields.depends('product', 'equipment', 'uom')
|
@fields.depends('product', 'equipment', 'uom')
|
||||||
def on_change_product(self):
|
def on_change_product(self):
|
||||||
if self.product:
|
if self.product:
|
||||||
@ -73,27 +94,28 @@ class ShipmentOut(metaclass=PoolMeta):
|
|||||||
|
|
||||||
service_maintenance_initial = fields.Boolean('Maintenance Initial', states={'readonly': True})
|
service_maintenance_initial = fields.Boolean('Maintenance Initial', states={'readonly': True})
|
||||||
sale_type = fields.Char('Type sale origin')
|
sale_type = fields.Char('Type sale origin')
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def __setup__(cls):
|
def __setup__(cls):
|
||||||
super(ShipmentOut, cls).__setup__()
|
super(ShipmentOut, cls).__setup__()
|
||||||
cls._buttons.update({
|
cls._buttons.update({
|
||||||
'maintenance_initial': {
|
'maintenance_initial': {
|
||||||
'invisible': ((Eval('service_maintenance_initial',True))
|
'invisible': ((Eval('service_maintenance_initial', True))
|
||||||
| (Eval('sale_type').in_(['maintenance', 'replaces'])))}
|
| (Eval('sale_type').in_(['maintenance', 'replaces'])))}
|
||||||
})
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def view_attributes(cls):
|
def view_attributes(cls):
|
||||||
return super(ShipmentOut, cls).view_attributes() + [
|
return super(ShipmentOut, cls).view_attributes() + [
|
||||||
('//page[@name="inventory_moves"]', 'states', {
|
('//page[@name="inventory_moves"]', 'states', {
|
||||||
'invisible': False,
|
'invisible': False,
|
||||||
}),]
|
}),]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
@Workflow.transition('done')
|
@Workflow.transition('done')
|
||||||
@set_employee('done_by')
|
@set_employee('done_by')
|
||||||
|
@process_sale('outgoing_moves')
|
||||||
def done(cls, shipments):
|
def done(cls, shipments):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
Move = pool.get('stock.move')
|
Move = pool.get('stock.move')
|
||||||
@ -104,25 +126,25 @@ class ShipmentOut(metaclass=PoolMeta):
|
|||||||
for move in shipment.inventory_moves:
|
for move in shipment.inventory_moves:
|
||||||
count = 0
|
count = 0
|
||||||
if move.equipment:
|
if move.equipment:
|
||||||
equipment = move.equipment
|
equipment = move.equipment
|
||||||
Id = equipment.id
|
Id = equipment.id
|
||||||
equipment = Equipments.search(['id', '=',Id])[0]
|
equipment = Equipments.search(['id', '=', Id])[0]
|
||||||
equipment.propietary = shipment.customer.id
|
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.location = Locations.search(['name', '=', 'Cliente'])[0].id
|
||||||
equipment.state="uncontrated"
|
equipment.state = "uncontrated"
|
||||||
equipment.shipment_destination = shipment
|
equipment.shipment_destination = shipment
|
||||||
equipment.sale_destination = shipment.outgoing_moves[count].origin
|
equipment.sale_destination = shipment.outgoing_moves[count].origin
|
||||||
equipment.propietarys += (shipment.customer,)
|
equipment.propietarys += (shipment.customer,)
|
||||||
equipment.maintenance_frequency = "6" if shipment.customer.customer_type == "ips" else "12"
|
equipment.maintenance_frequency = "6" if shipment.customer.customer_type == "ips" else "12"
|
||||||
count+=1
|
count += 1
|
||||||
equipment.save()
|
equipment.save()
|
||||||
else:
|
else:
|
||||||
count+=1
|
count += 1
|
||||||
|
|
||||||
Move.delete([
|
Move.delete([
|
||||||
m for s in shipments for m in s.outgoing_moves
|
m for s in shipments for m in s.outgoing_moves
|
||||||
if m.state == 'staging'])
|
if m.state == 'staging'])
|
||||||
|
|
||||||
Move.do([m for s in shipments for m in s.outgoing_moves])
|
Move.do([m for s in shipments for m in s.outgoing_moves])
|
||||||
for company, c_shipments in groupby(
|
for company, c_shipments in groupby(
|
||||||
@ -130,8 +152,8 @@ class ShipmentOut(metaclass=PoolMeta):
|
|||||||
with Transaction().set_context(company=company.id):
|
with Transaction().set_context(company=company.id):
|
||||||
today = Date.today()
|
today = Date.today()
|
||||||
cls.write([s for s in c_shipments if not s.effective_date], {
|
cls.write([s for s in c_shipments if not s.effective_date], {
|
||||||
'effective_date': today,
|
'effective_date': today,
|
||||||
})
|
})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
@ -150,20 +172,20 @@ class ShipmentOut(metaclass=PoolMeta):
|
|||||||
for move in shipment.inventory_moves:
|
for move in shipment.inventory_moves:
|
||||||
if move.product_equipment and move.equipment:
|
if move.product_equipment and move.equipment:
|
||||||
serial = True
|
serial = True
|
||||||
number_equipments +=1
|
number_equipments += 1
|
||||||
if move.equipment.product.maintenance_required:
|
if move.equipment.product.maintenance_required:
|
||||||
maintenance_required +=1
|
maintenance_required += 1
|
||||||
elif not move.product_equipment:
|
elif not move.product_equipment:
|
||||||
serial = True
|
serial = True
|
||||||
else:
|
else:
|
||||||
serial = False
|
serial = False
|
||||||
|
|
||||||
if number_equipments < 1 or maintenance_required < 1:
|
if number_equipments < 1 or maintenance_required < 1:
|
||||||
shipment.service_maintenance_initial = True
|
shipment.service_maintenance_initial = True
|
||||||
shipment.save()
|
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
|
break
|
||||||
|
|
||||||
sale_origin = shipment.outgoing_moves[0].origin.sale
|
sale_origin = shipment.outgoing_moves[0].origin.sale
|
||||||
maintenanceService = MaintenanceService.search(['sale_origin', '=', sale_origin])
|
maintenanceService = MaintenanceService.search(['sale_origin', '=', sale_origin])
|
||||||
if maintenanceService == []:
|
if maintenanceService == []:
|
||||||
@ -187,26 +209,27 @@ class ShipmentOut(metaclass=PoolMeta):
|
|||||||
service_maintenance=maintenanceService.id,
|
service_maintenance=maintenanceService.id,
|
||||||
maintenance_type='initial',
|
maintenance_type='initial',
|
||||||
propietary=shipment.customer.id,
|
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,
|
propietary_address=shipment.delivery_address.id,
|
||||||
equipment=move.equipment.id,
|
equipment=move.equipment.id,
|
||||||
initial_operation = move.equipment.product.initial_operation,
|
initial_operation=move.equipment.product.initial_operation,
|
||||||
check_equipment = move.equipment.product.template.check_equipment,
|
check_equipment=move.equipment.product.template.check_equipment,
|
||||||
check_electric_system = move.equipment.product.template.check_electric_system,
|
check_electric_system=move.equipment.product.template.check_electric_system,
|
||||||
clean_int_ext = move.equipment.product.template.clean_int_ext,
|
clean_int_ext=move.equipment.product.template.clean_int_ext,
|
||||||
clean_eyes = move.equipment.product.template.clean_eyes,
|
clean_eyes=move.equipment.product.template.clean_eyes,
|
||||||
check_calibration = move.equipment.product.template.check_calibration,
|
check_calibration=move.equipment.product.template.check_calibration,
|
||||||
temperature_min = maintenanceService.temperature_min,
|
temperature_min=maintenanceService.temperature_min,
|
||||||
temperature_max = maintenanceService.temperature_max,
|
temperature_max=maintenanceService.temperature_max,
|
||||||
temperature_uom = maintenanceService.temperature_uom.id,
|
temperature_uom=maintenanceService.temperature_uom.id,
|
||||||
moisture_min = maintenanceService.moisture_min,
|
moisture_min=maintenanceService.moisture_min,
|
||||||
moisture_max = maintenanceService.moisture_max,
|
moisture_max=maintenanceService.moisture_max,
|
||||||
moisture_uom = maintenanceService.moisture_uom.id)
|
moisture_uom=maintenanceService.moisture_uom.id)
|
||||||
maintenance.save()
|
maintenance.save()
|
||||||
shipment.service_maintenance_initial = True
|
shipment.service_maintenance_initial = True
|
||||||
shipment.save()
|
shipment.save()
|
||||||
else:
|
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):
|
class ShipmentInternal(metaclass=PoolMeta):
|
||||||
@ -227,10 +250,10 @@ class ShipmentInternal(metaclass=PoolMeta):
|
|||||||
if move.equipment:
|
if move.equipment:
|
||||||
move.equipment.location = shipment.to_location
|
move.equipment.location = shipment.to_location
|
||||||
move.equipment.save()
|
move.equipment.save()
|
||||||
|
|
||||||
Move.do([m for s in shipments for m in s.incoming_moves])
|
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], {
|
cls.write([s for s in shipments if not s.effective_date], {
|
||||||
'effective_date': Date.today(),})
|
'effective_date': Date.today(), })
|
||||||
|
|
||||||
|
|
||||||
class ShipmentOutReturn(metaclass=PoolMeta):
|
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])
|
Move.do([m for s in shipments for m in s.incoming_moves])
|
||||||
for s in shipments:
|
for s in shipments:
|
||||||
for m in s.incoming_moves:
|
for m in s.incoming_moves:
|
||||||
if m.equipment:
|
if m.equipment:
|
||||||
equipment = m.equipment
|
equipment = m.equipment
|
||||||
Id = equipment.id
|
Id = equipment.id
|
||||||
equipment = Equipments.search(['id', '=',Id])[0]
|
equipment = Equipments.search(['id', '=', Id])[0]
|
||||||
equipment.propietary = s.company.party.id
|
equipment.propietary = s.company.party.id
|
||||||
equipment.propietary_address= s.company.party.addresses[0].id
|
equipment.propietary_address = s.company.party.addresses[0].id
|
||||||
equipment.location = m.to_location.id
|
equipment.location = m.to_location.id
|
||||||
equipment.state="registred"
|
equipment.state = "registred"
|
||||||
equipment.save()
|
equipment.save()
|
||||||
|
|
||||||
cls.create_inventory_moves(shipments)
|
cls.create_inventory_moves(shipments)
|
||||||
# Set received state to allow done transition
|
# Set received state to allow done transition
|
||||||
cls.write(shipments, {'state': 'received'})
|
cls.write(shipments, {'state': 'received'})
|
||||||
to_do = [s for s in shipments
|
to_do = [s for s in shipments
|
||||||
if s.warehouse_storage == s.warehouse_input]
|
if s.warehouse_storage == s.warehouse_input]
|
||||||
|
|
||||||
|
|
||||||
if to_do:
|
if to_do:
|
||||||
cls.done(to_do)
|
cls.done(to_do)
|
||||||
|
|
||||||
|
|
||||||
class PickingListDeliveryReport(CompanyReport):
|
class PickingListDeliveryReport(CompanyReport):
|
||||||
__name__ = 'stock.shipment.out.picking_list1'
|
__name__ = 'stock.shipment.out.picking_list1'
|
||||||
|
|
||||||
@ -287,7 +311,7 @@ class PickingListDeliveryReport(CompanyReport):
|
|||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
class CapacitationReport(CompanyReport):
|
class CapacitationReport(CompanyReport):
|
||||||
__name__ = 'stock.shipment.out.capacitation_note'
|
__name__ = 'stock.shipment.out.capacitation_note'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user