def get_equipment_detail(request): eq = get_equipment_ext(request.GET.get('pk')) if not eq: return send_error(request, _('invalid item')) can_return = request.user.has_perm('CRM.add_equipmentreturn') and eq.is_involved can_mark_used = request.user.has_perm('CRM.change_equipment') and not eq.is_involved is_used = eq.is_used x = {'can_return': can_return, 'is_used': is_used, 'can_mark_used': can_mark_used} return HttpResponse(json.dumps(x))
def equipment_operation(request): equipment = get_equipment_ext(request.GET.get('pk')) if not equipment: return send_error(request, _('invalid item')) data = equipment.fk_involved_equipment_equipment.all().values('pk', 'ext', 'item_text', 'order__personnel__first_name', 'order__request_date') res = get_paginate(data, request.GET.get('current'), request.GET.get('rowCount')) return HttpResponse(res)
def view_equipment_change_history(request): equipment = get_equipment_ext(request.GET.get('pk')) if not equipment: return send_error(request, _('invalid item')) data = EquipmentItemCountHistory.objects.filter(equipment= equipment.pk).values('pk', 'change', 'update_date').order_by('-update_date') x = {'data': list(data)} return HttpResponse(json.dumps(x, default=date_handler))
def mark_equipment_as_used(request): eq = get_equipment_ext(request.GET.get('pk')) if not eq: return send_error(request, _('invalid item')) eq.is_used = not eq.is_used eq.save() if eq.is_used: eq.group.change_remain(1, -1) else: eq.group.change_remain(-1, 1) return HttpResponse(eq.ext)
def equipment_return_to_inventory(request): equipment = get_equipment_ext(request.POST.get('pk')) state = get_equipment_state_list_ext(request.POST.get('st')) return_amount = get_integer(request.POST.get('ram')) if not equipment: return send_error(request, _('invalid item')) if not state: return send_error(request, _('invalid state')) if EquipmentState.objects.filter(equipment=equipment.pk).exists(): st = EquipmentState.objects.get(equipment=equipment.pk) else: st = EquipmentState() st.equipment = equipment st.state = state st.save() if InvolvedEquipment.objects.filter(equipment=equipment.pk, is_deleted=False).exists() and 'rls' in request.POST: ie = InvolvedEquipment.objects.get(equipment=equipment.pk, is_deleted=False) ie.remove() if 'srt' in request.POST: if equipment.is_used: equipment.group.change_remain(1, 0) else: equipment.group.change_remain(0, 1) if 'rls' in request.POST: equipment.is_involved = False if equipment.fk_equipment_order_detail_equipment.exists(): res_x = equipment.fk_equipment_order_detail_equipment.all() for r in res_x: r.order_item.delete() r.delete() equipment.save() if equipment.fk_equipment_order_detail_equipment.exists(): rt = EquipmentReturn() rt.order_id = equipment.fk_equipment_order_detail_equipment.last().pk rt.save() ec = EquipmentItemCountHistory() ec.equipment = equipment if not return_amount: return_amount = 1 ec.change = return_amount ec.save() return HttpResponse('200')
def select_equipment_for_order(request): order = get_equipment_order_item_ext(request.POST.get('pk')) equipment = get_equipment_ext(request.POST.get('eq')) owner_tag = get_string(request.POST.get('bc')) address = get_string(request.POST.get('adr')) if not order: return send_error(request, _('invalid order')) if not equipment: return send_error(request, _('invalid item')) if InvolvedEquipment.objects.filter(equipment=equipment.pk, is_deleted=False).exists(): return send_error(request, _('this item selected for order')) ib = order.order.is_borrow if ib: if not owner_tag: return send_error(request, _('please enter property number')) if not address: return send_error(request, _('please enter address')) ed = EquipmentOrderDetail() ed.equipment = equipment ed.order_item = order ed.save() order.accept() equipment.is_involved = True equipment.save() ie = InvolvedEquipment() ie.equipment = equipment main_order = EquipmentOrder.objects.get(pk=order.order_id) ie.item_text = main_order.item_text ie.order_id = main_order.pk ie.save() if ib: eb = EquipmentBorrow() eb.address = address eb.order = ed eb.property_number = owner_tag eb.save() return HttpResponse(ed.ext)
def add_new_equipment(request): serial = get_string(request.POST.get('s')) des = get_string(request.POST.get('d')) group = get_equipment_group(request.POST.get('g')) equipment = get_equipment_ext(request.POST.get('pk')) if not serial: return send_error(request, _('invalid serial')) if not des: return send_error(request, _('please enter description')) if not group: return send_error(request, _('please select group')) if not equipment: equipment = Equipment() equipment.description = des equipment.group = group equipment.serial = serial if equipment.pk is None: if equipment.is_used: equipment.group.change_remain(1, 0) else: equipment.group.change_remain(0, 1) EquipmentNewItemAddedEventHandler().fire(equipment, None, request.user.pk) equipment.save() return HttpResponse(equipment.ext)
def delete_equipment(request): eq = get_equipment_ext(request.GET.get('pk')) if not eq: return send_error(request, _('invalid item')) eq.remove() return HttpResponse(eq.ext)
def view_equipment_detail(request): eq = get_equipment_ext(request.GET.get('pk')) if not eq: return send_error(request, _('invalid item')) res = {'serial': eq.serial, 'group': eq.group.ext, 'description': eq.description} return HttpResponse(json.dumps(res))