Compare commits

...

3 commits

Author SHA1 Message Date
Jan Böhmer
e5231e29f2 Allow to set a global default if new orderdetails should contain VAT or not
Some checks are pending
Build assets artifact / Build assets artifact (push) Waiting to run
Docker Image Build / docker (push) Waiting to run
Docker Image Build (FrankenPHP) / docker (push) Waiting to run
Static analysis / Static analysis (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, mysql) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, postgres) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.2, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.3, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.4, sqlite) (push) Waiting to run
PHPUnit Tests / PHPUnit and coverage Test (PHP 8.5, sqlite) (push) Waiting to run
2026-02-10 17:13:54 +01:00
Jan Böhmer
8ac8743792 Fixed phpunit tests 2026-02-10 16:54:13 +01:00
Jan Böhmer
586375d921 Moved VAT include info from pricedetail to orderdetail level
That makes implementing the form easier
2026-02-10 16:53:41 +01:00
15 changed files with 132 additions and 128 deletions

View file

@ -22,7 +22,7 @@ final class Version20260208131116 extends AbstractMultiPlatformMigration
$this->addSql('ALTER TABLE part_lots ADD last_stocktake_at DATETIME DEFAULT NULL');
$this->addSql('ALTER TABLE parts ADD gtin VARCHAR(255) DEFAULT NULL');
$this->addSql('CREATE INDEX parts_idx_gtin ON parts (gtin)');
$this->addSql('ALTER TABLE pricedetails ADD include_vat TINYINT DEFAULT NULL');
$this->addSql('ALTER TABLE orderdetails ADD prices_includes_vat TINYINT DEFAULT NULL');
}
public function mySQLDown(Schema $schema): void
@ -32,7 +32,7 @@ final class Version20260208131116 extends AbstractMultiPlatformMigration
$this->addSql('DROP INDEX parts_idx_gtin ON `parts`');
$this->addSql('ALTER TABLE `parts` DROP gtin');
$this->addSql('ALTER TABLE part_lots DROP last_stocktake_at');
$this->addSql('ALTER TABLE `pricedetails` DROP include_vat');
$this->addSql('ALTER TABLE `orderdetails` DROP prices_includes_vat');
}
public function sqLiteUp(Schema $schema): void
@ -57,7 +57,7 @@ final class Version20260208131116 extends AbstractMultiPlatformMigration
$this->addSql('CREATE INDEX IDX_6940A7FE1ECB93AE ON parts (id_manufacturer)');
$this->addSql('CREATE INDEX IDX_6940A7FEA3ED1215 ON parts (id_part_custom_state)');
$this->addSql('CREATE INDEX parts_idx_gtin ON parts (gtin)');
$this->addSql('ALTER TABLE pricedetails ADD COLUMN include_vat BOOLEAN DEFAULT NULL');
$this->addSql('ALTER TABLE orderdetails ADD COLUMN prices_includes_vat BOOLEAN DEFAULT NULL');
}
public function sqLiteDown(Schema $schema): void
@ -99,15 +99,14 @@ final class Version20260208131116 extends AbstractMultiPlatformMigration
$this->addSql('CREATE INDEX parts_idx_datet_name_last_id_needs ON "parts" (datetime_added, name, last_modified, id, needs_review)');
$this->addSql('CREATE INDEX parts_idx_name ON "parts" (name)');
$this->addSql('CREATE INDEX parts_idx_ipn ON "parts" (ipn)');
$this->addSql('CREATE TEMPORARY TABLE __temp__pricedetails AS SELECT id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added, id_currency, orderdetails_id FROM "pricedetails"');
$this->addSql('DROP TABLE "pricedetails"');
$this->addSql('CREATE TABLE "pricedetails" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, price NUMERIC(11, 5) NOT NULL, price_related_quantity DOUBLE PRECISION NOT NULL, min_discount_quantity DOUBLE PRECISION NOT NULL, manual_input BOOLEAN NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, id_currency INTEGER DEFAULT NULL, orderdetails_id INTEGER NOT NULL, CONSTRAINT FK_C68C4459398D64AA FOREIGN KEY (id_currency) REFERENCES currencies (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_C68C44594A01DDC7 FOREIGN KEY (orderdetails_id) REFERENCES "orderdetails" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO "pricedetails" (id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added, id_currency, orderdetails_id) SELECT id, price, price_related_quantity, min_discount_quantity, manual_input, last_modified, datetime_added, id_currency, orderdetails_id FROM __temp__pricedetails');
$this->addSql('DROP TABLE __temp__pricedetails');
$this->addSql('CREATE INDEX IDX_C68C4459398D64AA ON "pricedetails" (id_currency)');
$this->addSql('CREATE INDEX IDX_C68C44594A01DDC7 ON "pricedetails" (orderdetails_id)');
$this->addSql('CREATE INDEX pricedetails_idx_min_discount ON "pricedetails" (min_discount_quantity)');
$this->addSql('CREATE INDEX pricedetails_idx_min_discount_price_qty ON "pricedetails" (min_discount_quantity, price_related_quantity)');
$this->addSql('CREATE TEMPORARY TABLE __temp__orderdetails AS SELECT id, supplierpartnr, obsolete, supplier_product_url, last_modified, datetime_added, part_id, id_supplier FROM "orderdetails"');
$this->addSql('DROP TABLE "orderdetails"');
$this->addSql('CREATE TABLE "orderdetails" (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, supplierpartnr VARCHAR(255) NOT NULL, obsolete BOOLEAN NOT NULL, supplier_product_url CLOB NOT NULL, last_modified DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, datetime_added DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, part_id INTEGER NOT NULL, id_supplier INTEGER DEFAULT NULL, CONSTRAINT FK_489AFCDC4CE34BEC FOREIGN KEY (part_id) REFERENCES "parts" (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_489AFCDCCBF180EB FOREIGN KEY (id_supplier) REFERENCES "suppliers" (id) NOT DEFERRABLE INITIALLY IMMEDIATE)');
$this->addSql('INSERT INTO "orderdetails" (id, supplierpartnr, obsolete, supplier_product_url, last_modified, datetime_added, part_id, id_supplier) SELECT id, supplierpartnr, obsolete, supplier_product_url, last_modified, datetime_added, part_id, id_supplier FROM __temp__orderdetails');
$this->addSql('DROP TABLE __temp__orderdetails');
$this->addSql('CREATE INDEX IDX_489AFCDC4CE34BEC ON "orderdetails" (part_id)');
$this->addSql('CREATE INDEX IDX_489AFCDCCBF180EB ON "orderdetails" (id_supplier)');
$this->addSql('CREATE INDEX orderdetails_supplier_part_nr ON "orderdetails" (supplierpartnr)');
}
public function postgreSQLUp(Schema $schema): void
@ -116,7 +115,7 @@ final class Version20260208131116 extends AbstractMultiPlatformMigration
$this->addSql('ALTER TABLE part_lots ADD last_stocktake_at TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL');
$this->addSql('ALTER TABLE parts ADD gtin VARCHAR(255) DEFAULT NULL');
$this->addSql('CREATE INDEX parts_idx_gtin ON parts (gtin)');
$this->addSql('ALTER TABLE pricedetails ADD include_vat BOOLEAN DEFAULT NULL');
$this->addSql('ALTER TABLE orderdetails ADD prices_includes_vat BOOLEAN DEFAULT NULL');
}
public function postgreSQLDown(Schema $schema): void
@ -125,6 +124,6 @@ final class Version20260208131116 extends AbstractMultiPlatformMigration
$this->addSql('ALTER TABLE part_lots DROP last_stocktake_at');
$this->addSql('DROP INDEX parts_idx_gtin');
$this->addSql('ALTER TABLE "parts" DROP gtin');
$this->addSql('ALTER TABLE "pricedetails" DROP include_vat');
$this->addSql('ALTER TABLE "orderdetails" DROP prices_includes_vat');
}
}

