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

[CreditMemo] Rework credit memo #179

Merged
merged 6 commits into from
Jan 30, 2020

Conversation

GSadee
Copy link
Member

@GSadee GSadee commented Jan 23, 2020

image

Zrzut ekranu 2020-01-25 o 20 20 49

@GSadee GSadee added the Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.). label Jan 23, 2020
@GSadee GSadee requested a review from a team as a code owner January 23, 2020 07:55
features/seeing_details_of_credit_memo.feature Outdated Show resolved Hide resolved
features/seeing_details_of_credit_memo.feature Outdated Show resolved Hide resolved
features/seeing_details_of_credit_memo.feature Outdated Show resolved Hide resolved
features/seeing_details_of_credit_memo.feature Outdated Show resolved Hide resolved
features/seeing_details_of_credit_memo.feature Outdated Show resolved Hide resolved
features/seeing_details_of_credit_memo.feature Outdated Show resolved Hide resolved
features/seeing_details_of_credit_memo.feature Outdated Show resolved Hide resolved
@GSadee GSadee force-pushed the rework-credit-memo-template branch from f92af2c to 3eccda5 Compare January 27, 2020 08:27
@GSadee GSadee changed the title [WIP][CreditMemo] Rework credit memo [CreditMemo] Rework credit memo Jan 27, 2020
@GSadee GSadee force-pushed the rework-credit-memo-template branch 2 times, most recently from 05d57f7 to 45c0c62 Compare January 27, 2020 08:57
@GSadee GSadee force-pushed the rework-credit-memo-template branch from 45c0c62 to e6c7706 Compare January 27, 2020 09:06
@GSadee GSadee force-pushed the rework-credit-memo-template branch from b9a6f57 to 981220d Compare January 27, 2020 12:21
@CoderMaggie CoderMaggie self-requested a review January 27, 2020 14:36
features/having_credit_memo_generated.feature Show resolved Hide resolved

$label = $taxAdjustments->first()->getLabel();

