From c081fb9fa10e8f92123ef43aa2830d6a9be935c7 Mon Sep 17 00:00:00 2001 From: malkoas <41993717+malkoas@users.noreply.github.com> Date: Thu, 8 Oct 2020 13:09:13 +0300 Subject: [PATCH] PROX-458: change sum in vat.builder (#7) * PROX-458: change sum in vat.builder --- .../CashregBusinessRuApplication.java | 2 +- .../entry/CtxToEntryModelConverter.java | 9 ++++++- .../businessru/processor/ErrorProcessor.java | 2 +- .../processor/SuccessProcessor.java | 2 +- .../service/businessru/BusinessRuApi.java | 2 +- .../businessru/constant/Operations.java | 2 +- .../service/businessru/constant/Vat.java | 17 +++++++------ .../adapter/businessru/IntegrationTest.java | 6 +++++ .../adapter/businessru/MockUtils.java | 2 +- .../EntryModelConverterTest.java | 25 +++++++++++++++++++ 10 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 src/test/java/com/rbkmoney/adapter/businessru/entryconverter/EntryModelConverterTest.java diff --git a/src/main/java/com/rbkmoney/adapter/businessru/CashregBusinessRuApplication.java b/src/main/java/com/rbkmoney/adapter/businessru/CashregBusinessRuApplication.java index f7c8422..73fc466 100644 --- a/src/main/java/com/rbkmoney/adapter/businessru/CashregBusinessRuApplication.java +++ b/src/main/java/com/rbkmoney/adapter/businessru/CashregBusinessRuApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.web.servlet.ServletComponentScan; @ServletComponentScan @SpringBootApplication -public class CashregBusinessRuApplication extends SpringApplication{ +public class CashregBusinessRuApplication extends SpringApplication { public static void main(String[] args) { SpringApplication.run(CashregBusinessRuApplication.class, args); } diff --git a/src/main/java/com/rbkmoney/adapter/businessru/converter/entry/CtxToEntryModelConverter.java b/src/main/java/com/rbkmoney/adapter/businessru/converter/entry/CtxToEntryModelConverter.java index 97c004a..39ed7b7 100644 --- a/src/main/java/com/rbkmoney/adapter/businessru/converter/entry/CtxToEntryModelConverter.java +++ b/src/main/java/com/rbkmoney/adapter/businessru/converter/entry/CtxToEntryModelConverter.java @@ -22,6 +22,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static java.math.RoundingMode.HALF_UP; + @Component @RequiredArgsConstructor public class CtxToEntryModelConverter implements Converter { @@ -78,8 +80,13 @@ public class CtxToEntryModelConverter implements Converter buy(RequestWrapper requestWrapper) { return send(requestWrapper, Operations.BUY); } - + /** * чек «Коррекция расхода» */ diff --git a/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Operations.java b/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Operations.java index 9c16ec3..cbeedc0 100644 --- a/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Operations.java +++ b/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Operations.java @@ -8,7 +8,7 @@ import lombok.Getter; */ @Getter @AllArgsConstructor -public enum Operations { +public enum Operations { // чек «Приход» SELL("sell"), diff --git a/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Vat.java b/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Vat.java index c34ab18..d52e643 100644 --- a/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Vat.java +++ b/src/main/java/com/rbkmoney/adapter/businessru/service/businessru/constant/Vat.java @@ -7,18 +7,19 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public enum Vat { - VAT_0("0%", Tax.VAT0.getCode(), "0% НДС"), - VAT_10("10%", Tax.VAT10.getCode(), "10% НДС"), - VAT_18("18%", Tax.VAT18.getCode(), "18% НДС"), - VAT_20("20%", Tax.VAT20.getCode(), "20% НДС"), - NO_VAT("null", Tax.NONE.getCode(), "Без НДС"), - VAT_10_110("10/110", Tax.VAT110.getCode(), "10/110 НДС"), - VAT_18_118("18/118", Tax.VAT118.getCode(), "18/118 НДС"), - VAT_20_120("20/120", Tax.VAT120.getCode(), "20/120 НДС"); + VAT_0("0%", Tax.VAT0.getCode(), "0% НДС", 0), + VAT_10("10%", Tax.VAT10.getCode(), "10% НДС", 10), + VAT_18("18%", Tax.VAT18.getCode(), "18% НДС", 18), + VAT_20("20%", Tax.VAT20.getCode(), "20% НДС", 20), + NO_VAT("null", Tax.NONE.getCode(), "Без НДС", 0), + VAT_10_110("10/110", Tax.VAT110.getCode(), "10/110 НДС", 10), + VAT_18_118("18/118", Tax.VAT118.getCode(), "18/118 НДС", 18), + VAT_20_120("20/120", Tax.VAT120.getCode(), "20/120 НДС", 20); private final String codeText; private final String code; private final String message; + private final int rate; public static Vat codeTextOf(String codeText) { for (Vat vat : values()) { diff --git a/src/test/java/com/rbkmoney/adapter/businessru/IntegrationTest.java b/src/test/java/com/rbkmoney/adapter/businessru/IntegrationTest.java index 95eeb62..9445135 100644 --- a/src/test/java/com/rbkmoney/adapter/businessru/IntegrationTest.java +++ b/src/test/java/com/rbkmoney/adapter/businessru/IntegrationTest.java @@ -99,6 +99,12 @@ public abstract class IntegrationTest { Cart cart = new Cart(); List lines = new ArrayList<>(); + ItemsLine itemsLine = new ItemsLine(); + itemsLine.setPrice(cash); + itemsLine.setTax("18%"); + itemsLine.setQuantity(1); + itemsLine.setProduct("test"); + lines.add(itemsLine); cart.setLines(lines); paymentInfo.setCart(cart); paymentInfo.setEmail(TestData.TEST_EMAIL); diff --git a/src/test/java/com/rbkmoney/adapter/businessru/MockUtils.java b/src/test/java/com/rbkmoney/adapter/businessru/MockUtils.java index 1f6db60..49d9ca6 100644 --- a/src/test/java/com/rbkmoney/adapter/businessru/MockUtils.java +++ b/src/test/java/com/rbkmoney/adapter/businessru/MockUtils.java @@ -25,7 +25,7 @@ public class MockUtils { response.setPayload(Payload.builder() .fnNumber("fnNumber") .fiscalReceiptNumber(1L) - .build()); + .build()); response.setUuid("uuid"); return response; }).when(client).status(any()); diff --git a/src/test/java/com/rbkmoney/adapter/businessru/entryconverter/EntryModelConverterTest.java b/src/test/java/com/rbkmoney/adapter/businessru/entryconverter/EntryModelConverterTest.java new file mode 100644 index 0000000..014f0fc --- /dev/null +++ b/src/test/java/com/rbkmoney/adapter/businessru/entryconverter/EntryModelConverterTest.java @@ -0,0 +1,25 @@ +package com.rbkmoney.adapter.businessru.entryconverter; + +import com.rbkmoney.adapter.businessru.IntegrationTest; +import com.rbkmoney.adapter.businessru.converter.entry.CtxToEntryModelConverter; +import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.EntryStateModel; +import com.rbkmoney.damsel.cashreg.adapter.CashregContext; +import org.junit.Assert; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.math.BigDecimal; + +public class EntryModelConverterTest extends IntegrationTest { + + @Autowired + CtxToEntryModelConverter converter; + + @Test + public void prepareVatSumTest() { + CashregContext context = makeCashRegContext(); + EntryStateModel entryStateModel = converter.convert(context); + Assert.assertEquals(BigDecimal.valueOf(0.15), entryStateModel.getVats().get(0).getSum()); + } + +}