def test_send_dispatched(self): def call_db_procedure(name, parameters, using): assert name == 'write_waybill.dispatch', "Wrong procedure's name" assert isinstance(parameters, tuple), "Parameters must be a tuple" assert using == self.compas, "Wrong compas" ets.utils.call_db_procedure = call_db_procedure waybill = ets.models.Waybill.objects.get(pk="ISBX00211A") #Validate first waybill waybill.validated = True waybill.transport_dispach_signed_date = datetime.now() waybill.save() #Send all validated waybills to compas send_dispatched(waybill, self.compas) self.assertTrue(ets.models.Waybill.objects.get(pk="ISBX00211A").sent_compas) #Check compass logger logger = ets.models.CompasLogger.objects.get(waybill__pk='ISBX00211A') self.assertEqual(logger.status, ets.models.CompasLogger.SUCCESS)
def test_dispatch_failure(self): def call_db_procedure(name, parameters, using): raise ValidationError("Test wrong message", code="E") ets.utils.call_db_procedure = call_db_procedure ets.models.Waybill.objects.filter(pk="ISBX00211A").update(validated=True, transport_dispach_signed_date=datetime.now()) waybill = ets.models.Waybill.objects.get(pk="ISBX00211A") #Send all validated waybills to compas send_dispatched(waybill, self.compas) self.assertFalse(waybill.sent_compas) self.assertFalse(waybill.validated) #Check compass logger logger = ets.models.CompasLogger.objects.get(waybill__pk='ISBX00211A') self.assertTupleEqual((logger.status, logger.message), (ets.models.CompasLogger.FAILURE, "Test wrong message"))
def send_dispatched_view(request, queryset): """Submits dispatch waybills to COMPAS""" total = 0 for waybill in queryset: if send_dispatched(waybill): total += 1 messages.add_message(request, messages.INFO, _('Number of submitted waybills: %(total)s') % { 'total': total, }) if len(queryset) - total: messages.add_message(request, messages.ERROR, _('Number of wrong waybills: %(count)s') % { 'count': len(queryset) - total, }) return redirect('dispatch_validates')
def synchronize(self, compas): total = 0 for waybill in Waybill.objects.filter(transport_dispach_signed_date__lte=datetime.now(), validated=True, sent_compas__isnull=True, order__warehouse__compas__pk=compas.pk, order__warehouse__compas__read_only=False): if send_dispatched(waybill, compas.pk): total += 1 for waybill in Waybill.objects.filter(receipt_signed_date__lte=datetime.now(), receipt_validated=True, receipt_sent_compas__isnull=True, destination__compas__pk=compas.pk, destination__compas__read_only=False): if send_received(waybill, compas.pk): total += 1 if total: import_stock(compas.pk)