Bugfix - voucher items manipulation fixed.
This commit is contained in:
@@ -131,8 +131,14 @@ void Voucher::addItem(QSharedPointer<VoucherItem> item)
|
|||||||
|
|
||||||
void Voucher::removeItem(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);
|
m_items.removeOne(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Voucher::clearItems()
|
void Voucher::clearItems()
|
||||||
{
|
{
|
||||||
|
|||||||
+5
-1
@@ -515,7 +515,6 @@ void ShopForm::recalculate()
|
|||||||
{
|
{
|
||||||
ShopService srv;
|
ShopService srv;
|
||||||
srv.calculate(m_voucher);
|
srv.calculate(m_voucher);
|
||||||
this->m_itemsModel->setData(m_voucher->items());
|
|
||||||
|
|
||||||
setTotalText();
|
setTotalText();
|
||||||
ui->temporarySaveButton->setEnabled(!m_voucher->items().isEmpty());
|
ui->temporarySaveButton->setEnabled(!m_voucher->items().isEmpty());
|
||||||
@@ -530,6 +529,9 @@ void ShopForm::recalculate()
|
|||||||
{
|
{
|
||||||
srv.update(m_voucher);
|
srv.update(m_voucher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->m_itemsModel->setData(m_voucher->items());
|
||||||
|
connectItemSignals();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShopForm::on_receiptCombo_currentIndexChanged(int)
|
void ShopForm::on_receiptCombo_currentIndexChanged(int)
|
||||||
@@ -654,8 +656,10 @@ void ShopForm::on_actionDelete_items_triggered()
|
|||||||
QList<VoucherItemPtr> forDelete;
|
QList<VoucherItemPtr> forDelete;
|
||||||
|
|
||||||
for (const auto& row : ui->actualReceipt->selectionModel()->selectedIndexes()) {
|
for (const auto& row : ui->actualReceipt->selectionModel()->selectedIndexes()) {
|
||||||
|
if (!forDelete.contains(m_itemsModel->itemFromIndex(row))) {
|
||||||
forDelete << m_itemsModel->itemFromIndex(row);
|
forDelete << m_itemsModel->itemFromIndex(row);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& item : forDelete) {
|
for (auto& item : forDelete) {
|
||||||
m_voucher->removeItem(item);
|
m_voucher->removeItem(item);
|
||||||
|
|||||||
@@ -173,6 +173,10 @@ void ShopService::pay(VoucherPtr voucher)
|
|||||||
voucher->setPayDateTime(QDateTime::currentDateTime());
|
voucher->setPayDateTime(QDateTime::currentDateTime());
|
||||||
|
|
||||||
this->update(voucher, &session);
|
this->update(voucher, &session);
|
||||||
|
|
||||||
|
if (!session.isValid()) {
|
||||||
|
qDebug() << session.firstError().text();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShopService::updateRelatedItem(VoucherItem* item, int countAdded)
|
void ShopService::updateRelatedItem(VoucherItem* item, int countAdded)
|
||||||
@@ -526,10 +530,11 @@ void ShopService::update(VoucherPtr entity, qx::QxSession* pSession) {
|
|||||||
|
|
||||||
Service::update(entity, pSession);
|
Service::update(entity, pSession);
|
||||||
auto oldItems = entity->items();
|
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){
|
auto newItem = std::find_if(oldItems.begin(), oldItems.end(), [item](auto it){
|
||||||
return item->id() == it->id();
|
return item->id() == it->id();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user