Skip to content

Commit

Permalink
fix(Timetracker/Export/Ods): export start time by template tag
Browse files Browse the repository at this point in the history
  • Loading branch information
ccheng-dev authored and pschuele committed Aug 5, 2024
1 parent bdd9d68 commit 319b6df
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 14 deletions.
65 changes: 65 additions & 0 deletions tests/tine20/Sales/Export/definitions/rechnung_bereitschaft.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<model>Timetracker_Model_Timesheet</model>
<name>ts_rechnung_ods</name>
<type>export</type>
<plugin>Timetracker_Export_Ods_Timesheet</plugin>
<description>standard rechnungs export</description>
<customFields>1</customFields>
<header>1</header>
<headers>
<header>{date}</header>
<header>{user}</header>
</headers>
<columns>
<column>
<identifier>start_date</identifier>
<header>Datum</header>
<type>date</type>
</column>
<column>
<identifier>description</identifier>
<header>Bemerkungen / Art der Arbeit</header>
<type>string</type>
<maxcharacters>250</maxcharacters>
<maxlines>30</maxlines>
<removeEmptyLines>1</removeEmptyLines>
</column>
<column>
<identifier>asp</identifier>
<header>Ansprechpartner</header>
<type>string</type>
<custom>1</custom>
</column>
<column>
<identifier>account_id</identifier>
<header>Mitarbeiter</header>
<type>account_id</type>
<field>accountDisplayName</field>
</column>
<column>
<identifier>accounting_time</identifier>
<header>Std.</header>
<type>float</type>
<divisor>60</divisor>
<number>1</number>
</column>
<column>
<identifier>ticket</identifier>
<header>T#</header>
<type>string</type>
<custom>1</custom>
</column>
<column>
<identifier>start_time</identifier>
<header>Startzeit</header>
<type>string</type>
<clearValueIfTagNotSet>Bereitschaft</clearValueIfTagNotSet>
</column>
<column>
<identifier>tags</identifier>
<header>Tags</header>
<type>tags</type>
</column>
</columns>
</config>
19 changes: 15 additions & 4 deletions tests/tine20/Sales/InvoiceControllerTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -1879,7 +1879,7 @@ public function testExportInvoicePositionsOds()
if (!$fsConfig || !$fsConfig->{Tinebase_Config::FILESYSTEM_CREATE_PREVIEWS}) {
$this->markTestSkipped('PreviewService not configured.');
}

if ($this->_addressRecords === null) {
$this->_createCustomers(1);
}
Expand Down Expand Up @@ -2008,9 +2008,20 @@ public function testExportInvoicePositionsOds()
));
$filter->addFilter(new Tinebase_Model_Filter_Text(array('field' => 'invoice_id', 'operator' => 'equals', 'value' => $invoice->getId())));

// test default template
Tinebase_Core::getPreference('Timetracker')->setValue(Timetracker_Preference::TSODSEXPORTCONFIG, 'ts_default_ods');
$export = Tinebase_Export::factory($filter, ['format' => 'ods',], Timetracker_Controller_Timesheet::getInstance());
// test export with test template
$config = [
'definition' => __DIR__ . '/Export/definitions/rechnung_bereitschaft.xml',
'app' => 'Timetracker'
];
$app = Tinebase_Application::getInstance()->getApplicationByName($config['app']);
$definition = Tinebase_ImportExportDefinition::getInstance()
->updateOrCreateFromFilename($config['definition'], $app);

$export = Tinebase_Export::factory($filter, [
'format' => 'ods',
'definitionId' => $definition,
], Timetracker_Controller_Timesheet::getInstance());

$result = $export->generate();
$xmlBody = $export->getDocument()->asXML();
$this->assertTrue(file_exists($result));
Expand Down
15 changes: 5 additions & 10 deletions tine20/Timetracker/Export/Ods/Timesheet.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ class Timetracker_Export_Ods_Timesheet extends Tinebase_Export_Spreadsheet_Ods
*/
protected $_specialFields = array('timeaccount');

/**
* Summarize records with a certain tag
*/
const TAG_SUM = 'Bereitschaft';

/**
* the constructor
*
Expand All @@ -66,16 +61,16 @@ protected function _resolveRecords(Tinebase_Record_RecordSet $_records)
// @todo we need a more generic way of resolving tags! thats quite obscure for modelconfig applications! -> TRA->getTags() maybe?
Tinebase_Tags::getInstance()->getMultipleTagsOfRecords($_records);
parent::_resolveRecords($_records);
$showStartDate = true;


$tag = null;
foreach ($this->_config->columns->column as $field) {
if ($field->identifier === 'start_time' && isset($field->clearValueIfTagNotSet) && $field->clearValueIfTagNotSet === static::TAG_SUM) {
$showStartDate = false;
if ($field->identifier === 'start_time' && !empty($field->clearValueIfTagNotSet)) {
$tag = $field->clearValueIfTagNotSet;
}
}

foreach ($_records as $record) {
if (!$showStartDate || !$record->tags || ($record->tags->filter('name', static::TAG_SUM)->count() === 0)) {
if ($tag && (!$record->tags || ($record->tags->filter('name', $tag)->count() === 0))) {
$record->start_time = null;
$record->end_time = null;
}
Expand Down

0 comments on commit 319b6df

Please sign in to comment.