Search in sources :

Example 1 with TaxRateDescription

use of com.salesmanager.shop.model.tax.TaxRateDescription 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 2 with TaxRateDescription

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

the class PersistableTaxRateMapper method taxRate.

private com.salesmanager.core.model.tax.taxrate.TaxRate taxRate(com.salesmanager.core.model.tax.taxrate.TaxRate destination, PersistableTaxRate source) throws Exception {
    if (!CollectionUtils.isEmpty(source.getDescriptions())) {
        for (TaxRateDescription desc : source.getDescriptions()) {
            com.salesmanager.core.model.tax.taxrate.TaxRateDescription description = null;
            if (!CollectionUtils.isEmpty(destination.getDescriptions())) {
                for (com.salesmanager.core.model.tax.taxrate.TaxRateDescription d : destination.getDescriptions()) {
                    if (!StringUtils.isBlank(desc.getLanguage()) && desc.getLanguage().equals(d.getLanguage().getCode())) {
                        d.setDescription(desc.getDescription());
                        d.setName(desc.getName());
                        d.setTitle(desc.getTitle());
                        description = d;
                        break;
                    }
                }
            }
            if (description == null) {
                description = description(desc);
                description.setTaxRate(destination);
                destination.getDescriptions().add(description);
            }
        }
    }
    return destination;
}
Also used : TaxRateDescription(com.salesmanager.shop.model.tax.TaxRateDescription)

Example 3 with TaxRateDescription

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

the class PersistableTaxRateMapper method description.

private com.salesmanager.core.model.tax.taxrate.TaxRateDescription description(TaxRateDescription source) throws Exception {
    Validate.notNull(source.getLanguage(), "description.language should not be null");
    com.salesmanager.core.model.tax.taxrate.TaxRateDescription desc = new com.salesmanager.core.model.tax.taxrate.TaxRateDescription();
    desc.setId(null);
    desc.setDescription(source.getDescription());
    desc.setName(source.getName());
    if (source.getId() != null && source.getId().longValue() > 0) {
        desc.setId(source.getId());
    }
    Language lang = languageService.getByCode(source.getLanguage());
    desc.setLanguage(lang);
    return desc;
}
Also used : TaxRateDescription(com.salesmanager.shop.model.tax.TaxRateDescription) Language(com.salesmanager.core.model.reference.language.Language)

Aggregations

TaxRateDescription (com.salesmanager.shop.model.tax.TaxRateDescription)3 Language (com.salesmanager.core.model.reference.language.Language)1 Entity (com.salesmanager.shop.model.entity.Entity)1 EntityExists (com.salesmanager.shop.model.entity.EntityExists)1 PersistableTaxRate (com.salesmanager.shop.model.tax.PersistableTaxRate)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