def test_batch_number_suggestion_synchronized_mode(self):
        branch = api.get_current_branch(self.store)
        branch.acronym = u'AB'

        storable = self.create_storable(is_batch=True)
        storable2 = self.create_storable(is_batch=True)

        dialog = BatchIncreaseSelectionDialog(self.store, storable, 10)
        self.assertEqual(dialog._last_entry.get_text(), '')

        with self.sysparam(SUGGEST_BATCH_NUMBER=True, SYNCHRONIZED_MODE=True):
            storable.register_initial_stock(1, self.create_branch(), 0,
                                            batch_number=u'130')
            dialog = BatchIncreaseSelectionDialog(self.store, storable, 10)
            # Make sure it suggested right
            self.assertEqual(dialog._last_entry.get_text(), '131-AB')

            spinbutton = dialog.get_spin_by_entry(dialog._last_entry)
            spinbutton.update(5)
            # Updating the spinbutton should append a new entry with the suggestion
            self.assertEqual(dialog._last_entry.get_text(), '132-AB')
            self.click(dialog.main_dialog.ok_button)

            dialog = BatchIncreaseSelectionDialog(self.store, storable2, 10)
            # Since the dialog above was confirmed on the same store this one is,
            # it should consider it's batch numbers for the next suggestion
            self.assertEqual(dialog._last_entry.get_text(), '133-AB')

            branch.acronym = None
            spinbutton = dialog.get_spin_by_entry(dialog._last_entry)
    def test_get_batch_item(self):
        storable = self.create_storable()
        batch = self.create_storable_batch(storable, batch_number=u'123456')
        dialog = BatchIncreaseSelectionDialog(self.store, storable, 10)

        self.assertEqual(dialog.get_batch_item(batch), u'123456')
        self.assertEqual(dialog.get_batch_item(batch.batch_number), u'123456')
        self.assertEqual(dialog.get_batch_item(None), None)
    def test_batch_number_validation(self):
        storable = self.create_storable(is_batch=True)
        storable2 = self.create_storable(is_batch=True)
        self.create_storable_batch(storable=storable, batch_number=u'123')
        self.create_storable_batch(storable=storable, batch_number=u'124')

        dialog = BatchIncreaseSelectionDialog(self.store, storable2, 10)
        dialog._last_entry.update(u'123')
        self.assertInvalid(dialog, ['_last_entry'])
        dialog._last_entry.update(u'126')
        self.assertValid(dialog, ['_last_entry'])