change supplier for user_from and receiver for user_to
This commit is contained in:
parent
538e355026
commit
8b27b18fc1
|
@ -628,10 +628,10 @@ class DataWipeForm(NewActionForm):
|
||||||
|
|
||||||
|
|
||||||
class TradeForm(NewActionForm):
|
class TradeForm(NewActionForm):
|
||||||
supplier = StringField(u'Supplier', [validators.Optional()],
|
user_from = StringField(u'Supplier', [validators.Optional()],
|
||||||
description="Please enter the supplier's email address",
|
description="Please enter the supplier's email address",
|
||||||
render_kw={'data-email': ""})
|
render_kw={'data-email': ""})
|
||||||
receiver = StringField(u'Receiver', [validators.Optional()],
|
user_to = StringField(u'Receiver', [validators.Optional()],
|
||||||
description="Please enter the receiver's email address",
|
description="Please enter the receiver's email address",
|
||||||
render_kw={'data-email': ""})
|
render_kw={'data-email': ""})
|
||||||
confirm = BooleanField(u'Confirm', [validators.Optional()],
|
confirm = BooleanField(u'Confirm', [validators.Optional()],
|
||||||
|
@ -642,8 +642,8 @@ class TradeForm(NewActionForm):
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.supplier.render_kw['data-email'] = g.user.email
|
self.user_from.render_kw['data-email'] = g.user.email
|
||||||
self.receiver.render_kw['data-email'] = g.user.email
|
self.user_to.render_kw['data-email'] = g.user.email
|
||||||
self._lot = Lot.query.filter(Lot.id==self.lot.data).filter(Lot.owner_id==g.user.id).one()
|
self._lot = Lot.query.filter(Lot.id==self.lot.data).filter(Lot.owner_id==g.user.id).one()
|
||||||
|
|
||||||
def validate(self, extra_validators=None):
|
def validate(self, extra_validators=None):
|
||||||
|
@ -653,19 +653,19 @@ class TradeForm(NewActionForm):
|
||||||
self.code.errors = ["If you don't want confirm, you need a code"]
|
self.code.errors = ["If you don't want confirm, you need a code"]
|
||||||
is_valid = False
|
is_valid = False
|
||||||
|
|
||||||
if self.confirm.data and not (self.receiver.data or self.supplier.data):
|
if self.confirm.data and not (self.user_to.data or self.user_to.data):
|
||||||
errors = ["If you want confirm, you need a email"]
|
errors = ["If you want confirm, you need a email"]
|
||||||
if not self.receiver.data:
|
if not self.user_to.data:
|
||||||
self.receiver.errors = errors
|
self.user_to.errors = errors
|
||||||
|
|
||||||
if not self.supplier.data:
|
if not self.user_from.data:
|
||||||
self.supplier.errors = errors
|
self.user_from.errors = errors
|
||||||
|
|
||||||
is_valid = False
|
is_valid = False
|
||||||
|
|
||||||
if self.confirm.data and is_valid:
|
if self.confirm.data and is_valid:
|
||||||
user_to = User.query.filter_by(email=self.receiver.data).first() or g.user
|
user_to = User.query.filter_by(email=self.user_to.data).first() or g.user
|
||||||
user_from = User.query.filter_by(email=self.supplier.data).first() or g.user
|
user_from = User.query.filter_by(email=self.user_from.data).first() or g.user
|
||||||
if user_to == user_from:
|
if user_to == user_from:
|
||||||
is_valid = False
|
is_valid = False
|
||||||
else:
|
else:
|
||||||
|
@ -687,11 +687,11 @@ class TradeForm(NewActionForm):
|
||||||
def prepare_instance(self):
|
def prepare_instance(self):
|
||||||
Model = db.Model._decl_class_registry.data[self.type.data]()
|
Model = db.Model._decl_class_registry.data[self.type.data]()
|
||||||
self.instance = Model()
|
self.instance = Model()
|
||||||
self.instance.devices = self._lot.devices
|
# import pdb; pdb.set_trace()
|
||||||
self.instance.severity = Severity[self.severity.data]
|
|
||||||
self.instance.user_from = self.user_from
|
self.instance.user_from = self.user_from
|
||||||
self.instance.user_to = self.user_to
|
self.instance.user_to = self.user_to
|
||||||
self.instance.lot_id = self._lot.id
|
self.instance.lot_id = self._lot.id
|
||||||
|
self.instance.devices = self._lot.devices
|
||||||
self.instance.code = self.code.data
|
self.instance.code = self.code.data
|
||||||
self.instance.confirm = self.confirm.data
|
self.instance.confirm = self.confirm.data
|
||||||
self.instance.date = self.date.data
|
self.instance.date = self.date.data
|
||||||
|
@ -713,8 +713,8 @@ class TradeForm(NewActionForm):
|
||||||
if self.confirm.data or not self.code.data:
|
if self.confirm.data or not self.code.data:
|
||||||
return
|
return
|
||||||
|
|
||||||
user_from = self.supplier.data
|
user_from = self.user_from.data
|
||||||
user_to = self.receiver.data
|
user_to = self.user_to.data
|
||||||
code = self.code.data
|
code = self.code.data
|
||||||
|
|
||||||
if user_from and user_to:
|
if user_from and user_to:
|
||||||
|
|
|
@ -66,20 +66,20 @@ function removeTag() {
|
||||||
|
|
||||||
function newTrade(action) {
|
function newTrade(action) {
|
||||||
var title = "Trade "
|
var title = "Trade "
|
||||||
var receiver = $("#receiver").data("email");
|
var user_to = $("#user_to").data("email");
|
||||||
var supplier = $("#supplier").data("email");
|
var user_from = $("#user_from").data("email");
|
||||||
if (action == 'supplier') {
|
if (action == 'user_from') {
|
||||||
title = 'Trade Incoming';
|
title = 'Trade Incoming';
|
||||||
$("#receiver").attr('readonly', 'readonly');
|
$("#user_to").attr('readonly', 'readonly');
|
||||||
$("#supplier").prop('readonly', false);
|
$("#user_from").prop('readonly', false);
|
||||||
$("#supplier").val('');
|
$("#user_from").val('');
|
||||||
$("#receiver").val(receiver);
|
$("#user_to").val(user_to);
|
||||||
} else if (action == 'receiver') {
|
} else if (action == 'user_to') {
|
||||||
title = 'Trade Outgoing';
|
title = 'Trade Outgoing';
|
||||||
$("#supplier").attr('readonly', 'readonly');
|
$("#user_from").attr('readonly', 'readonly');
|
||||||
$("#receiver").prop('readonly', false);
|
$("#user_to").prop('readonly', false);
|
||||||
$("#receiver").val('');
|
$("#user_to").val('');
|
||||||
$("#supplier").val(supplier);
|
$("#user_from").val(user_from);
|
||||||
}
|
}
|
||||||
$("#tradeLotModalModal #title-action").html(title);
|
$("#tradeLotModalModal #title-action").html(title);
|
||||||
$("#activeTradeModal").click();
|
$("#activeTradeModal").click();
|
||||||
|
|
|
@ -75,13 +75,13 @@
|
||||||
</li>
|
</li>
|
||||||
{% if lot.is_temporary %}
|
{% if lot.is_temporary %}
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:newTrade('supplier')" class="dropdown-item">
|
<a href="javascript:newTrade('user_from')" class="dropdown-item">
|
||||||
<i class="bi bi-plus"></i>
|
<i class="bi bi-plus"></i>
|
||||||
Add supplier
|
Add supplier
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a href="javascript:newTrade('receiver')" class="dropdown-item">
|
<a href="javascript:newTrade('user_to')" class="dropdown-item">
|
||||||
<i class="bi bi-plus"></i>
|
<i class="bi bi-plus"></i>
|
||||||
Add receiver
|
Add receiver
|
||||||
</a>
|
</a>
|
||||||
|
|
Reference in New Issue