View file

@ -148,6 +148,13 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
#[ORM\JoinColumn(name: 'id_supplier')]
protected ?Supplier $supplier = null;
/**
* @var bool|null Whether the prices includes VAT or not. Null means, that it is not specified, if the prices includes VAT or not.
*/
#[ORM\Column(type: Types::BOOLEAN, nullable: true)]
#[Groups(['extended', 'full', 'import', 'orderdetail:read', 'orderdetail:write'])]
protected ?bool $prices_includes_vat = null;
public function __construct()
{
$this->pricedetails = new ArrayCollection();
@ -390,45 +397,23 @@ class Orderdetail extends AbstractDBElement implements TimeStampableInterface, N
}
/**
* Checks if the prices of this orderdetail include VAT. This is determined by checking the pricedetails of this
* orderdetail. If there are no pricedetails or if the pricedetails have conflicting values, null is returned.
* Checks if the prices of this orderdetail include VAT. Null means, that it is not specified, if the prices includes
* VAT or not.
* @return bool|null
*/
#[Groups(['orderdetail:read'])]
#[SerializedName('prices_include_vat')]
public function getPricesIncludesVAT(): ?bool
{
$value = null;
//We determine that via the pricedetails
foreach ($this->getPricedetails() as $pricedetail) {
/** @var Pricedetail $pricedetail */
if ($pricedetail->getIncludesVat() === null) {
return null; // If any pricedetail doesn't specify this, we can't determine it
}
if ($value === null) {
$value = $pricedetail->getIncludesVat(); // Set initial value
} elseif ($value !== $pricedetail->getIncludesVat()) {
return null; // If there are conflicting values, we can't determine it
}
}
return $value;
return $this->prices_includes_vat;
}
/**
* Sets whether the prices of this orderdetail include VAT. This is set for all pricedetails of this orderdetail.
* Sets whether the prices of this orderdetail include VAT.
* @param bool|null $includesVat
* @return $this
*/
#[Groups(['orderdetail:write'])]
#[SerializedName('prices_include_vat')]
public function setPricesIncludesVAT(?bool $includesVat): self
{
foreach ($this->getPricedetails() as $pricedetail) {
/** @var Pricedetail $pricedetail */
$pricedetail->setIncludesVat($includesVat);
}
$this->prices_includes_vat = $includesVat;
return $this;
}

