Пример #1
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])
Пример #2
0
    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])
Пример #3
0
def test_next_value_for():
    assert next_value_for(u"") == u"1"
    assert next_value_for(u"1") == u"2"
    assert next_value_for(u"999") == u"1000"
    assert next_value_for(u"A999") == u"A1000"
    assert next_value_for(u"A8") == u"A9"
    assert next_value_for(u"A9") == u"A10"
    assert next_value_for(u"A99") == u"A100"
    assert next_value_for(u"A999") == u"A1000"
    assert next_value_for(u"999A") == u"999A1"
    assert next_value_for(u"999A1") == u"999A2"
Пример #4
0
 def _update_default_sellable_code(self, category=None):
     if category:
         query = (Sellable.category_id == category.id)
         code = Sellable.get_max_value(self.store, Sellable.code, query=query)
     else:
         code = Sellable.get_max_value(self.store, Sellable.code)
     self.code.update(next_value_for(code))
Пример #5
0
 def _update_default_sellable_code(self, category=None):
     if category:
         query = (Sellable.category_id == category.id)
         code = Sellable.get_max_value(self.store, Sellable.code, query=query)
     else:
         code = Sellable.get_max_value(self.store, Sellable.code)
     self.code.update(next_value_for(code))
Пример #6
0
 def _update_default_sellable_code(self):
     code = Sellable.get_max_value(self.store, Sellable.code)
     self.code.update(next_value_for(code))
Пример #7
0
 def _update_default_sellable_code(self):
     code = Sellable.get_max_value(self.store, Sellable.code)
     self.code.update(next_value_for(code))
Пример #8
0
 def _update_default_sellable_code(self):
     code = self.store.find(Sellable).max(Sellable.code)
     self.code.update(next_value_for(code))
Пример #9
0
 def _update_default_sellable_code(self):
     code = self.store.find(Sellable).max(Sellable.code)
     self.code.update(next_value_for(code))
Пример #10
0
    def test_next_value_for(self):
        # Trivial cases
        self.assertEqual(next_value_for(u''), u'1')
        self.assertEqual(next_value_for(u'1'), u'2')
        self.assertEqual(next_value_for(u'999'), u'1000')

        # Ending with digit cases
        self.assertEqual(next_value_for(u'A999'), u'A1000')
        self.assertEqual(next_value_for(u'A8'), u'A9')
        self.assertEqual(next_value_for(u'A9'), u'A10')
        self.assertEqual(next_value_for(u'A99'), u'A100')
        self.assertEqual(next_value_for(u'A199'), u'A200')
        self.assertEqual(next_value_for(u'999A1'), u'999A2')
        self.assertEqual(next_value_for(u'A009'), u'A010')
        self.assertEqual(next_value_for(u'AB0099'), u'AB0100')

        # Ending with alphanumeric cases
        self.assertEqual(next_value_for(u'999A'), u'999B')
        self.assertEqual(next_value_for(u'A999A'), u'A999B')
        self.assertEqual(next_value_for(u'A99AZ'), u'A99B0')
        self.assertEqual(next_value_for(u'A999Z'), u'A10000')
        self.assertEqual(next_value_for(u'A999-A'), u'A999-B')
        self.assertEqual(next_value_for(u'A999-Z'), u'A999-00')

        # Not handled cases
        self.assertEqual(next_value_for(u'A999-'), u'A999-0')