def _get_next_batch_number(self):
        max_db = StorableBatch.get_max_value(self.store,
                                             StorableBatch.batch_number)
        max_used = max_value_for(self._get_used_batches() | set([max_db]))
        if not api.sysparam.get_bool('SYNCHRONIZED_MODE'):
            return next_value_for(max_used)

        # On synchronized mode we need to append the branch acronym
        # to avoid conflicts
        max_used_list = max_used.split('-')
        if len(max_used_list) == 1:
            # '123'
            max_used = max_used_list[0]
        elif len(max_used_list) == 2:
            # '123-AB'
            max_used = max_used_list[0]
        else:
            # '123-456-AB'
            max_used = ''.join(max_used_list[:-1])

        branch = api.get_current_branch(self.store)
        if not branch.acronym:
            raise ValueError("branch '%s' needs an acronym since we are on "
                             "synchronized mode" % (branch.get_description(),))
        return '-'.join([next_value_for(max_used), branch.acronym])
Example #2
0
    def _get_next_batch_number(self):
        max_db = StorableBatch.get_max_batch_number(self.store)
        max_used = max_value_for(self._get_used_batches() | set([max_db]))
        if not api.sysparam.get_bool('SYNCHRONIZED_MODE'):
            return next_value_for(max_used)

        # On synchronized mode we need to append the branch acronym
        # to avoid conflicts
        max_used_list = max_used.split('-')
        if len(max_used_list) == 1:
            # '123'
            max_used = max_used_list[0]
        elif len(max_used_list) == 2:
            # '123-AB'
            max_used = max_used_list[0]
        else:
            # TODO: Maybe we should allow only one dash in the batch number
            # '123-456-AB'
            max_used = ''.join(max_used_list[:-1])

        branch = api.get_current_branch(self.store)
        if not branch.acronym:
            raise ValueError("branch '%s' needs an acronym since we are on "
                             "synchronized mode" % (branch.get_description(),))
        return '-'.join([next_value_for(max_used), branch.acronym])
Example #3
0
 def test_max_value_for(self):
     self.assertEqual(max_value_for([u'']), u'')
     self.assertEqual(max_value_for([u'1']), u'1')
     self.assertEqual(max_value_for([u'1', u'2']), u'2')
     self.assertEqual(max_value_for([u'9', u'10']), u'10')
     self.assertEqual(max_value_for([u'009', u'10']), u'010')
     self.assertEqual(max_value_for([u'a09', u'999']), u'a09')