View file

@ -121,12 +121,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
#[Groups(['pricedetail:read:standalone', 'pricedetail:write'])]
protected ?Orderdetail $orderdetail = null;
/**
* @var bool|null Whether the price includes VAT or not. Null means, that it is not specified, if the price includes VAT or not.
*/
#[ORM\Column(name: "include_vat", type: Types::BOOLEAN, nullable: true)]
#[Groups(['extended', 'full', 'import', 'pricedetail:read', 'pricedetail:write'])]
protected ?bool $includes_vat = null;
public function __construct()
{
@ -277,7 +272,7 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
*/
public function getIncludesVat(): ?bool
{
return $this->includes_vat;
return $this->orderdetail?->getPricesIncludesVAT();
}
/********************************************************************************
@ -376,15 +371,4 @@ class Pricedetail extends AbstractDBElement implements TimeStampableInterface
return $this;
}
/**
* Set whether the price includes VAT or not. Null means, that it is not specified, if the price includes VAT or not.
* @param bool|null $includes_vat
* @return $this
*/
public function setIncludesVat(?bool $includes_vat): self
{
$this->includes_vat = $includes_vat;
return $this;
}
}

View file

@ -43,6 +43,7 @@ use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\LogSystem\EventCommentNeededHelper;
use App\Services\LogSystem\EventCommentType;
use App\Settings\MiscSettings\IpnSuggestSettings;
use App\Settings\SystemSettings\LocalizationSettings;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
@ -63,6 +64,7 @@ class PartBaseType extends AbstractType
protected UrlGeneratorInterface $urlGenerator,
protected EventCommentNeededHelper $event_comment_needed_helper,
protected IpnSuggestSettings $ipnSuggestSettings,
private readonly LocalizationSettings $localizationSettings,
) {
}
@ -267,6 +269,9 @@ class PartBaseType extends AbstractType
'entity' => $part,
]);
$orderdetailPrototype = new Orderdetail();
$orderdetailPrototype->setPricesIncludesVAT($this->localizationSettings->pricesIncludeTaxByDefault);
//Orderdetails section
$builder->add('orderdetails', CollectionType::class, [
'entry_type' => OrderdetailType::class,
@ -275,7 +280,7 @@ class PartBaseType extends AbstractType
'allow_delete' => true,
'label' => false,
'by_reference' => false,
'prototype_data' => new Orderdetail(),
'prototype_data' => $orderdetailPrototype,
'entry_options' => [
'measurement_unit' => $part->getPartUnit(),
],

View file

@ -39,7 +39,9 @@ readonly class PriceDTO
public string $price,
/** @var string The currency of the used ISO code of this price detail */
public ?string $currency_iso_code,
/** @var bool If the price includes tax */
/** @var bool If the price includes tax
* @deprecated Use the prices_include_vat property of the PurchaseInfoDTO instead, as this property is not reliable if there are multiple prices with different values for includes_tax
*/
public ?bool $includes_tax = true,
/** @var float the price related quantity */
public ?float $price_related_quantity = 1.0,

View file

@ -29,6 +29,9 @@ namespace App\Services\InfoProviderSystem\DTOs;
*/
readonly class PurchaseInfoDTO
{
/** @var bool|null If the prices contain VAT or not. Null if state is unknown. */
public ?bool $prices_include_vat;
public function __construct(
public string $distributor_name,
public string $order_number,
@ -36,6 +39,7 @@ readonly class PurchaseInfoDTO
public array $prices,
/** @var string|null An url to the product page of the vendor */
public ?string $product_url = null,
?bool $prices_include_vat = null,
)
{
//Ensure that the prices are PriceDTO instances
@ -44,5 +48,17 @@ readonly class PurchaseInfoDTO
throw new \InvalidArgumentException('The prices array must only contain PriceDTO instances');
}
}
//If no prices_include_vat information is given, try to deduct it from the prices
if ($prices_include_vat === null) {
$vatValues = array_unique(array_map(fn(PriceDTO $price) => $price->includes_tax, $this->prices));
if (count($vatValues) === 1) {
$this->prices_include_vat = $vatValues[0]; //Use the value of the prices if they are all the same
} else {
$this->prices_include_vat = null; //If there are different values for the prices, we cannot determine if the prices include VAT or not
}
} else {
$this->prices_include_vat = $prices_include_vat;
}
}
}

