Commit 05ea62a8 authored by Vincent Texier's avatar Vincent Texier

[enh] #798 source automatically checked when opening transfer dialog

parent 5d2df929
......@@ -53,7 +53,7 @@ class TransferController(QObject):
)
self.view.spinbox_amount.valueChanged.connect(self.handle_amount_change)
self.view.spinbox_relative.valueChanged.connect(self.handle_relative_change)
self.view.button_source_check.clicked.connect(self.check_source)
self.view.button_source_check.clicked.connect(self.check_source_dialog)
@classmethod
def create(cls, parent, app):
......@@ -117,7 +117,11 @@ class TransferController(QObject):
controller.set_amount_value(source.amount, source.base)
controller.view.spinbox_amount.setDisabled(True)
controller.view.spinbox_relative.setDisabled(True)
controller.view.button_source_check.setEnabled(True)
result, _ = controller.check_source(source)
# by default, source is unlocked, if not...
if not result:
# enabled the check button to open the errors dialog
controller.view.button_source_check.setEnabled(True)
else:
controller.view.widget_source.hide()
......@@ -326,9 +330,19 @@ class TransferController(QObject):
self.password_input.set_connection(self.model.connection)
self.refresh()
def check_source(self):
def check_source(self, source):
"""
Check source conditions lock status
Return a tupple with :
result: bool,
errors: list of tuples
[(condition: str, message: str, info: int|str),...]
:param source:
:return tuple:
"""
# evaluate condition
source = self.model.current_source
condition = pypeg2.parse(source.conditions, Condition)
result, _errors = self.model.app.sources_service.evaluate_condition(
self.model.app.currency,
......@@ -337,6 +351,17 @@ class TransferController(QObject):
[],
source.identifier,
)
return result, _errors
def check_source_dialog(self):
"""
Open check source result and errors dialog
:return:
"""
source = self.model.current_source
result, _errors = self.check_source(source)
# if success...
if result:
message = QCoreApplication.translate(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment