Commit bb6c1661 authored by Thomas Baumgart's avatar Thomas Baumgart
Browse files

Entering negative amounts switches between deposit and payment

In some circumstances, entering negative amounts did not have any
effect. This change fixes that so that entering a negative amount
changes a payment into a deposit and vice versa.

BUG: 186616
FIXED-IN: 5.1.2
parent b4d06aef
......@@ -448,8 +448,6 @@ void StdTransactionEditor::loadEditWidgets(eRegister::Action action)
amountWidget->setValue(value.abs());
}
slotUpdateCategory(categoryId);
// try to preset for specific action if a new transaction is being started
if (d->m_transaction.id().isEmpty()) {
if ((w = haveWidget("category-label")) != 0) {
......@@ -1039,28 +1037,13 @@ void StdTransactionEditor::updateAmount(const MyMoneyMoney& val)
auto categoryLabel = dynamic_cast<QLabel*>(haveWidget("category-label"));
if (categoryLabel) {
if (auto cashflow = dynamic_cast<KMyMoneyCashFlowCombo*>(d->m_editWidgets["cashflow"])) {
if (!val.isPositive()) { // fixes BUG321317
if (categoryLabel->text() != i18n("Category")) {
if (cashflow->direction() == eRegister::CashFlowDirection::Payment) {
categoryLabel->setText(i18n("Transfer to"));
}
} else {
slotUpdateCashFlow(cashflow->direction());
}
if (auto amountWidget = dynamic_cast<AmountEdit*>(d->m_editWidgets["amount"]))
amountWidget->setValue(val.abs());
} else {
if (categoryLabel->text() != i18n("Category")) {
if (cashflow->direction() == eRegister::CashFlowDirection::Payment) {
categoryLabel->setText(i18n("Transfer to"));
} else {
categoryLabel->setText(i18n("Transfer from"));
cashflow->setDirection(eRegister::CashFlowDirection::Deposit); // editing with +ve shows 'from' not 'pay to'
}
}
if (auto amountWidget = dynamic_cast<AmountEdit*>(d->m_editWidgets["amount"]))
amountWidget->setValue(val.abs());
QSignalBlocker blockCashFlow(cashflow);
if (val.isNegative()) {
cashflow->reverseDirection();
}
slotUpdateCashFlow(cashflow->direction());
if (auto amountWidget = dynamic_cast<AmountEdit*>(d->m_editWidgets["amount"]))
amountWidget->setValue(val.abs());
}
}
}
......
......@@ -67,6 +67,21 @@ void KMyMoneyCashFlowCombo::setDirection(eRegister::CashFlowDirection dir)
setSelectedItem(num.setNum((int)dir));
}
void KMyMoneyCashFlowCombo::reverseDirection()
{
Q_D(KMyMoneyCashFlowCombo);
switch (d->m_dir) {
case eWidgets::eRegister::CashFlowDirection::Deposit:
setDirection(eWidgets::eRegister::CashFlowDirection::Payment);
break;
case eWidgets::eRegister::CashFlowDirection::Payment:
setDirection(eWidgets::eRegister::CashFlowDirection::Deposit);
break;
default:
break;
}
}
eRegister::CashFlowDirection KMyMoneyCashFlowCombo::direction() const
{
Q_D(const KMyMoneyCashFlowCombo);
......
......@@ -51,6 +51,7 @@ public:
~KMyMoneyCashFlowCombo() override;
void setDirection(eWidgets::eRegister::CashFlowDirection dir);
void reverseDirection();
eWidgets::eRegister::CashFlowDirection direction() const;
void removeDontCare();
......
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