View file

@ -100,8 +100,6 @@ final class DTOtoEntityConverter
$entity->setCurrency(null);
}
$entity->setIncludesVat($dto->includes_tax);
return $entity;
}
@ -118,6 +116,8 @@ final class DTOtoEntityConverter
$entity->addPricedetail($this->convertPrice($price));
}
$entity->setPricesIncludesVAT($dto->prices_include_vat);
return $entity;
}

View file

@ -25,6 +25,7 @@ namespace App\Settings\SystemSettings;
use App\Form\Settings\LanguageMenuEntriesType;
use App\Form\Type\LocaleSelectType;
use App\Form\Type\TriStateCheckboxType;
use App\Settings\SettingsIcon;
use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
use Jbtronics\SettingsBundle\ParameterTypes\ArrayType;
@ -46,7 +47,7 @@ class LocalizationSettings
#[Assert\Locale()]
#[Assert\NotBlank()]
#[SettingsParameter(label: new TM("settings.system.localization.locale"), formType: LocaleSelectType::class,
envVar: "string:DEFAULT_LANG", envVarMode: EnvVarMode::OVERWRITE)]
envVar: "string:DEFAULT_LANG", envVarMode: EnvVarMode::OVERWRITE)]
public string $locale = 'en';
#[Assert\Timezone()]
@ -73,4 +74,14 @@ class LocalizationSettings
)]
#[Assert\All([new Assert\Locale()])]
public array $languageMenuEntries = [];
#[SettingsParameter(label: new TM("settings.system.localization.prices_include_tax_by_default"),
description: new TM("settings.system.localization.prices_include_tax_by_default.description"),
formType: TriStateCheckboxType::class
)]
/**
* Indicates whether prices should include tax by default. This is used when creating new pricedetails.
* Null means that the VAT state should be indetermine by default.
*/
public ?bool $pricesIncludeTaxByDefault = null;
}

View file

