Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Taxes displayed properly on credit memo #264

Merged
Merged
5 changes: 4 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
### UPGRADE FROM 1.0.0-RC.7 TO 1.0.0-RC.8

1. The `fully_refunded` state and the `refund` transition have been removed from `sylius_order` state machine.
1. The `fully_refunded` state and the `refund` transition have been removed from `sylius_order` state machine.
2. `Sylius\RefundPlugin\Provider\LabelBasedTaxRateProvider` has been changed to `Sylius\RefundPlugin\Provider\TaxRateProvider`.
3. The method `Sylius\RefundPlugin\Provider\TaxRateProviderInterface` has been changed
from `provide(OrderItemUnitInterface $orderItemUnit): ?string` to `provide(AdjustableInterface $adjustable): ?string`.

### UPGRADE FROM 1.0.0-RC.5 TO 1.0.0-RC.6

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@refunds
Feature: Viewing details of a credit memo
Feature: Viewing details of a credit memo with taxes excluded from price
In order to be aware of what order units have been refunded
As an Administrator
I want to be able to view details of a credit memo
Expand All @@ -9,12 +9,14 @@ Feature: Viewing details of a credit memo
And channel "United States" billing data is "Haas & Milan", "Pacific Coast Hwy", "90003" "Los Angeles", "United States" with "1100110011" tax ID
And default tax zone is "US"
And the store has "US VAT" tax rate of 10% for "Clothes" within the "US" zone
And the store has included in price "VAT" tax rate of 20% for "Mugs" within the "US" zone
And the store has "Galaxy Post" shipping method with "$10.00" fee
And the store has "VAT" tax rate of 20% for "Mugs" within the "US" zone
And the store has "SHIPPING_VAT" tax rate of 15% for "Shipments" within the "US" zone
And the store has "Galaxy Post" shipping method with "$10.00" fee within the "US" zone
And shipping method "Galaxy Post" belongs to "Shipments" tax category
And the store allows paying with "Space money"
And the store has a product "PHP T-Shirt" priced at "$10.00"
And it belongs to "Clothes" tax category
And the store has a product "Symfony Mug" priced at "$21.00"
And the store has a product "Symfony Mug" priced at "$20.00"
And it belongs to "Mugs" tax category
And there is a customer "[email protected]" that placed an order "#00000022"
And the customer bought a "PHP T-Shirt" and a "Symfony Mug"
Expand All @@ -25,17 +27,21 @@ Feature: Viewing details of a credit memo

@ui @application
Scenario: Viewing details of a credit memo issued for a full refund
Given all units from the order "#00000022" are refunded with "Space money" payment
Given all units and shipment from the order "#00000022" are refunded with "Space money" payment
When I browse the details of the only credit memo generated for order "#00000022"
Then it should have sequential number generated from current date
And it should be issued in "United States" channel
And it should be issued to "Haas & Milan", "Pacific Coast Hwy", "90003" "Los Angeles" in the "United States" with "1100110011" tax ID
And it should be issued from "Rick Sanchez", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And it should contain 1 "PHP T-Shirt" product with "10.00" net value, "1.00" tax amount and "11.00" gross value in "USD" currency
And it should contain 1 "Symfony Mug" product with "17.50" net value, "3.50" tax amount and "21.00" gross value in "USD" currency
And it should contain 1 "Symfony Mug" product with "20.00" net value, "4.00" tax amount and "24.00" gross value in "USD" currency
And it should contain 1 "Galaxy Post" shipment with "10.00" net value, "1.50" tax amount and "11.50" gross value in "USD" currency
And it should contain a tax item "10%" with amount "1.00" in "USD" currency
And it should contain a tax item "20%" with amount "3.50" in "USD" currency
And its total should be "32.00" in "USD" currency
And it should contain a tax item "15%" with amount "1.50" in "USD" currency
And it should contain a tax item "20%" with amount "4.00" in "USD" currency
And its total should be "46.50" in "USD" currency
And its net total should be "40.00"
And its tax total should be "6.50"

