add render views for delivery and receiver notes
This commit is contained in:
parent
e635abdbbc
commit
83bdf79514
|
@ -1181,6 +1181,14 @@ class EditTransferForm(TransferForm):
|
||||||
self.description.data = self._obj.description
|
self.description.data = self._obj.description
|
||||||
self.date.data = self._obj.date
|
self.date.data = self._obj.date
|
||||||
|
|
||||||
|
def validate(self, extra_validators=None):
|
||||||
|
is_valid = super().validate(extra_validators)
|
||||||
|
date = self.date.data
|
||||||
|
if date and date > datetime.datetime.now().date():
|
||||||
|
self.date.errors = ["You have to choose a date before today."]
|
||||||
|
is_valid = False
|
||||||
|
return is_valid
|
||||||
|
|
||||||
def set_obj(self, commit=True):
|
def set_obj(self, commit=True):
|
||||||
self.populate_obj(self._obj)
|
self.populate_obj(self._obj)
|
||||||
|
|
||||||
|
@ -1239,13 +1247,58 @@ class NotesForm(FlaskForm):
|
||||||
"""You can put a number for tracer of receiber note."""
|
"""You can put a number for tracer of receiber note."""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if self.is_editable():
|
||||||
|
self.number.render_kw.pop('disabled', None)
|
||||||
|
self.date.render_kw.pop('disabled', None)
|
||||||
|
self.units.render_kw.pop('disabled', None)
|
||||||
|
self.weight.render_kw.pop('disabled', None)
|
||||||
|
else:
|
||||||
|
disabled = {'disabled': "disabled"}
|
||||||
|
self.number.render_kw.update(disabled)
|
||||||
|
self.date.render_kw.update(disabled)
|
||||||
|
self.units.render_kw.update(disabled)
|
||||||
|
self.weight.render_kw.update(disabled)
|
||||||
|
|
||||||
if self._obj and not self.data['csrf_token']:
|
if self._obj and not self.data['csrf_token']:
|
||||||
self.number.data = self._obj.number
|
self.number.data = self._obj.number
|
||||||
self.date.data = self._obj.date
|
self.date.data = self._obj.date
|
||||||
self.units.data = self._obj.units
|
self.units.data = self._obj.units
|
||||||
self.weight.data = self._obj.weight
|
self.weight.data = self._obj.weight
|
||||||
|
|
||||||
|
def is_editable(self):
|
||||||
|
if not self._tmp_lot.transfer:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self._tmp_lot.transfer.closed:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self._tmp_lot.transfer.code:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if self._tmp_lot.transfer.user_from == g.user and self.type == 'Receiver':
|
||||||
|
return False
|
||||||
|
|
||||||
|
if self._tmp_lot.transfer.user_to == g.user and self.type == 'Delivery':
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def validate(self, extra_validators=None):
|
||||||
|
is_valid = super().validate(extra_validators)
|
||||||
|
date = self.date.data
|
||||||
|
if date and date > datetime.datetime.now().date():
|
||||||
|
self.date.errors = ["You have to choose a date before today."]
|
||||||
|
is_valid = False
|
||||||
|
|
||||||
|
if not self.is_editable():
|
||||||
|
is_valid = False
|
||||||
|
|
||||||
|
return is_valid
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
|
if self._tmp_lot.transfer.closed:
|
||||||
|
return self._obj
|
||||||
|
|
||||||
self.populate_obj(self._obj)
|
self.populate_obj(self._obj)
|
||||||
db.session.add(self._obj)
|
db.session.add(self._obj)
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,8 @@ class DeviceListMixin(GenericMixin):
|
||||||
devices = form_filter.search()
|
devices = form_filter.search()
|
||||||
lot = None
|
lot = None
|
||||||
form_transfer = ''
|
form_transfer = ''
|
||||||
|
form_delivery = ''
|
||||||
|
form_receiver = ''
|
||||||
|
|
||||||
if lot_id:
|
if lot_id:
|
||||||
lot = lots.filter(Lot.id == lot_id).one()
|
lot = lots.filter(Lot.id == lot_id).one()
|
||||||
|
@ -458,6 +460,10 @@ class EditTransferView(GenericMixin):
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
messages.error('Transfer updated error!')
|
messages.error('Transfer updated error!')
|
||||||
|
for k, v in form.errors.items():
|
||||||
|
value = ';'.join(v)
|
||||||
|
key = form[k].label.text
|
||||||
|
messages.error('Error {key}: {value}!'.format(key=key, value=value))
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
|
@ -647,10 +653,14 @@ class DeliveryNoteView(GenericMixin):
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.save()
|
form.save()
|
||||||
messages.success('Transfer updated successfully!')
|
messages.success('Delivery Note updated successfully!')
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
messages.error('Transfer updated error!')
|
messages.error('Delivery Note updated error!')
|
||||||
|
for k, v in form.errors.items():
|
||||||
|
value = ';'.join(v)
|
||||||
|
key = form[k].label.text
|
||||||
|
messages.error('Error {key}: {value}!'.format(key=key, value=value))
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
|
@ -665,10 +675,14 @@ class ReceiverNoteView(GenericMixin):
|
||||||
|
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.save()
|
form.save()
|
||||||
messages.success('Transfer updated successfully!')
|
messages.success('Receiver Note updated successfully!')
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
messages.error('Transfer updated error!')
|
messages.error('Receiver Note updated error!')
|
||||||
|
for k, v in form.errors.items():
|
||||||
|
value = ';'.join(v)
|
||||||
|
key = form[k].label.text
|
||||||
|
messages.error('Error {key}: {value}!'.format(key=key, value=value))
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
|
|
||||||
|
@ -736,9 +750,9 @@ devices.add_url_rule(
|
||||||
)
|
)
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/lot/<string:lot_id>/deliverynote/',
|
'/lot/<string:lot_id>/deliverynote/',
|
||||||
view_func=DeliveryNoteView.as_view('deliverynote'),
|
view_func=DeliveryNoteView.as_view('delivery_note'),
|
||||||
)
|
)
|
||||||
devices.add_url_rule(
|
devices.add_url_rule(
|
||||||
'/lot/<string:lot_id>/receivernote/',
|
'/lot/<string:lot_id>/receivernote/',
|
||||||
view_func=ReceiverNoteView.as_view('receivernote'),
|
view_func=ReceiverNoteView.as_view('receiver_note'),
|
||||||
)
|
)
|
||||||
|
|
|
@ -490,6 +490,7 @@
|
||||||
<span class="text-danger">*</span>
|
<span class="text-danger">*</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{{ field }}
|
{{ field }}
|
||||||
|
<small class="text-muted">{{ field.description }}</small>
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
<p class="text-danger">
|
<p class="text-danger">
|
||||||
{% for error in field.errors %}
|
{% for error in field.errors %}
|
||||||
|
@ -510,7 +511,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div id="edit-delivery-note" class="tab-pane fade edit-delivery-note">
|
<div id="edit-delivery-note" class="tab-pane fade edit-delivery-note">
|
||||||
<h5 class="card-title">Delivery Note</h5>
|
<h5 class="card-title">Delivery Note</h5>
|
||||||
<form method="post" action="{{ url_for('inventory.edit_transfer', lot_id=lot.id) }}" class="row g-3 needs-validation" novalidate>
|
<form method="post" action="{{ url_for('inventory.delivery_note', lot_id=lot.id) }}" class="row g-3 needs-validation" novalidate>
|
||||||
{{ form_delivery.csrf_token }}
|
{{ form_delivery.csrf_token }}
|
||||||
|
|
||||||
{% for field in form_delivery %}
|
{% for field in form_delivery %}
|
||||||
|
@ -519,6 +520,7 @@
|
||||||
{% if field != form_delivery.type %}
|
{% if field != form_delivery.type %}
|
||||||
{{ field.label(class_="form-label") }}
|
{{ field.label(class_="form-label") }}
|
||||||
{{ field }}
|
{{ field }}
|
||||||
|
<small class="text-muted">{{ field.description }}</small>
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
<p class="text-danger">
|
<p class="text-danger">
|
||||||
{% for error in field.errors %}
|
{% for error in field.errors %}
|
||||||
|
@ -531,15 +533,17 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if lot.transfer and form_receiver.is_editable() %}
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url_for('inventory.lotdevicelist', lot_id=lot.id) }}" class="btn btn-danger">Cancel</a>
|
<a href="{{ url_for('inventory.lotdevicelist', lot_id=lot.id) }}" 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>
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div id="edit-receiver-note" class="tab-pane fade edit-receiver-note">
|
<div id="edit-receiver-note" class="tab-pane fade edit-receiver-note">
|
||||||
<h5 class="card-title">Receiver Note</h5>
|
<h5 class="card-title">Receiver Note</h5>
|
||||||
<form method="post" action="{{ url_for('inventory.edit_transfer', lot_id=lot.id) }}" class="row g-3 needs-validation" novalidate>
|
<form method="post" action="{{ url_for('inventory.receiver_note', lot_id=lot.id) }}" class="row g-3 needs-validation" novalidate>
|
||||||
{{ form_receiver.csrf_token }}
|
{{ form_receiver.csrf_token }}
|
||||||
|
|
||||||
{% for field in form_receiver %}
|
{% for field in form_receiver %}
|
||||||
|
@ -548,6 +552,7 @@
|
||||||
{% if field != form_receiver.type %}
|
{% if field != form_receiver.type %}
|
||||||
{{ field.label(class_="form-label") }}
|
{{ field.label(class_="form-label") }}
|
||||||
{{ field }}
|
{{ field }}
|
||||||
|
<small class="text-muted">{{ field.description }}</small>
|
||||||
{% if field.errors %}
|
{% if field.errors %}
|
||||||
<p class="text-danger">
|
<p class="text-danger">
|
||||||
{% for error in field.errors %}
|
{% for error in field.errors %}
|
||||||
|
@ -560,10 +565,12 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if lot.transfer and form_receiver.is_editable() %}
|
||||||
<div>
|
<div>
|
||||||
<a href="{{ url_for('inventory.lotdevicelist', lot_id=lot.id) }}" class="btn btn-danger">Cancel</a>
|
<a href="{{ url_for('inventory.lotdevicelist', lot_id=lot.id) }}" 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>
|
||||||
|
{% endif %}
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Reference in New Issue