@ -100,6 +100,17 @@
{%- endif -%}
{%- endblock tristate_widget %}
{% block tristate_row -%}
<div{% with {attr: row_attr|merge({class: (row_attr.class|default('mb-3') ~ ' row')|trim})} %}{{ block('attributes') }}{% endwith %}>{#--#}
<div class="{{ block('form_label_class') }}"></div>{#--#}
<div class="{{ block('form_group_class') }}">
{{- form_widget(form) -}}
{{- form_help(form) -}}
{{- form_errors(form) -}}
</div>{#--#}
</div>
{%- endblock tristate_row %}
{%- block choice_widget_collapsed -%}
{# Only add the BS5 form-select class if we dont use bootstrap-selectpicker #}
{# {% if attr["data-controller"] is defined and attr["data-controller"] not in ["elements--selectpicker"] %}

View file

@ -32,7 +32,7 @@
{{ form_row(form.supplierpartnr, {'attr': {'class': 'form-control-sm'}}) }}
{{ form_row(form.supplier_product_url, {'attr': {'class': 'form-control-sm'}}) }}
{{ form_widget(form.obsolete) }}
{{ form_row(form.pricesIncludesVAT) }}
{{ form_widget(form.pricesIncludesVAT) }}
</td>
<td>
<div {{ collection.controller(form.pricedetails, 'pricedetails.edit.delete.confirm') }}>

View file

@ -62,76 +62,17 @@ class OrderdetailTest extends TestCase
$this->assertSame($price5, $orderdetail->findPriceForQty(10000));
}
public function testGetPricesIncludesVAT(): void
public function testGetSetPricesIncludesVAT(): void
{
$orderdetail = new Orderdetail();
//By default, the pricesIncludesVAT property should be null for empty orderdetails
$this->assertNull($orderdetail->getPricesIncludesVAT());
$price0 = (new Pricedetail())->setMinDiscountQuantity(0.23);
$price1 = (new Pricedetail())->setMinDiscountQuantity(1);
$price5 = (new Pricedetail())->setMinDiscountQuantity(5.3);
$orderdetail->addPricedetail($price0)->addPricedetail($price1)->addPricedetail($price5);
//With empty pricedetails, the pricesIncludesVAT property should still be null
$this->assertNull($orderdetail->getPricesIncludesVAT());
//If all of the pricedetails have the same value for includesVAT, the pricesIncludesVAT property should return this value
$price0->setIncludesVAT(true);
$price1->setIncludesVAT(true);
$price5->setIncludesVAT(true);
$this->assertTrue($orderdetail->getPricesIncludesVAT());
$price0->setIncludesVAT(false);
$price1->setIncludesVAT(false);
$price5->setIncludesVAT(false);
$this->assertFalse($orderdetail->getPricesIncludesVAT());
//If the pricedetails have different values for includesVAT, the pricesIncludesVAT property should return null
$price0->setIncludesVAT(true);
$price1->setIncludesVAT(false);
$price5->setIncludesVAT(true);
$this->assertNull($orderdetail->getPricesIncludesVAT());
//If the pricedetails have different values for includesVAT, the pricesIncludesVAT property should return null, even if one of them is null
$price0->setIncludesVAT(null);
$price1->setIncludesVAT(false);
$price5->setIncludesVAT(false);
$this->assertNull($orderdetail->getPricesIncludesVAT());
}
public function testSetPricesIncludesVAT(): void
{
$orderdetail = new Orderdetail();
$price0 = (new Pricedetail())->setMinDiscountQuantity(0.23);
$price1 = (new Pricedetail())->setMinDiscountQuantity(1);
$price5 = (new Pricedetail())->setMinDiscountQuantity(5.3);
$orderdetail->addPricedetail($price0)->addPricedetail($price1)->addPricedetail($price5);
$this->assertNull($orderdetail->getPricesIncludesVAT());
$orderdetail->setPricesIncludesVAT(true);
$this->assertTrue($orderdetail->getPricesIncludesVAT());
//Ensure that the pricesIncludesVAT property is correctly propagated to the pricedetails
foreach ($orderdetail->getPricedetails() as $pricedetail) {
$this->assertTrue($pricedetail->getIncludesVAT());
}
$orderdetail->setPricesIncludesVAT(false);
$this->assertFalse($orderdetail->getPricesIncludesVAT());
//Ensure that the pricesIncludesVAT property is correctly propagated to the pricedetails
foreach ($orderdetail->getPricedetails() as $pricedetail) {
$this->assertFalse($pricedetail->getIncludesVAT());
}
$orderdetail->setPricesIncludesVAT(null);
$this->assertNull($orderdetail->getPricesIncludesVAT());
//Ensure that the pricesIncludesVAT property is correctly propagated to the pricedetails
foreach ($orderdetail->getPricedetails() as $pricedetail) {
$this->assertNull($pricedetail->getIncludesVAT());
}
}
}

View file

@ -108,6 +108,7 @@ class BulkSearchResponseDTOTest extends KernelTestCase
'manufacturing_status' => NULL,
'provider_url' => NULL,
'footprint' => NULL,
'gtin' => NULL,
),
'source_field' => 'mpn',
'source_keyword' => '1234',
@ -129,6 +130,7 @@ class BulkSearchResponseDTOTest extends KernelTestCase
'manufacturing_status' => NULL,
'provider_url' => NULL,
'footprint' => NULL,
'gtin' => NULL,
),
'source_field' => 'name',
'source_keyword' => '1234',

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
*/
namespace App\Tests\Services\InfoProviderSystem\DTOs;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use PHPUnit\Framework\TestCase;
@ -33,4 +34,40 @@ class PurchaseInfoDTOTest extends TestCase
$this->expectExceptionMessage('The prices array must only contain PriceDTO instances');
new PurchaseInfoDTO('test', 'test', [new \stdClass()]);
}
public function testPricesIncludesVATHandling(): void
{
$pricesTrue = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: true),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: true),
];
$pricesFalse = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: false),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: false),
];
$pricesMixed = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: true),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: false),
];
$pricesNull = [
new PriceDTO(minimum_discount_amount: 1, price: '10.00', currency_iso_code: 'USD', includes_tax: null),
new PriceDTO(minimum_discount_amount: 5, price: '9.00', currency_iso_code: 'USD', includes_tax: null),
];
//If the prices_include_vat parameter is given, use it:
$dto = new PurchaseInfoDTO('test', 'test', $pricesMixed, prices_include_vat: true);
$this->assertTrue($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesMixed, prices_include_vat: false);
$this->assertFalse($dto->prices_include_vat);
//If the prices_include_vat parameter is not given, try to deduct it from the prices:
$dto = new PurchaseInfoDTO('test', 'test', $pricesTrue);
$this->assertTrue($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesFalse);
$this->assertFalse($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesMixed);
$this->assertNull($dto->prices_include_vat);
$dto = new PurchaseInfoDTO('test', 'test', $pricesNull);
$this->assertNull($dto->prices_include_vat);
}
}