@ui @application
Scenario: Viewing details of a credit memo issued for a partial refund
Expand All @@ -46,12 +52,16 @@ Feature: Viewing details of a credit memo
And it should contain 1 "PHP T-Shirt" product with "5.00" net value, "0.50" tax amount and "5.50" gross value in "USD" currency
And it should contain a tax item "10%" with amount "0.50" in "USD" currency
And its total should be "5.50" in "USD" currency
And its net total should be "5.00"
And its tax total should be "0.50"

@ui @application
Scenario: Viewing details of a credit memo issued for a partial shipping cost refund
Given the "#00000022" order's shipping cost already has a refund of "$4.50" with "Space money" payment
Given the "#00000022" order's shipping cost already has a refund of "$5.75" with "Space money" payment
When I browse the details of the only credit memo generated for order "#00000022"
Then it should have sequential number generated from current date
And it should contain 1 "Galaxy Post" shipment with "4.50" gross value in "USD" currency
And it should contain 1 "Galaxy Post" shipment with "5.00" net value, "0.75" tax amount and "5.75" gross value in "USD" currency
And it should be issued in "United States" channel
And its total should be "4.50" in "USD" currency
And its total should be "5.75" in "USD" currency
And its net total should be "5.00"
And its tax total should be "0.75"
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
@refunds
Feature: Viewing details of a credit memo with taxes included in price
In order to be aware of what order units have been refunded
As an Administrator
I want to be able to view details of a credit memo

Background:
Given the store operates on a single green channel in "United States"
And channel "United States" billing data is "Haas & Milan", "Pacific Coast Hwy", "90003" "Los Angeles", "United States" with "1100110011" tax ID
And default tax zone is "US"
And the store has included in price "US VAT" tax rate of 10% for "Clothes" within the "US" zone
And the store has included in price "VAT" tax rate of 20% for "Mugs" within the "US" zone
And the store has included in price "SHIPPING_VAT" tax rate of 15% for "Shipments" within the "US" zone
And the store has "Galaxy Post" shipping method with "$11.50" fee within the "US" zone
And shipping method "Galaxy Post" belongs to "Shipments" tax category
And the store allows paying with "Space money"
And the store has a product "PHP T-Shirt" priced at "$11.00"
And it belongs to "Clothes" tax category
And the store has a product "Symfony Mug" priced at "$24.00"
And it belongs to "Mugs" tax category
And there is a customer "[email protected]" that placed an order "#00000022"
And the customer bought a "PHP T-Shirt" and a "Symfony Mug"
And the customer "Rick Sanchez" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address
And the customer chose "Galaxy Post" shipping method with "Space money" payment
And the order "#00000022" is already paid
And I am logged in as an administrator

@ui @application
Scenario: Viewing details of a credit memo issued for a full refund
Given all units and shipment from the order "#00000022" are refunded with "Space money" payment
When I browse the details of the only credit memo generated for order "#00000022"
Then it should have sequential number generated from current date
And it should be issued in "United States" channel
And it should be issued to "Haas & Milan", "Pacific Coast Hwy", "90003" "Los Angeles" in the "United States" with "1100110011" tax ID
And it should be issued from "Rick Sanchez", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And it should contain 1 "PHP T-Shirt" product with "10.00" net value, "1.00" tax amount and "11.00" gross value in "USD" currency
And it should contain 1 "Symfony Mug" product with "20.00" net value, "4.00" tax amount and "24.00" gross value in "USD" currency
And it should contain 1 "Galaxy Post" shipment with "10.00" net value, "1.50" tax amount and "11.50" gross value in "USD" currency
And it should contain a tax item "10%" with amount "1.00" in "USD" currency
And it should contain a tax item "15%" with amount "1.50" in "USD" currency
And it should contain a tax item "20%" with amount "4.00" in "USD" currency
And its total should be "46.50" in "USD" currency
And its net total should be "40.00"
And its tax total should be "6.50"

