diff --git a/tine20/Timetracker/Controller/Timeaccount.php b/tine20/Timetracker/Controller/Timeaccount.php index 8ac0710558..ec46e2e89e 100644 --- a/tine20/Timetracker/Controller/Timeaccount.php +++ b/tine20/Timetracker/Controller/Timeaccount.php @@ -319,8 +319,9 @@ private function _resolveTimesheets($updatedRecord, $record, $currentRecord) $invoiceIdPresent = Sales_Config::getInstance()->featureEnabled(Sales_Config::FEATURE_INVOICES_MODULE); $filter = Tinebase_Model_Filter_FilterGroup::getFilterForModel(Timetracker_Model_Timesheet::class, [ - ['field' => 'timeaccount_id', 'operator' => 'equals', 'value' => $updatedRecord->getId()], - ]); + ['field' => 'timeaccount_id', 'operator' => 'equals', 'value' => $updatedRecord->getId()], + ['field' => 'is_billable', 'operator' => 'equals', 'value' => true], + ]); $innerFilter = Tinebase_Model_Filter_FilterGroup::getFilterForModel(Timetracker_Model_Timesheet::class, [ ['field' => 'is_cleared', 'operator' => 'equals', 'value' => false], ], Tinebase_Model_Filter_FilterGroup::CONDITION_OR); diff --git a/tine20/Timetracker/js/TimeaccountEditDialog.js b/tine20/Timetracker/js/TimeaccountEditDialog.js index 0c875f7298..1d623e39b1 100644 --- a/tine20/Timetracker/js/TimeaccountEditDialog.js +++ b/tine20/Timetracker/js/TimeaccountEditDialog.js @@ -261,6 +261,7 @@ Tine.Timetracker.TimeaccountEditDialog = Ext.extend(Tine.widgets.dialog.EditDial listeners: { scope: this, 'select': (combo, invoiceRecord, index) => { + this.updateTimeaccount = true; this.record.set('invoice_id', invoiceRecord.get('id')); this.invoiceRecordPicker.setValue(invoiceRecord); } @@ -305,32 +306,32 @@ Tine.Timetracker.TimeaccountEditDialog = Ext.extend(Tine.widgets.dialog.EditDial }, onApplyChanges: async function (closeWindow) { - let notAccountedTimesheets = []; - if (this.record.get('status') === 'billed') { + await new Promise(async (resolve) => { + if (this.record.get('status') !== 'billed' || !this.updateTimeaccount) return resolve(); const filter = [ {field: 'timeaccount_id', operator: 'equals', value: this.record.get('id')}, + {field: 'is_billable', operator: 'equals', value: true}, + { + condition: "OR", filters: [ + {field: 'is_cleared', operator: 'equals', value: false}, + {field: 'invoice_id', operator: 'equals', value: null}, + ] + } ]; - await Tine.Timetracker.searchTimesheets(filter) - .then((result) => { - notAccountedTimesheets = _.filter(result.results, (timesheet) => { - return timesheet?.is_cleared === '0' || !timesheet?.invoice_id; - }); - }) - } - - if (notAccountedTimesheets.length > 0) { + const {results: notAccountedTimesheets} = await Tine.Timetracker.searchTimesheets(filter); + if (notAccountedTimesheets.length === 0) return resolve(); Ext.MessageBox.confirm( this.app.i18n._('Update Timesheets?'), this.app.i18n._('Attention: There are timesheets that have not yet been accounted. ' + 'If you continue, they will be set to accounted. ' + 'This action cannot be undone. Continue anyway?'), - function (button) { - if (button === 'yes') { - Tine.Timetracker.TimeaccountEditDialog.superclass.onApplyChanges.call(this, closeWindow); - } - }, this); - } else { + function (button) { + if (button === 'yes') { + return resolve(); + } + }, this); + }).then(() => { Tine.Timetracker.TimeaccountEditDialog.superclass.onApplyChanges.call(this, closeWindow); - } + }) } });