if (preg_match('#\((.*?)\)#', $label, $matches)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o.O What has happened here?

I don't have an idea what we try to achieve here.

Copy link
Member Author

@GSadee GSadee Jan 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the simplest way to get tax rate from tax adjustment, as it is set in tax rate label, I was wondering if it is ok for now 😃

CreditMemoUnitGeneratorInterface $orderItemUnitCreditMemoUnitGenerator,
CreditMemoUnitGeneratorInterface $shipmentCreditMemoUnitGenerator,
LineItemsConverterInterface $lineItemsConverter,
LineItemsConverterInterface $shipmentLineItemsConverter,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the order of these services is important, I would recommend creating two interfaces instead of one. Otherwise, errors may be really misleading (when units would be passed to shipmentLineItemsConvertera and shipments to lineItemsConverter)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced to that, the input and output are the same and having the same interface is logical to me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the best would be the queue with priorities accepting only array of specific units 💃 But I would leave it as it is right now

src/Resources/config/doctrine/CreditMemo.orm.xml Outdated Show resolved Hide resolved
<td>{{ loop.index }}</td>
<td>{{ item.name }}</td>
<td>{{ item.quantity }}</td>
<td>{{ (item.unitNetPrice/100)|number_format(2) }}</td>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't you used sylius_format_money?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I want to have prices without currency 😢

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the other question - why we want here prices without currency? 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because credit memo should look like this 😃 /cc @CoderMaggie

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed by PO 👩‍⚖

tests/Behat/Context/Transform/PriceContext.php Outdated Show resolved Hide resolved
UPGRADE.md Outdated Show resolved Hide resolved
UPGRADE.md Outdated Show resolved Hide resolved
$this->addSql('CREATE TABLE sylius_refund_line_item (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, quantity INT NOT NULL, unit_net_price INT NOT NULL, unit_gross_price INT NOT NULL, net_value INT NOT NULL, gross_value INT NOT NULL, tax_amount INT NOT NULL, tax_rate VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET UTF8 COLLATE `UTF8_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE sylius_refund_credit_memo_line_items ADD CONSTRAINT FK_1453B90E8E574316 FOREIGN KEY (credit_memo_id) REFERENCES sylius_refund_credit_memo (id)');
$this->addSql('ALTER TABLE sylius_refund_credit_memo_line_items ADD CONSTRAINT FK_1453B90EA7CBD339 FOREIGN KEY (line_item_id) REFERENCES sylius_refund_line_item (id)');
$this->addSql('ALTER TABLE sylius_refund_credit_memo DROP units');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we migrate those units to line items?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO no, because I do not have enough information and also the old credit memos shouldn't be changed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They'll be changed after we drop this column though

src/Converter/LineItemsConverterInterface.php Outdated Show resolved Hide resolved
src/Converter/LineItemsConverterInterface.php Outdated Show resolved Hide resolved
src/Converter/LineItemsConverter.php Outdated Show resolved Hide resolved
src/Entity/LineItem.php Show resolved Hide resolved
src/Generator/TaxItemsGeneratorInterface.php Outdated Show resolved Hide resolved
src/Resources/views/Download/creditMemo.html.twig Outdated Show resolved Hide resolved
tests/Behat/Context/Transform/PriceContext.php Outdated Show resolved Hide resolved
features/refunding_part_of_order_unit.feature Outdated Show resolved Hide resolved
@GSadee GSadee force-pushed the rework-credit-memo-template branch from 598c940 to ee91d19 Compare January 29, 2020 09:10
spec/Entity/CreditMemoSpec.php Outdated Show resolved Hide resolved

$grossValue = $unitRefund->total();
$taxAmount = (int) ($grossValue * $orderItemUnit->getTaxTotal() / $orderItemUnit->getTotal());
$netValue = $grossValue - $taxAmount;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel that there is a lot of things we could extract there - even if they're done only there, it still does not seem nice 😢 Maybe we could have some VO like CreditMemoValues which would calculate these variables? Or some LineItemFactory? It's not a must-have, for now, for me, but would definitely improve a DX 🖖

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I've extracted creating line item to the separate private method, but I agree that in future some refactor could improve a DX

src/Converter/LineItemsConverterInterface.php Outdated Show resolved Hide resolved
src/Entity/LineItem.php Outdated Show resolved Hide resolved
src/Entity/LineItem.php Outdated Show resolved Hide resolved
CreditMemoUnitGeneratorInterface $orderItemUnitCreditMemoUnitGenerator,
CreditMemoUnitGeneratorInterface $shipmentCreditMemoUnitGenerator,
LineItemsConverterInterface $lineItemsConverter,
LineItemsConverterInterface $shipmentLineItemsConverter,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the best would be the queue with priorities accepting only array of specific units 💃 But I would leave it as it is right now

src/Converter/LineItemsConverter.php Show resolved Hide resolved
@GSadee GSadee force-pushed the rework-credit-memo-template branch 4 times, most recently from f9869ef to b7a1869 Compare January 29, 2020 14:45
@GSadee GSadee force-pushed the rework-credit-memo-template branch from b7a1869 to f62c77d Compare January 29, 2020 14:52

$label = $taxAdjustments->first()->getLabel();

if (preg_match('/\((.*?)\)/', $label, $matches)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely think how to handle it better (either here on on Sylius/Sylius) but let's just open an issue for that :)

@pamil pamil merged commit 757c53f into Sylius:master Jan 30, 2020
@pamil
Copy link
Contributor

pamil commented Jan 30, 2020

Thanks, Grzegorz! 🎉

@GSadee GSadee deleted the rework-credit-memo-template branch January 30, 2020 12:57
Zales0123 added a commit that referenced this pull request Jan 31, 2020
…adee)

This PR was merged into the 1.0-dev branch.

Discussion
----------

After #179 

Commits
-------

146c371 Extract tax rate provider from line items converter
6af2b26 Fixes for tax rate provider after PR review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants