Merge pull request #378 from eReuse/feature/3854-new-button-transfer

Feature/3854 new button transfer
This commit is contained in:
cayop 2022-10-10 13:10:38 +02:00 committed by GitHub
commit 5d5a52376b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 12 deletions

View File

@ -1259,6 +1259,12 @@ class TradeDocumentForm(FlaskForm):
class TransferForm(FlaskForm): class TransferForm(FlaskForm):
lot_name = StringField(
'Lot Name',
[validators.DataRequired()],
render_kw={'class': "form-control"},
description="You need put a lot name",
)
code = StringField( code = StringField(
'Code', 'Code',
[validators.DataRequired()], [validators.DataRequired()],
@ -1303,9 +1309,7 @@ class TransferForm(FlaskForm):
return self._obj return self._obj
def set_obj(self): def set_obj(self):
name = self.code.data name = self.lot_name.data
if self._tmp_lot:
name = self._tmp_lot.name
self.newlot = Lot(name=name) self.newlot = Lot(name=name)
if self._tmp_lot: if self._tmp_lot:
self.newlot.devices = self._tmp_lot.devices self.newlot.devices = self._tmp_lot.devices
@ -1339,6 +1343,7 @@ class EditTransferForm(TransferForm):
self.code.data = self._obj.code self.code.data = self._obj.code
self.description.data = self._obj.description self.description.data = self._obj.description
self.date.data = self._obj.date self.date.data = self._obj.date
self.lot_name.data = self._obj.lot.name
def validate(self, extra_validators=None): def validate(self, extra_validators=None):
is_valid = super().validate(extra_validators) is_valid = super().validate(extra_validators)
@ -1350,6 +1355,7 @@ class EditTransferForm(TransferForm):
def set_obj(self, commit=True): def set_obj(self, commit=True):
self.populate_obj(self._obj) self.populate_obj(self._obj)
self._obj.lot.name = self.lot_name.data
class NotesForm(FlaskForm): class NotesForm(FlaskForm):

View File

@ -756,6 +756,8 @@ class NewTransferView(GenericMixin):
def dispatch_request(self, type_id, lot_id=None): def dispatch_request(self, type_id, lot_id=None):
self.form = self.form_class(lot_id=lot_id, type=type_id) self.form = self.form_class(lot_id=lot_id, type=type_id)
self.get_context() self.get_context()
referrer = request.referrer or url_for('inventory.devicelist')
self.context.update({'referrer': referrer})
if self.form.validate_on_submit(): if self.form.validate_on_submit():
self.form.save() self.form.save()
@ -767,7 +769,12 @@ class NewTransferView(GenericMixin):
next_url = url_for('inventory.lotdevicelist', lot_id=str(new_lot_id)) next_url = url_for('inventory.lotdevicelist', lot_id=str(new_lot_id))
return flask.redirect(next_url) return flask.redirect(next_url)
self.context.update({'form': self.form, 'title': self.title}) self.context.update(
{
'form': self.form,
'title': self.title,
}
)
return flask.render_template(self.template_name, **self.context) return flask.render_template(self.template_name, **self.context)

View File

@ -38,7 +38,7 @@
<div class="col-12"> <div class="col-12">
{% if field != form.type %} {% if field != form.type %}
{{ field.label(class_="form-label") }} {{ field.label(class_="form-label") }}
{% if field == form.code %} {% if field in [form.code, form.lot_name] %}
<span class="text-danger">*</span> <span class="text-danger">*</span>
{% endif %} {% endif %}
{{ field }} {{ field }}
@ -55,7 +55,7 @@
{% endfor %} {% endfor %}
<div> <div>
<a href="{{ url_for('inventory.lotdevicelist', lot_id=form._tmp_lot.id) }}" class="btn btn-danger">Cancel</a> <a href="{{ referrer }}" class="btn btn-danger">Cancel</a>
<button class="btn btn-primary" type="submit">Save</button> <button class="btn btn-primary" type="submit">Save</button>
</div> </div>
</form> </form>

View File

@ -1374,6 +1374,7 @@ def test_wb_settings_register(user3: UserClientFlask):
def test_create_transfer(user3: UserClientFlask): def test_create_transfer(user3: UserClientFlask):
user3.get('/inventory/lot/add/') user3.get('/inventory/lot/add/')
lot_name = 'lot1' lot_name = 'lot1'
lot_name2 = 'lot2'
data = { data = {
'name': lot_name, 'name': lot_name,
'csrf_token': generate_csrf(), 'csrf_token': generate_csrf(),
@ -1390,13 +1391,14 @@ def test_create_transfer(user3: UserClientFlask):
assert 'Description' in body assert 'Description' in body
assert 'Save' in body assert 'Save' in body
data = {'csrf_token': generate_csrf(), 'code': 'AAA'} data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name2}
body, status = user3.post(uri, data=data) body, status = user3.post(uri, data=data)
assert status == '200 OK' assert status == '200 OK'
assert 'Transfer created successfully!' in body assert 'Transfer created successfully!' in body
assert 'Delete Lot' in body assert 'Delete Lot' in body
assert 'Incoming Lot' in body assert 'Incoming Lot' in body
assert lot_name2 in body
@pytest.mark.mvp @pytest.mark.mvp
@ -1405,6 +1407,8 @@ def test_edit_transfer(user3: UserClientFlask):
# create lot # create lot
user3.get('/inventory/lot/add/') user3.get('/inventory/lot/add/')
lot_name = 'lot1' lot_name = 'lot1'
lot_name2 = 'lot2'
lot_name3 = 'lot3'
data = { data = {
'name': lot_name, 'name': lot_name,
'csrf_token': generate_csrf(), 'csrf_token': generate_csrf(),
@ -1422,12 +1426,13 @@ def test_edit_transfer(user3: UserClientFlask):
# create new incoming lot # create new incoming lot
uri = f'/inventory/lot/{lot_id}/transfer/incoming/' uri = f'/inventory/lot/{lot_id}/transfer/incoming/'
data = {'csrf_token': generate_csrf(), 'code': 'AAA'} data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name2}
body, status = user3.post(uri, data=data) body, status = user3.post(uri, data=data)
assert 'Transfer (<span class="text-success">Open</span>)' in body assert 'Transfer (<span class="text-success">Open</span>)' in body
assert '<i class="bi bi-trash"></i> Delete Lot' in body assert '<i class="bi bi-trash"></i> Delete Lot' in body
lot = Lot.query.filter()[1] lot = Lot.query.filter()[1]
assert lot.transfer is not None assert lot.transfer is not None
assert lot_name2 in body
# edit transfer with errors # edit transfer with errors
lot_id = lot.id lot_id = lot.id
@ -1436,6 +1441,7 @@ def test_edit_transfer(user3: UserClientFlask):
'csrf_token': generate_csrf(), 'csrf_token': generate_csrf(),
'code': 'AAA', 'code': 'AAA',
'description': 'one one one', 'description': 'one one one',
'lot_name': lot_name3,
'date': datetime.datetime.now().date() + datetime.timedelta(15), 'date': datetime.datetime.now().date() + datetime.timedelta(15),
} }
body, status = user3.post(uri, data=data) body, status = user3.post(uri, data=data)
@ -1450,6 +1456,7 @@ def test_edit_transfer(user3: UserClientFlask):
'csrf_token': generate_csrf(), 'csrf_token': generate_csrf(),
'code': 'AAA', 'code': 'AAA',
'description': 'one one one', 'description': 'one one one',
'lot_name': lot_name3,
'date': datetime.datetime.now().date() - datetime.timedelta(15), 'date': datetime.datetime.now().date() - datetime.timedelta(15),
} }
body, status = user3.post(uri, data=data) body, status = user3.post(uri, data=data)
@ -1458,6 +1465,7 @@ def test_edit_transfer(user3: UserClientFlask):
assert 'one one one' in body assert 'one one one' in body
assert '<i class="bi bi-trash"></i> Delete Lot' not in body assert '<i class="bi bi-trash"></i> Delete Lot' not in body
assert 'Transfer (<span class="text-danger">Closed</span>)' in body assert 'Transfer (<span class="text-danger">Closed</span>)' in body
assert lot_name3 in body
@pytest.mark.mvp @pytest.mark.mvp
@ -1476,7 +1484,7 @@ def test_edit_deliverynote(user3: UserClientFlask):
# create new incoming lot # create new incoming lot
uri = f'/inventory/lot/{lot_id}/transfer/incoming/' uri = f'/inventory/lot/{lot_id}/transfer/incoming/'
data = {'csrf_token': generate_csrf(), 'code': 'AAA'} data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name}
user3.post(uri, data=data) user3.post(uri, data=data)
lot = Lot.query.filter()[1] lot = Lot.query.filter()[1]
lot_id = lot.id lot_id = lot.id
@ -1517,7 +1525,7 @@ def test_edit_receivernote(user3: UserClientFlask):
# create new incoming lot # create new incoming lot
uri = f'/inventory/lot/{lot_id}/transfer/incoming/' uri = f'/inventory/lot/{lot_id}/transfer/incoming/'
data = {'csrf_token': generate_csrf(), 'code': 'AAA'} data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name}
user3.post(uri, data=data) user3.post(uri, data=data)
lot = Lot.query.filter()[1] lot = Lot.query.filter()[1]
lot_id = lot.id lot_id = lot.id
@ -1558,7 +1566,7 @@ def test_edit_notes_with_closed_transfer(user3: UserClientFlask):
# create new incoming lot # create new incoming lot
uri = f'/inventory/lot/{lot_id}/transfer/incoming/' uri = f'/inventory/lot/{lot_id}/transfer/incoming/'
data = {'csrf_token': generate_csrf(), 'code': 'AAA'} data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name}
user3.post(uri, data=data) user3.post(uri, data=data)
lot = Lot.query.filter()[1] lot = Lot.query.filter()[1]
lot_id = lot.id lot_id = lot.id
@ -2403,7 +2411,7 @@ def test_bug_3831_documents(user3: UserClientFlask):
uri = f'/inventory/lot/{lot_id}/transfer/incoming/' uri = f'/inventory/lot/{lot_id}/transfer/incoming/'
user3.get(uri) user3.get(uri)
data = {'csrf_token': generate_csrf(), 'code': 'AAA'} data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name}
body, status = user3.post(uri, data=data) body, status = user3.post(uri, data=data)
assert status == '200 OK' assert status == '200 OK'