Skip to content

Commit

Permalink
work in progress. still need store these strings in the database.
Browse files Browse the repository at this point in the history
just to hear from users how they feel about the functionality.
  • Loading branch information
mfrasca committed Jan 27, 2016
1 parent 03feea3 commit 1473f22
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
8 changes: 7 additions & 1 deletion bauble/plugins/garden/acc_editor.glade
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,20 @@
<col id="0">%Y.####</col>
</row>
<row>
<col id="0">######</col>
<col id="0">%{Y-1}.####</col>
</row>
<row>
<col id="0">XXXX.####</col>
</row>
<row>
<col id="0">SD.#####</col>
</row>
<row>
<col id="0">H.#####</col>
</row>
<row>
<col id="0">######</col>
</row>
</data>
</object>
<object class="GtkDialog" id="accession_dialog">
Expand Down
5 changes: 4 additions & 1 deletion bauble/plugins/garden/accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,10 @@ def get_next_code(cls, code_format=None):
if code_format is None:
code_format = cls.code_format
format = code_format.replace('%PD', Plant.get_delimiter())
format = datetime.date.today().strftime(format)
today = datetime.date.today()
format = today.strftime(format)
if format.find('%{Y-1}') >= 0:
format = format.replace('%{Y-1}', str(today.year - 1))
start = unicode(format.rstrip('#'))
if start == format:
# fixed value
Expand Down
10 changes: 10 additions & 0 deletions bauble/plugins/garden/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,16 @@ def test_get_next_code_fixed(self):
self.assertEquals(Accession.get_next_code(u'00003'), '00003')
self.assertEquals(Accession.get_next_code(u'H.0003'), 'H.0003')

def test_get_next_code_previous_year_subst(self):
this_year = datetime.date.today().year
last_year = this_year - 1
acc = Accession(species=self.species, code=u'%s.0012' % last_year)
ac2 = Accession(species=self.species, code=u'%s.0987' % this_year)
self.session.add_all([acc, ac2])
self.session.flush()
self.assertEquals(Accession.get_next_code(u'%{Y-1}.####')[5:], '0013')
self.assertEquals(Accession.get_next_code(u'%Y.####')[5:], '0988')


class GlobalFunctionsTests(GardenTestCase):

Expand Down

1 comment on commit 1473f22

@mfrasca
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to connect the commit to the issue - Bauble/bauble.classic#59

Please sign in to comment.