change supplier for user_from and receiver for user_to

This commit is contained in:
Cayo Puigdefabregas 2022-02-18 09:30:20 +01:00
parent 538e355026
commit 8b27b18fc1
3 changed files with 29 additions and 29 deletions

View file

@ -628,10 +628,10 @@ class DataWipeForm(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",
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",
render_kw={'data-email': ""})
confirm = BooleanField(u'Confirm', [validators.Optional()],
@ -642,8 +642,8 @@ class TradeForm(NewActionForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.supplier.render_kw['data-email'] = g.user.email
self.receiver.render_kw['data-email'] = g.user.email
self.user_from.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()
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"]
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"]
if not self.receiver.data:
self.receiver.errors = errors
if not self.user_to.data:
self.user_to.errors = errors
if not self.supplier.data:
self.supplier.errors = errors
if not self.user_from.data:
self.user_from.errors = errors
is_valid = False
if self.confirm.data and is_valid:
user_to = User.query.filter_by(email=self.receiver.data).first() or g.user
user_from = User.query.filter_by(email=self.supplier.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.user_from.data).first() or g.user
if user_to == user_from:
is_valid = False
else:
@ -687,11 +687,11 @@ class TradeForm(NewActionForm):
def prepare_instance(self):
Model = db.Model._decl_class_registry.data[self.type.data]()
self.instance = Model()
self.instance.devices = self._lot.devices
self.instance.severity = Severity[self.severity.data]
# import pdb; pdb.set_trace()
self.instance.user_from = self.user_from
self.instance.user_to = self.user_to
self.instance.lot_id = self._lot.id
self.instance.devices = self._lot.devices
self.instance.code = self.code.data
self.instance.confirm = self.confirm.data
self.instance.date = self.date.data
@ -713,8 +713,8 @@ class TradeForm(NewActionForm):
if self.confirm.data or not self.code.data:
return
user_from = self.supplier.data
user_to = self.receiver.data
user_from = self.user_from.data
user_to = self.user_to.data
code = self.code.data
if user_from and user_to:

View file

@ -66,20 +66,20 @@ function removeTag() {
function newTrade(action) {
var title = "Trade "
var receiver = $("#receiver").data("email");
var supplier = $("#supplier").data("email");
if (action == 'supplier') {
var user_to = $("#user_to").data("email");
var user_from = $("#user_from").data("email");
if (action == 'user_from') {
title = 'Trade Incoming';
$("#receiver").attr('readonly', 'readonly');
$("#supplier").prop('readonly', false);
$("#supplier").val('');
$("#receiver").val(receiver);
} else if (action == 'receiver') {
$("#user_to").attr('readonly', 'readonly');
$("#user_from").prop('readonly', false);
$("#user_from").val('');
$("#user_to").val(user_to);
} else if (action == 'user_to') {
title = 'Trade Outgoing';
$("#supplier").attr('readonly', 'readonly');
$("#receiver").prop('readonly', false);
$("#receiver").val('');
$("#supplier").val(supplier);
$("#user_from").attr('readonly', 'readonly');
$("#user_to").prop('readonly', false);
$("#user_to").val('');
$("#user_from").val(user_from);
}
$("#tradeLotModalModal #title-action").html(title);
$("#activeTradeModal").click();

View file

@ -75,13 +75,13 @@
</li>
{% if lot.is_temporary %}
<li>
<a href="javascript:newTrade('supplier')" class="dropdown-item">
<a href="javascript:newTrade('user_from')" class="dropdown-item">
<i class="bi bi-plus"></i>
Add supplier
</a>
</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>
Add receiver
</a>