Bugfix - voucher items manipulation fixed.

master
Josef Rokos 2 years ago
parent 46b2098ffc
commit 8b132c6c51

@ -131,7 +131,13 @@ void Voucher::addItem(QSharedPointer<VoucherItem> item)
void Voucher::removeItem(QSharedPointer<VoucherItem> item)
{
if (item->id() != 0) {
m_items.removeIf([&item](const auto& it){
return item->id() == it->id();
});
} else {
m_items.removeOne(item);
}
}
void Voucher::clearItems()

@ -515,7 +515,6 @@ void ShopForm::recalculate()
{
ShopService srv;
srv.calculate(m_voucher);
this->m_itemsModel->setData(m_voucher->items());
setTotalText();
ui->temporarySaveButton->setEnabled(!m_voucher->items().isEmpty());
@ -530,6 +529,9 @@ void ShopForm::recalculate()
{
srv.update(m_voucher);
}
this->m_itemsModel->setData(m_voucher->items());
connectItemSignals();
}
void ShopForm::on_receiptCombo_currentIndexChanged(int)
@ -654,8 +656,10 @@ void ShopForm::on_actionDelete_items_triggered()
QList<VoucherItemPtr> forDelete;
for (const auto& row : ui->actualReceipt->selectionModel()->selectedIndexes()) {
if (!forDelete.contains(m_itemsModel->itemFromIndex(row))) {
forDelete << m_itemsModel->itemFromIndex(row);
}
}
for (auto& item : forDelete) {
m_voucher->removeItem(item);

@ -173,6 +173,10 @@ void ShopService::pay(VoucherPtr voucher)
voucher->setPayDateTime(QDateTime::currentDateTime());
this->update(voucher, &session);
if (!session.isValid()) {
qDebug() << session.firstError().text();
}
}
void ShopService::updateRelatedItem(VoucherItem* item, int countAdded)
@ -526,10 +530,11 @@ void ShopService::update(VoucherPtr entity, qx::QxSession* pSession) {
Service::update(entity, pSession);
auto oldItems = entity->items();
entity->clearItems();
load(entity);
for (auto item : entity->items()) {
Service<VoucherItem> srvItem;
auto items = srvItem.all("voucher = " + QString::number(entity->id()));
for (auto item : items) {
auto newItem = std::find_if(oldItems.begin(), oldItems.end(), [item](auto it){
return item->id() == it->id();
});

Loading…
Cancel
Save