invoice: do not use activity name as fallback for description (#4884)
* added replacement field description_safe
This commit is contained in:
@@ -88,10 +88,6 @@ abstract class AbstractMergedCalculator extends AbstractCalculator
|
||||
$invoiceItem->setProject($entry->getProject());
|
||||
}
|
||||
|
||||
if (empty($invoiceItem->getDescription()) && null !== $entry->getActivity()) {
|
||||
$invoiceItem->setDescription($entry->getActivity()->getName());
|
||||
}
|
||||
|
||||
if ($entry instanceof Timesheet) {
|
||||
foreach ($entry->getTagsAsArray() as $tag) {
|
||||
$invoiceItem->addTag($tag);
|
||||
|
||||
@@ -47,10 +47,6 @@ final class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
|
||||
$begin = $item->getBegin();
|
||||
$end = $item->getEnd();
|
||||
|
||||
if (empty($description) && null !== $activity) {
|
||||
$description = $activity->getName();
|
||||
}
|
||||
|
||||
// this should never happen!
|
||||
if (empty($appliedRate)) {
|
||||
$appliedRate = 0;
|
||||
@@ -59,6 +55,7 @@ final class InvoiceItemDefaultHydrator implements InvoiceItemHydrator
|
||||
$values = [
|
||||
'entry.row' => '',
|
||||
'entry.description' => $description ?? '',
|
||||
'entry.description_safe' => ($description === null || $description === '' ? ($activity?->getName() ?? $project?->getName() ?? '') : $description),
|
||||
'entry.amount' => $amount,
|
||||
'entry.type' => $item->getType(),
|
||||
'entry.tags' => implode(', ', $item->getTags()),
|
||||
|
||||
@@ -111,7 +111,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
$result = $entries[0];
|
||||
|
||||
$this->assertEquals('2018-11-28', $result->getBegin()?->format('Y-m-d'));
|
||||
$this->assertEquals('activity description', $result->getDescription());
|
||||
$this->assertEquals('', $result->getDescription());
|
||||
$this->assertEquals(293.27, $result->getHourlyRate());
|
||||
$this->assertNull($result->getFixedRate());
|
||||
$this->assertEquals(472.5, $result->getRate());
|
||||
@@ -190,7 +190,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
|
||||
/** @var InvoiceItem $result */
|
||||
$result = $sut->getEntries()[0];
|
||||
$this->assertEquals('activity description', $result->getDescription());
|
||||
$this->assertNull($result->getDescription());
|
||||
$this->assertEquals(488.38, $result->getHourlyRate());
|
||||
$this->assertEquals(488.38, $result->getFixedRate());
|
||||
$this->assertEquals(488.38, $result->getRate());
|
||||
@@ -266,7 +266,7 @@ class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
|
||||
/** @var InvoiceItem $result */
|
||||
$result = $sut->getEntries()[0];
|
||||
$this->assertEquals('activity description', $result->getDescription());
|
||||
$this->assertNull($result->getDescription());
|
||||
$this->assertEquals(488.38, $result->getHourlyRate());
|
||||
$this->assertEquals(488.38, $result->getRate());
|
||||
$this->assertEquals(5800, $result->getDuration());
|
||||
|
||||
@@ -27,13 +27,26 @@ class InvoiceItemDefaultHydratorTest extends TestCase
|
||||
$sut = new InvoiceItemDefaultHydrator();
|
||||
$sut->setInvoiceModel($model);
|
||||
|
||||
$result = $sut->hydrate($model->getCalculator()->getEntries()[0]);
|
||||
$metaFields = ['entry.meta.foo-timesheet'];
|
||||
$this->assertEntryStructure($result, $metaFields);
|
||||
$expected = [
|
||||
['meta_fields' => ['entry.meta.foo-timesheet'], 'description' => '== jhg ljhg ', 'description_safe' => '== jhg ljhg '],
|
||||
['meta_fields' => ['entry.meta.foo-timesheet', 'entry.meta.foo-timesheet2'], 'description' => '', 'description_safe' => 'activity description'],
|
||||
['meta_fields' => ['entry.meta.foo-timesheet'], 'description' => '', 'description_safe' => 'activity description'],
|
||||
['meta_fields' => ['entry.meta.foo-timesheet3']],
|
||||
['meta_fields' => []],
|
||||
];
|
||||
|
||||
$result = $sut->hydrate($model->getCalculator()->getEntries()[1]);
|
||||
$metaFields = ['entry.meta.foo-timesheet', 'entry.meta.foo-timesheet2'];
|
||||
$this->assertEntryStructure($result, $metaFields);
|
||||
$i = 0;
|
||||
foreach ($model->getCalculator()->getEntries() as $entry) {
|
||||
$result = $sut->hydrate($entry);
|
||||
$exp = $expected[$i++];
|
||||
$this->assertEntryStructure($result, $exp['meta_fields']);
|
||||
if (\array_key_exists('description', $exp)) {
|
||||
$this->assertEquals($exp['description'], $result['entry.description']);
|
||||
}
|
||||
if (\array_key_exists('description_safe', $exp)) {
|
||||
$this->assertEquals($exp['description_safe'], $result['entry.description_safe']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function assertEntryStructure(array $model, array $metaFields): void
|
||||
@@ -41,6 +54,7 @@ class InvoiceItemDefaultHydratorTest extends TestCase
|
||||
$keys = [
|
||||
'entry.row',
|
||||
'entry.description',
|
||||
'entry.description_safe',
|
||||
'entry.amount',
|
||||
'entry.rate',
|
||||
'entry.rate_nc',
|
||||
@@ -87,7 +101,9 @@ class InvoiceItemDefaultHydratorTest extends TestCase
|
||||
'entry.tags',
|
||||
];
|
||||
|
||||
if (\count($metaFields) > 0) {
|
||||
$keys = array_merge($keys, $metaFields);
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
$this->assertArrayHasKey($key, $model);
|
||||
|
||||
@@ -262,6 +262,7 @@ class DebugRendererTest extends TestCase
|
||||
$keys = [
|
||||
'entry.row',
|
||||
'entry.description',
|
||||
'entry.description_safe',
|
||||
'entry.amount',
|
||||
'entry.rate',
|
||||
'entry.rate_nc',
|
||||
|
||||
@@ -2250,7 +2250,7 @@ parameters:
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getEntries\\(\\) on App\\\\Invoice\\\\CalculatorInterface\\|null\\.$#"
|
||||
count: 2
|
||||
count: 1
|
||||
path: Invoice/Hydrator/InvoiceItemDefaultHydratorTest.php
|
||||
|
||||
-
|
||||
|
||||
Reference in New Issue
Block a user