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)
def test_sync_compas(self): self.assertEqual(ets.models.Compas.objects.count(), 1) self.assertEqual(compas_models.Place.objects.using(self.compas).count(), 3) self.assertEqual(ets.models.Location.objects.count(), 0) self.assertEqual(ets.models.Warehouse.objects.count(), 3) self.assertEqual(ets.models.Organization.objects.count(), 0) call_command('import_compas_full') call_command('sync_compas') """Test place's update method""" self.assertEqual(ets.models.Location.objects.count(), 2) self.assertEqual(ets.models.Warehouse.objects.count(), 3) self.assertEqual(ets.models.Organization.objects.count(), 2) self.assertEqual(ets.models.Compas.objects.count(), 1) wh = ets.models.Warehouse.objects.get(pk='ISBX002') self.assertTupleEqual((wh.organization, wh.location, wh.compas) , (ets.models.Organization.objects.get(pk='WFP'), ets.models.Location.objects.get(pk='ISBX'), ets.models.Compas.objects.get(pk=self.compas),)) #Persons person = ets.models.Person.objects.get(pk=2) self.assertTupleEqual((person.organization, person.location, person.compas, person.username), (ets.models.Organization.objects.get(pk='WFP'), ets.models.Location.objects.get(pk='ISBX'), ets.models.Compas.objects.get(pk=self.compas), 'ISBX0020000586')) #test loss and damage types. The same story. It's stupid :) self.assertEqual(ets.models.LossDamageType.objects.count(), 4) """test stock update""" self.assertEqual(ets.models.StockItem.objects.count(), 7) stock_item = ets.models.StockItem.objects.get(pk='KARX025KARX0010000944801MIXMIXHEBCG1558') #Commodity name and category self.assertTupleEqual((stock_item.commodity.name, stock_item.commodity.category.pk), (u'WHEET', u'SED')) #After import we've got net --> number_of_units and quantity_net == 1 self.assertTupleEqual((stock_item.number_of_units, stock_item.unit_weight_net), (1000, 1)) #Update changed stock compas_models.EpicStock.objects.using(self.compas).filter(origin_id='testme0124').update(quantity_net="0.7") import_stock(self.compas) self.assertEqual(ets.models.StockItem.objects.get(pk='KARX025KARX0010000944801MIXMIXHEBCG1558').number_of_units, 700) #Deleted stock compas_models.EpicStock.objects.using(self.compas).filter(origin_id='testme0124').delete() import_stock(self.compas) self.assertEqual(ets.models.StockItem.objects.get(pk='KARX025KARX0010000944801MIXMIXHEBCG1558').number_of_units, 0) """Update orders""" order = ets.models.Order.objects.all()[0] self.assertEqual(order.warehouse, wh) self.assertEqual(order.location, ets.models.Location.objects.get(pk='ISBX')) self.assertEqual(order.consignee, ets.models.Organization.objects.get(pk='DOEAF')) #Test updated consignee's name self.assertEqual(ets.models.Organization.objects.get(pk='DOEAF').name, 'First consignee in our system') #Test order items self.assertEqual(order.items.count(), 1)