PROX-458: change sum in vat.builder (#7)

* PROX-458: change sum in vat.builder
This commit is contained in:
malkoas 2020-10-08 13:09:13 +03:00 committed by GitHub
parent cae9bf4d9a
commit c081fb9fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 54 additions and 15 deletions

View File

@ -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);
}

View File

@ -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<CashregContext, EntryStateModel> {
@ -78,8 +80,13 @@ public class CtxToEntryModelConverter implements Converter<CashregContext, Entry
}
private Vat prepareVat(ItemsLine itemsLine) {
com.rbkmoney.adapter.businessru.service.businessru.constant.Vat vat =
com.rbkmoney.adapter.businessru.service.businessru.constant.Vat.codeTextOf(itemsLine.getTax());
BigDecimal sum = BigDecimal.valueOf(vat.getRate())
.multiply(prepareAmount(itemsLine.getPrice().getAmount()))
.divide(BigDecimal.valueOf(vat.getRate() + 100L), 2, HALF_UP);
return Vat.builder()
.sum(prepareAmount(itemsLine.getPrice().getAmount()))
.sum(sum)
.type(itemsLine.getTax())
.build();
}

View File

@ -1,7 +1,7 @@
package com.rbkmoney.adapter.businessru.processor;
import com.rbkmoney.adapter.businessru.service.businessru.model.response.CommonResponse;
import com.rbkmoney.adapter.businessru.utils.ErrorUtils;
import com.rbkmoney.adapter.businessru.service.businessru.model.response.CommonResponse;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.AdapterState;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.EntryStateModel;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.ExitStateModel;

View File

@ -1,8 +1,8 @@
package com.rbkmoney.adapter.businessru.processor;
import com.rbkmoney.adapter.businessru.utils.ErrorUtils;
import com.rbkmoney.adapter.businessru.service.businessru.constant.Status;
import com.rbkmoney.adapter.businessru.service.businessru.model.response.CommonResponse;
import com.rbkmoney.adapter.businessru.utils.ErrorUtils;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.AdapterState;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.EntryStateModel;
import com.rbkmoney.adapter.cashreg.spring.boot.starter.model.ExitStateModel;

View File

@ -60,7 +60,7 @@ public class BusinessRuApi {
public ResponseEntity<CommonResponse> buy(RequestWrapper<CommonRequest> requestWrapper) {
return send(requestWrapper, Operations.BUY);
}
/**
* чек «Коррекция расхода»
*/

View File

@ -8,7 +8,7 @@ import lombok.Getter;
*/
@Getter
@AllArgsConstructor
public enum Operations {
public enum Operations {
// чек «Приход»
SELL("sell"),

View File

@ -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()) {

View File

@ -99,6 +99,12 @@ public abstract class IntegrationTest {
Cart cart = new Cart();
List<ItemsLine> 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);

View File

@ -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());

View File

@ -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());
}
}