View file

@ -94,15 +94,12 @@ class DTOtoEntityConverterTest extends WebTestCase
minimum_discount_amount: 5,
price: "10.0",
currency_iso_code: 'EUR',
includes_tax: true,
);
$entity = $this->service->convertPrice($dto);
//For base currencies, the currency field is null
$this->assertNull($entity->getCurrency());
$this->assertTrue($entity->getIncludesVat());
}
public function testConvertPurchaseInfo(): void
@ -117,6 +114,7 @@ class DTOtoEntityConverterTest extends WebTestCase
order_number: 'TestOrderNumber',
prices: $prices,
product_url: 'https://example.com',
prices_include_vat: true,
);
$entity = $this->service->convertPurchaseInfo($dto);
@ -124,6 +122,7 @@ class DTOtoEntityConverterTest extends WebTestCase
$this->assertSame($dto->distributor_name, $entity->getSupplier()->getName());
$this->assertSame($dto->order_number, $entity->getSupplierPartNr());
$this->assertEquals($dto->product_url, $entity->getSupplierProductUrl());
$this->assertTrue($dto->prices_include_vat);
}
public function testConvertFileWithName(): void

View file

@ -12455,5 +12455,17 @@ Buerklin-API Authentication server:
<target>Excl. VAT</target>
</segment>
</unit>
<unit id="WDJ7EeF" name="settings.system.localization.prices_include_tax_by_default">
<segment>
<source>settings.system.localization.prices_include_tax_by_default</source>
<target>Prices include VAT by default</target>
</segment>
</unit>
<unit id="01oGY_r" name="settings.system.localization.prices_include_tax_by_default.description">
<segment>
<source>settings.system.localization.prices_include_tax_by_default.description</source>
<target>The default value for newly created purchase infos, if prices include VAT or not.</target>
</segment>
</unit>
</file>
</xliff>