def test_should_get_last_manual_sync_status(self): VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 13), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 12), end_date=datetime.date(2016, 3, 13), is_daily_sync=False) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_last_manual_sync_status(), VisionSyncInfo.STATUS.SUCCESS) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 15), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 15), is_daily_sync=False) self.assertEqual(VisionSyncInfo.get_last_manual_sync_status(), VisionSyncInfo.STATUS.FAILURE)
def test_should_get_manual_sync_start_date(self): system_settings = SystemSettings.objects.create() self.assertEqual(VisionSyncInfo.get_manual_sync_start_date(), None) system_settings.sync_start_date = datetime.date(2016, 3, 12) system_settings.save() self.assertEqual(VisionSyncInfo.get_manual_sync_start_date(), datetime.date(2016, 3, 12))
def daily_sync(): start_date = VisionSyncInfo.get_daily_sync_start_date() end_date = VisionSyncInfo.get_daily_sync_end_date() if start_date: logger.info('daily sync. start_date=%s, end_date=%s' % (start_date, end_date)) sync_record = VisionSyncInfo.new_instance(True, start_date, end_date) sync(sync_record, format_date(start_date), format_date(end_date))
def test_should_get_ro_sync_start_date(self): self.successful_so.sync_date = self.date_2015_12_03 self.successful_so.save() self.successful_po.sync_date = self.date_2015_12_15 self.successful_po.save() self.successful_ro.sync_date = self.date_2015_12_31 self.successful_ro.save() self.assertEqual(VisionSyncInfo.get_sync_start_date('RO'), self.date_2015_12_03_str) self.successful_so.sync_date = self.date_2015_12_15 self.successful_so.save() self.successful_po.sync_date = self.date_2015_12_03 self.successful_po.save() self.successful_ro.sync_date = self.date_2015_12_31 self.successful_ro.save() self.assertEqual(VisionSyncInfo.get_sync_start_date('RO'), self.date_2015_12_03_str) self.successful_so.sync_date = self.date_2015_12_15 self.successful_so.save() self.successful_po.sync_date = self.date_2015_12_03 self.successful_po.save() self.successful_ro.delete() self.assertEqual(VisionSyncInfo.get_sync_start_date('RO'), self.date_2015_12_03_str)
def on_pre_save_system_settings(sender, **kwargs): start_date = VisionSyncInfo.get_manual_sync_start_date() end_date = VisionSyncInfo.get_manual_sync_end_date() new_sync_date = kwargs["instance"].sync_start_date if new_sync_date and new_sync_date < datetime.date.today() and (not start_date or new_sync_date < start_date): logger.info("manual sync. start_date=%s, end_date=%s" % (new_sync_date, end_date)) sync_record = VisionSyncInfo.new_instance(False, new_sync_date, end_date) run.apply_async(args=[sync_record, format_date(new_sync_date), format_date(end_date)])
def resync_if_manual_sync_fail(): start_date = VisionSyncInfo.get_manual_sync_start_date() end_date = VisionSyncInfo.get_manual_sync_end_date() if start_date and VisionSyncInfo.get_last_manual_sync_status() == VisionSyncInfo.STATUS.FAILURE: logger.info('resync as manual sync failed. start_date=%s, end_date=%s' % (start_date, end_date)) sync_record = VisionSyncInfo.new_instance(False, start_date, end_date) sync(sync_record, format_date(start_date), format_date(end_date)) return True return False
def resync_if_manual_sync_fail(): start_date = VisionSyncInfo.get_manual_sync_start_date() end_date = VisionSyncInfo.get_manual_sync_end_date() if start_date and VisionSyncInfo.get_last_manual_sync_status( ) == VisionSyncInfo.STATUS.FAILURE: logger.info( 'resync as manual sync failed. start_date=%s, end_date=%s' % (start_date, end_date)) sync_record = VisionSyncInfo.new_instance(False, start_date, end_date) sync(sync_record, format_date(start_date), format_date(end_date)) return True return False
def on_pre_save_system_settings(sender, **kwargs): start_date = VisionSyncInfo.get_manual_sync_start_date() end_date = VisionSyncInfo.get_manual_sync_end_date() new_sync_date = kwargs['instance'].sync_start_date if new_sync_date and new_sync_date < datetime.date.today() and ( not start_date or new_sync_date < start_date): logger.info('manual sync. start_date=%s, end_date=%s' % (new_sync_date, end_date)) sync_record = VisionSyncInfo.new_instance(False, new_sync_date, end_date) run.apply_async(args=[ sync_record, format_date(new_sync_date), format_date(end_date) ])
def on_pre_save_system_settings(sender, **kwargs): new_sync_start_date = kwargs['instance'].sync_start_date new_sync_end_date = kwargs['instance'].sync_end_date if new_sync_start_date and new_sync_end_date and new_sync_start_date < new_sync_end_date: logger.info('manual sync. start_date=%s, end_date=%s' % (new_sync_start_date, new_sync_end_date)) sync_record = VisionSyncInfo.new_instance(False, new_sync_start_date, new_sync_end_date) run.apply_async(args=[sync_record, format_date(new_sync_start_date), format_date(new_sync_end_date)])
def test_should_get_daily_sync_start_date(self): system_settings = SystemSettings.objects.create() self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), None) system_settings.sync_start_date = datetime.date(2016, 3, 13) system_settings.save() self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 13)) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=False) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14))
def test_should_get_daily_sync_start_date_when_last_sync_fail(self): VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=True) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 15), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 14), end_date=datetime.date(2016, 3, 15), is_daily_sync=True) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 16), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 1, 1), end_date=datetime.date(2016, 3, 16), is_daily_sync=False) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14)) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 16), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 14), end_date=datetime.date(2016, 3, 16), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14)) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 17), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 14), end_date=datetime.date(2016, 3, 17), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 17))
def test_should_get_daily_sync_start_date(self): system_settings = SystemSettings.objects.create() self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), None) system_settings.sync_start_date = datetime.date(2016, 3, 13) system_settings.save() self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 13)) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=False) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14))
def test_should_get_last_manual_sync_status(self): VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 13), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 12), end_date=datetime.date(2016, 3, 13), is_daily_sync=False) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_last_manual_sync_status(), VisionSyncInfo.STATUS.SUCCESS) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 15), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 15), is_daily_sync=False) self.assertEqual(VisionSyncInfo.get_last_manual_sync_status(), VisionSyncInfo.STATUS.FAILURE)
def test_should_get_daily_sync_start_date_when_all_sync_successfully(self): VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 13), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 12), end_date=datetime.date(2016, 3, 13), is_daily_sync=True) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14))
def test_should_get_daily_sync_start_date_when_last_sync_fail(self): VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=True) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 15), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 14), end_date=datetime.date(2016, 3, 15), is_daily_sync=True) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 16), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 1, 1), end_date=datetime.date(2016, 3, 16), is_daily_sync=False) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14)) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 16), sync_status=VisionSyncInfo.STATUS.FAILURE, start_date=datetime.date(2016, 3, 14), end_date=datetime.date(2016, 3, 16), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14)) VisionSyncInfo.objects.create(sync_date=datetime.date(2016, 3, 17), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 14), end_date=datetime.date(2016, 3, 17), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 17))
def test_should_get_daily_sync_start_date_when_all_sync_successfully(self): VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 13), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 12), end_date=datetime.date(2016, 3, 13), is_daily_sync=True) VisionSyncInfo.objects.create( sync_date=datetime.date(2016, 3, 14), sync_status=VisionSyncInfo.STATUS.SUCCESS, start_date=datetime.date(2016, 3, 13), end_date=datetime.date(2016, 3, 14), is_daily_sync=True) self.assertEqual(VisionSyncInfo.get_daily_sync_start_date(), datetime.date(2016, 3, 14))
def _sync_orders(sync_record, start_date='', end_date=''): order_synchronizers = ({'SO': SalesOrderSynchronizer}, {'PO': PurchaseOrderSynchronizer}, {'RO': ReleaseOrderSynchronizer}) for synchronizer_dict in order_synchronizers: key = synchronizer_dict.keys()[0] synchronizer = synchronizer_dict.values()[0] try: if not start_date: start_date = VisionSyncInfo.get_sync_start_date(key) synchronizer(start_date, end_date).sync() sync_record.set_sync_status_success(key) logger.info("%s sync successfully" % key) except VisionException, e: sync_record.set_sync_status_failure(key) logger.error("%s sync failed, Reason:%s" % (key, e.message))
def sync(start_date='', end_date=''): sync_record = VisionSyncInfo.new_instance() _sync_consignee(sync_record) _sync_programme(sync_record) _sync_orders(sync_record, start_date, end_date) _auto_track_release_orders.apply_async()
def sync(start_date="", end_date=""): sync_record = VisionSyncInfo.new_instance() _sync_consignee(sync_record) _sync_programme(sync_record) _sync_orders(sync_record, start_date, end_date) _auto_track_release_orders.apply_async()
def test_should_get_manual_sync_end_date_at_first_time(self): self.assertEqual(VisionSyncInfo.get_manual_sync_end_date(), datetime.date(2014, 9, 25))
def test_should_get_daily_sync_end_date(self): self.assertEqual(VisionSyncInfo.get_daily_sync_end_date(), datetime.date(2014, 9, 25))