@ui @application
Scenario: Viewing details of a credit memo issued for a partial refund
Given the 1st "PHP T-Shirt" product from order "#00000022" has a refund of "$5.50" with "Space money" payment
When I browse the details of the only credit memo generated for order "#00000022"
Then it should have sequential number generated from current date
And it should be issued in "United States" channel
And it should contain 1 "PHP T-Shirt" product with "5.00" net value, "0.50" tax amount and "5.50" gross value in "USD" currency
And it should contain a tax item "10%" with amount "0.50" in "USD" currency
And its total should be "5.50" in "USD" currency
And its net total should be "5.00"
And its tax total should be "0.50"

@ui @application
Scenario: Viewing details of a credit memo issued for a partial shipping cost refund
Given the "#00000022" order's shipping cost already has a refund of "$5.75" with "Space money" payment
When I browse the details of the only credit memo generated for order "#00000022"
Then it should have sequential number generated from current date
And it should contain 1 "Galaxy Post" shipment with "5.00" net value, "0.75" tax amount and "5.75" gross value in "USD" currency
And it should be issued in "United States" channel
And its total should be "5.75" in "USD" currency
And its net total should be "5.00"
And its tax total should be "0.75"
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ Feature: Viewing details of a credit memo for order with a promotion applied
And the store has "US VAT" tax rate of 10% for "Clothes" within the "US" zone
And the store has a product "PHP T-Shirt" priced at "$10.00"
And it belongs to "Clothes" tax category
And the store has "Galaxy Post" shipping method with "$10.00" fee
And the store has included in price "SHIPPING_VAT" tax rate of 15% for "Shipments" within the "US" zone
And the store has "Galaxy Post" shipping method with "$11.50" fee within the "US" zone
And shipping method "Galaxy Post" belongs to "Shipments" tax category
And the store allows paying with "Space money"
And there is a promotion "Anatomy Park Promotion"
And this promotion gives "$3.99" discount to every order with quantity at least 4
And there is a customer "[email protected]" that placed an order "#00000022"
And there is a promotion "Cheaper shipments"
And it gives "50%" discount on shipping to every order
And the customer bought 4 "PHP T-Shirt" products
And the customer "Rick Sanchez" addressed it to "Seaside Fwy", "90802" "Los Angeles" in the "United States" with identical billing address
And the customer chose "Galaxy Post" shipping method with "Space money" payment
Expand All @@ -24,13 +28,15 @@ Feature: Viewing details of a credit memo for order with a promotion applied

@ui @application
Scenario: Viewing details of a credit memo issued for an order with a promotion applied
Given all units from the order "#00000022" are refunded with "Space money" payment
Given all units and shipment from the order "#00000022" are refunded with "Space money" payment
When I browse the details of the only credit memo generated for order "#00000022"
Then it should have sequential number generated from current date
And it should be issued in "United States" channel
And it should be issued to "Haas & Milan", "Pacific Coast Hwy", "90003" "Los Angeles" in the "United States" with "1100110011" tax ID
And it should be issued from "Rick Sanchez", "Seaside Fwy", "90802" "Los Angeles" in the "United States"
And it should contain 3 "PHP T-Shirt" products with "27.00" net value, "2.70" tax amount and "29.70" gross value in "USD" currency
And it should contain 1 "PHP T-Shirt" product with "9.01" net value, "0.90" tax amount and "9.91" gross value in "USD" currency
And it should contain 1 "Galaxy Post" shipment with "5.00" net value, "0.75" tax amount and "5.75" gross value in "USD" currency
And it should contain a tax item "10%" with amount "3.60" in "USD" currency
And its total should be "39.61" in "USD" currency
And it should contain a tax item "15%" with amount "0.75" in "USD" currency
And its total should be "45.36" in "USD" currency
59 changes: 51 additions & 8 deletions spec/Converter/ShipmentLineItemsConverterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@

namespace spec\Sylius\RefundPlugin\Converter;

