Merge pull request #378 from eReuse/feature/3854-new-button-transfer
Feature/3854 new button transfer
This commit is contained in:
commit
5d5a52376b
|
@ -1259,6 +1259,12 @@ class TradeDocumentForm(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',
|
||||
[validators.DataRequired()],
|
||||
|
@ -1303,9 +1309,7 @@ class TransferForm(FlaskForm):
|
|||
return self._obj
|
||||
|
||||
def set_obj(self):
|
||||
name = self.code.data
|
||||
if self._tmp_lot:
|
||||
name = self._tmp_lot.name
|
||||
name = self.lot_name.data
|
||||
self.newlot = Lot(name=name)
|
||||
if self._tmp_lot:
|
||||
self.newlot.devices = self._tmp_lot.devices
|
||||
|
@ -1339,6 +1343,7 @@ class EditTransferForm(TransferForm):
|
|||
self.code.data = self._obj.code
|
||||
self.description.data = self._obj.description
|
||||
self.date.data = self._obj.date
|
||||
self.lot_name.data = self._obj.lot.name
|
||||
|
||||
def validate(self, extra_validators=None):
|
||||
is_valid = super().validate(extra_validators)
|
||||
|
@ -1350,6 +1355,7 @@ class EditTransferForm(TransferForm):
|
|||
|
||||
def set_obj(self, commit=True):
|
||||
self.populate_obj(self._obj)
|
||||
self._obj.lot.name = self.lot_name.data
|
||||
|
||||
|
||||
class NotesForm(FlaskForm):
|
||||
|
|
|
@ -756,6 +756,8 @@ class NewTransferView(GenericMixin):
|
|||
def dispatch_request(self, type_id, lot_id=None):
|
||||
self.form = self.form_class(lot_id=lot_id, type=type_id)
|
||||
self.get_context()
|
||||
referrer = request.referrer or url_for('inventory.devicelist')
|
||||
self.context.update({'referrer': referrer})
|
||||
|
||||
if self.form.validate_on_submit():
|
||||
self.form.save()
|
||||
|
@ -767,7 +769,12 @@ class NewTransferView(GenericMixin):
|
|||
next_url = url_for('inventory.lotdevicelist', lot_id=str(new_lot_id))
|
||||
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)
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<div class="col-12">
|
||||
{% if field != form.type %}
|
||||
{{ field.label(class_="form-label") }}
|
||||
{% if field == form.code %}
|
||||
{% if field in [form.code, form.lot_name] %}
|
||||
<span class="text-danger">*</span>
|
||||
{% endif %}
|
||||
{{ field }}
|
||||
|
@ -55,7 +55,7 @@
|
|||
{% endfor %}
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</form>
|
||||
|
|
|
@ -1374,6 +1374,7 @@ def test_wb_settings_register(user3: UserClientFlask):
|
|||
def test_create_transfer(user3: UserClientFlask):
|
||||
user3.get('/inventory/lot/add/')
|
||||
lot_name = 'lot1'
|
||||
lot_name2 = 'lot2'
|
||||
data = {
|
||||
'name': lot_name,
|
||||
'csrf_token': generate_csrf(),
|
||||
|
@ -1390,13 +1391,14 @@ def test_create_transfer(user3: UserClientFlask):
|
|||
assert 'Description' 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)
|
||||
assert status == '200 OK'
|
||||
assert 'Transfer created successfully!' in body
|
||||
assert 'Delete Lot' in body
|
||||
assert 'Incoming Lot' in body
|
||||
assert lot_name2 in body
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
@ -1405,6 +1407,8 @@ def test_edit_transfer(user3: UserClientFlask):
|
|||
# create lot
|
||||
user3.get('/inventory/lot/add/')
|
||||
lot_name = 'lot1'
|
||||
lot_name2 = 'lot2'
|
||||
lot_name3 = 'lot3'
|
||||
data = {
|
||||
'name': lot_name,
|
||||
'csrf_token': generate_csrf(),
|
||||
|
@ -1422,12 +1426,13 @@ def test_edit_transfer(user3: UserClientFlask):
|
|||
|
||||
# create new incoming lot
|
||||
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)
|
||||
assert 'Transfer (<span class="text-success">Open</span>)' in body
|
||||
assert '<i class="bi bi-trash"></i> Delete Lot' in body
|
||||
lot = Lot.query.filter()[1]
|
||||
assert lot.transfer is not None
|
||||
assert lot_name2 in body
|
||||
|
||||
# edit transfer with errors
|
||||
lot_id = lot.id
|
||||
|
@ -1436,6 +1441,7 @@ def test_edit_transfer(user3: UserClientFlask):
|
|||
'csrf_token': generate_csrf(),
|
||||
'code': 'AAA',
|
||||
'description': 'one one one',
|
||||
'lot_name': lot_name3,
|
||||
'date': datetime.datetime.now().date() + datetime.timedelta(15),
|
||||
}
|
||||
body, status = user3.post(uri, data=data)
|
||||
|
@ -1450,6 +1456,7 @@ def test_edit_transfer(user3: UserClientFlask):
|
|||
'csrf_token': generate_csrf(),
|
||||
'code': 'AAA',
|
||||
'description': 'one one one',
|
||||
'lot_name': lot_name3,
|
||||
'date': datetime.datetime.now().date() - datetime.timedelta(15),
|
||||
}
|
||||
body, status = user3.post(uri, data=data)
|
||||
|
@ -1458,6 +1465,7 @@ def test_edit_transfer(user3: UserClientFlask):
|
|||
assert 'one one one' 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 lot_name3 in body
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
@ -1476,7 +1484,7 @@ def test_edit_deliverynote(user3: UserClientFlask):
|
|||
|
||||
# create new incoming lot
|
||||
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)
|
||||
lot = Lot.query.filter()[1]
|
||||
lot_id = lot.id
|
||||
|
@ -1517,7 +1525,7 @@ def test_edit_receivernote(user3: UserClientFlask):
|
|||
|
||||
# create new incoming lot
|
||||
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)
|
||||
lot = Lot.query.filter()[1]
|
||||
lot_id = lot.id
|
||||
|
@ -1558,7 +1566,7 @@ def test_edit_notes_with_closed_transfer(user3: UserClientFlask):
|
|||
|
||||
# create new incoming lot
|
||||
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)
|
||||
lot = Lot.query.filter()[1]
|
||||
lot_id = lot.id
|
||||
|
@ -2403,7 +2411,7 @@ def test_bug_3831_documents(user3: UserClientFlask):
|
|||
|
||||
uri = f'/inventory/lot/{lot_id}/transfer/incoming/'
|
||||
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)
|
||||
assert status == '200 OK'
|
||||
|
|
Reference in New Issue