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