use Doctrine\Common\Collections\ArrayCollection;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\RefundPlugin\Converter\LineItemsConverterInterface;
use Sylius\RefundPlugin\Entity\AdjustmentInterface;
use Sylius\RefundPlugin\Entity\LineItem;
use Sylius\RefundPlugin\Entity\ShipmentInterface;
use Sylius\RefundPlugin\Exception\MoreThanOneTaxAdjustment;
use Sylius\RefundPlugin\Model\ShipmentRefund;
use Sylius\RefundPlugin\Provider\TaxRateProviderInterface;

final class ShipmentLineItemsConverterSpec extends ObjectBehavior
{
function let(RepositoryInterface $adjustmentRepository): void
function let(RepositoryInterface $adjustmentRepository, TaxRateProviderInterface $taxRateProvider): void
{
$this->beConstructedWith($adjustmentRepository);
$this->beConstructedWith($adjustmentRepository, $taxRateProvider);
}

function it_implements_line_items_converter_interface(): void
Expand All @@ -26,29 +29,38 @@ function it_implements_line_items_converter_interface(): void

function it_converts_shipment_unit_refunds_to_line_items(
RepositoryInterface $adjustmentRepository,
TaxRateProviderInterface $taxRateProvider,
AdjustmentInterface $shippingAdjustment,
AdjustmentInterface $taxAdjustment,
ShipmentInterface $shipment
): void {
$shipmentRefund = new ShipmentRefund(1, 500);
$shipmentRefund = new ShipmentRefund(1, 575);

$adjustmentRepository
->findOneBy(['id' => 1, 'type' => AdjustmentInterface::SHIPPING_ADJUSTMENT])
->willReturn($shippingAdjustment)
;

$shippingAdjustment->getLabel()->willReturn('Galaxy post');
$shippingAdjustment->getShipment()->willReturn($shipment);

$shipment->getAdjustmentsTotal()->willReturn(1000);
$shipment->getAdjustmentsTotal()->willReturn(1150);
$shipment
->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)
->willReturn(new ArrayCollection([$taxAdjustment->getWrappedObject()]))
;

$taxAdjustment->getAmount()->willReturn(150);
$taxRateProvider->provide($shipment)->willReturn('15%');

$this->convert([$shipmentRefund])->shouldBeLike([new LineItem(
'Galaxy post',
1,
500,
575,
500,
500,
500,
0
575,
75,
'15%'
)]);
}

Expand Down Expand Up @@ -88,4 +100,35 @@ function it_throws_an_exception_if_refund_amount_is_higher_than_shipping_amount(
->during('convert', [[$shipmentRefund]])
;
}

function it_throws_an_exception_if_shipment_has_more_tax_adjustments_than_one(
RepositoryInterface $adjustmentRepository,
TaxRateProviderInterface $taxRateProvider,
AdjustmentInterface $shippingAdjustment,
AdjustmentInterface $firstTaxAdjustment,
AdjustmentInterface $secondTaxAdjustment,
ShipmentInterface $shipment
): void {
$shipmentRefund = new ShipmentRefund(1, 575);

$adjustmentRepository
->findOneBy(['id' => 1, 'type' => AdjustmentInterface::SHIPPING_ADJUSTMENT])
->willReturn($shippingAdjustment)
;
$shippingAdjustment->getLabel()->willReturn('Galaxy post');
$shippingAdjustment->getShipment()->willReturn($shipment);

$shipment->getAdjustmentsTotal()->willReturn(1150);
$shipment
->getAdjustments(AdjustmentInterface::TAX_ADJUSTMENT)
->willReturn(new ArrayCollection([$firstTaxAdjustment->getWrappedObject(), $secondTaxAdjustment->getWrappedObject()]))
;

$taxRateProvider->provide($shipment)->shouldNotBeCalled();

$this
->shouldThrow(MoreThanOneTaxAdjustment::class)
->during('convert', [[$shipmentRefund]])
;
}
}
Loading