Search in sources :

Example 1 with PersistableTaxRate

use of com.salesmanager.shop.model.tax.PersistableTaxRate in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method createTaxRate.

@Override
public Entity createTaxRate(PersistableTaxRate taxRate, MerchantStore store, Language language) {
    Validate.notNull(taxRate, "TaxRate cannot be null");
    Validate.notNull(taxRate.getCode(), "TaxRate code cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    try {
        TaxRate model = taxRateService.getByCode(taxRate.getCode(), store);
        if (model != null) {
            throw new OperationNotAllowedException("Tax rate [" + taxRate.getCode() + "] already exist for store [" + store.getCode() + "]");
        }
        model = persistableTaxRateMapper.convert(taxRate, store, language);
        model = taxRateService.saveOrUpdate(model);
        Entity id = new Entity();
        id.setId(model.getId());
        return id;
    } catch (ServiceException e) {
        LOGGER.error("Error while saving taxRate [" + taxRate.getCode() + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while saving taxRate [" + taxRate.getCode() + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : Entity(com.salesmanager.shop.model.entity.Entity) ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 2 with PersistableTaxRate

use of com.salesmanager.shop.model.tax.PersistableTaxRate in project shopizer by shopizer-ecommerce.

the class TaxRateIntegrationTest method manageTaxRates.

@Test
public void manageTaxRates() throws Exception {
    // create tax class
    PersistableTaxRate taxRate = new PersistableTaxRate();
    taxRate.setCode("taxcode1");
    taxRate.setCountry("US");
    taxRate.setPriority(0);
    taxRate.setRate(new BigDecimal(5));
    taxRate.setStore("DEFAULT");
    taxRate.setTaxClass("DEFAULT");
    taxRate.setZone("NY");
    // descriptions
    TaxRateDescription en = new TaxRateDescription();
    en.setLanguage("en");
    en.setName("TaxCode1EN");
    en.setDescription("TaxCode1EN description");
    TaxRateDescription fr = new TaxRateDescription();
    fr.setLanguage("fr");
    fr.setName("TaxCode1FR");
    fr.setDescription("TaxCode1fr description");
    taxRate.getDescriptions().add(en);
    taxRate.getDescriptions().add(fr);
    final HttpEntity<PersistableTaxRate> taxClassEntity = new HttpEntity<>(taxRate, getHeader());
    final ResponseEntity<Entity> response = testRestTemplate.postForEntity(String.format("/api/v1/private/tax/rate/"), taxClassEntity, Entity.class);
    Entity e = response.getBody();
    assertNotNull(e.getId());
    assertTrue(e.getId() > 0);
    final HttpEntity<String> httpEntity = new HttpEntity<>(getHeader());
    // tax class exists
    final ResponseEntity<EntityExists> exists = testRestTemplate.exchange(String.format("/api/v1/private/tax/rate/unique?code=" + taxRate.getCode()), HttpMethod.GET, httpEntity, EntityExists.class);
    assertTrue(exists.getBody().isExists());
}
Also used : TaxRateDescription(com.salesmanager.shop.model.tax.TaxRateDescription) Entity(com.salesmanager.shop.model.entity.Entity) HttpEntity(org.springframework.http.HttpEntity) ResponseEntity(org.springframework.http.ResponseEntity) HttpEntity(org.springframework.http.HttpEntity) EntityExists(com.salesmanager.shop.model.entity.EntityExists) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) BigDecimal(java.math.BigDecimal) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with PersistableTaxRate

use of com.salesmanager.shop.model.tax.PersistableTaxRate in project shopizer by shopizer-ecommerce.

the class TaxFacadeImpl method updateTaxRate.

@Override
public void updateTaxRate(Long id, PersistableTaxRate taxRate, MerchantStore store, Language language) {
    Validate.notNull(taxRate, "TaxRate cannot be null");
    Validate.notNull(id, "TaxRate id cannot be null");
    Validate.notNull(store, "MerchantStore cannot be null");
    Validate.notNull(store.getCode(), "MerchantStore code cannot be null");
    TaxRate model = taxRateById(id, store, language);
    model = persistableTaxRateMapper.merge(taxRate, model, store, language);
    try {
        model = taxRateService.saveOrUpdate(model);
    } catch (ServiceException e) {
        LOGGER.error("Error while saving taxRate [" + taxRate.getCode() + "] for store [" + store.getCode() + "]", e);
        throw new ServiceRuntimeException("Error while saving taxRate [" + taxRate.getCode() + "] for store [" + store.getCode() + "]", e);
    }
}
Also used : ServiceException(com.salesmanager.core.business.exception.ServiceException) TaxRate(com.salesmanager.core.model.tax.taxrate.TaxRate) ReadableTaxRate(com.salesmanager.shop.model.tax.ReadableTaxRate) PersistableTaxRate(com.salesmanager.shop.model.tax.PersistableTaxRate) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

PersistableTaxRate (com.salesmanager.shop.model.tax.PersistableTaxRate)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 TaxRate (com.salesmanager.core.model.tax.taxrate.TaxRate)2 Entity (com.salesmanager.shop.model.entity.Entity)2 ReadableTaxRate (com.salesmanager.shop.model.tax.ReadableTaxRate)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 EntityExists (com.salesmanager.shop.model.entity.EntityExists)1 TaxRateDescription (com.salesmanager.shop.model.tax.TaxRateDescription)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 BigDecimal (java.math.BigDecimal)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 HttpEntity (org.springframework.http.HttpEntity)1 ResponseEntity (org.springframework.http.ResponseEntity)1