Bug 12911: batch_id for new labels batches can be asssigned to several batches
Currently batch_id is assigned upon creation of a new batch object. This patch leaves batch_id as 0 at creation and adds a check when adding items. If batch is new then batch_id is created then Test plan: 1 -In one browser window, go to tools->label creator and click the new batch button 2 - Before adding items, open a new browser, and go tools->label creator and click the new batch button 3 - Note that both batches have the same number listed 4 - Add an item to the first batch - you should now see one item in the batch 5 - Add an item to the second batch, you should see two items in the batch 6 - Apply patch and repeat steps 1&2 7 - Note that neither batch lists a batch number 8 - Add an item to the first batch, you should see one item and a batch number 9 - Add an item to the second batch, you should see one item and a new batch number Patch behaves as expected. Signed-off-by: Marc Veron <veron@veron.ch> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
This commit is contained in:
parent
aa8bd7a098
commit
dedd059ac0
|
|
@ -51,10 +51,6 @@ sub new {
|
|||
batch_stat => 0, # False if any data has changed and the db has not been updated
|
||||
@_,
|
||||
};
|
||||
my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM creator_batches;");
|
||||
$sth->execute();
|
||||
my $batch_id = $sth->fetchrow_array;
|
||||
$self->{'batch_id'} = ++$batch_id unless $self->{'batch_id'} != 0; # this allows batch_id to be passed in for individual label printing
|
||||
bless ($self, $type);
|
||||
return $self;
|
||||
}
|
||||
|
|
@ -64,12 +60,18 @@ sub add_item {
|
|||
my $number = shift;
|
||||
ref($self) =~ m/C4::(.+)::.+$/;
|
||||
my $number_type = ($1 eq 'Patroncards' ? 'borrower_number' : 'item_number');
|
||||
if ($self->{'batch_id'} == 0){ #if this is a new batch batch_id must be created
|
||||
my $sth = C4::Context->dbh->prepare("SELECT MAX(batch_id) FROM creator_batches;");
|
||||
$sth->execute();
|
||||
my $batch_id = $sth->fetchrow_array;
|
||||
$self->{'batch_id'}= ++$batch_id;
|
||||
}
|
||||
my $query = "INSERT INTO creator_batches (batch_id, $number_type, branch_code, creator) VALUES (?,?,?,?);";
|
||||
my $sth = C4::Context->dbh->prepare($query);
|
||||
# $sth->{'TraceLevel'} = 3;
|
||||
$sth->execute($self->{'batch_id'}, $number, $self->{'branch_code'}, $1);
|
||||
if ($sth->err) {
|
||||
warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr);
|
||||
warn sprintf('Database returned the following error on attempted INSERT: %s', $sth->errstr);
|
||||
return -1;
|
||||
}
|
||||
$query = "SELECT max(label_id) FROM creator_batches WHERE batch_id=? AND $number_type=? AND branch_code=?;";
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@
|
|||
<fieldset class="rows" style="border-bottom: 0px; border: 0px;">
|
||||
<ol><li>
|
||||
<div class="dialog message">
|
||||
<h4>There are no items in Batch [% batch_id %] yet</h4>
|
||||
<h4>There are no items in this batch yet</h4>
|
||||
<p>Add items by barcode using the text area above or leave empty to add via item search.</p>
|
||||
</div>
|
||||
</li></ol>
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ elsif ($op eq 'add') {
|
|||
foreach my $item_number (@item_numbers) {
|
||||
$err = $batch->add_item($item_number);
|
||||
}
|
||||
$batch_id = $batch->get_attr('batch_id') if $batch_id == 0; #update batch_id if we added to a new batch
|
||||
$errstr = "item(s) not added to batch $batch_id." if $err;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
Loading…
Reference in New Issue