示例#1
0
    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))
示例#3
0
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))
示例#4
0
    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)
示例#5
0
    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))
示例#6
0
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))
示例#7
0
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)])
示例#8
0
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
示例#9
0
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
示例#10
0
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)
        ])
示例#11
0
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)])
示例#12
0
    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))
示例#13
0
    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))
示例#14
0
    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))
示例#15
0
    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)
示例#16
0
    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))
示例#17
0
    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))
示例#18
0
    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))
示例#19
0
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))
示例#20
0
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()
示例#21
0
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()
示例#22
0
 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))
示例#23
0
 def test_should_get_daily_sync_end_date(self):
     self.assertEqual(VisionSyncInfo.get_daily_sync_end_date(),
                      datetime.date(2014, 9, 25))
示例#24
0
 def test_should_get_daily_sync_end_date(self):
     self.assertEqual(VisionSyncInfo.get_daily_sync_end_date(), datetime.date(2014, 9, 25))
示例#25
0
 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))