Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,14 @@ protected String getItemTotalAllowanceChargeStr(IZUGFeRDAllowanceCharge allowanc
return itemTotalAllowanceChargeStr;
}

protected TransactionCalculator createCalculator(IExportableTransaction trans) {
return new TransactionCalculator(trans);
}

@Override
public void generateXML(IExportableTransaction trans) {
this.trans = trans;
this.calc = new TransactionCalculator(trans);
this.calc = createCalculator(trans);

boolean hasDueDate = trans.getDueDate() != null;
final SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.mustangproject.ZUGFeRD;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import java.util.Date;

import org.junit.jupiter.api.Test;
import org.mustangproject.Invoice;
import org.mustangproject.Item;
import org.mustangproject.Product;
import org.mustangproject.TradeParty;

public class ZUGFeRD2PullProviderFactoryTest {

static class TestTransactionCalculator extends TransactionCalculator {

private boolean called = false;

public TestTransactionCalculator(IExportableTransaction trans) {
super(trans);
}

@Override
public BigDecimal getGrandTotal() {
called = true;
return BigDecimal.valueOf(999.99);
}

public boolean wasCalled() {
return called;
}
}

static class TestPullProvider extends ZUGFeRD2PullProvider {

private TestTransactionCalculator calculator;

@Override
protected TransactionCalculator createCalculator(IExportableTransaction trans) {
calculator = new TestTransactionCalculator(trans);
return calculator;
}

public TestTransactionCalculator getCalculator() {
return calculator;
}
}

@Test
void customCalculatorIsUsed() throws Exception {

TradeParty buyer = new TradeParty("Client X", "3 rue C", "33000", "Bordeaux", "FR");
TradeParty seller = new TradeParty("Mairie A", "1 rue A", "75001", "Paris", "FR");

Invoice invoice = new Invoice().setNumber("INV-CALC-001").setIssueDate(new Date()).setDeliveryDate(new Date())
.setDueDate(new Date()).setCurrency("EUR").setSender(buyer).setRecipient(seller);

Product service = new Product("Prestation", "Service intercommunal", "C62", new BigDecimal("20.00"));

invoice.addItem(new Item(service, BigDecimal.ONE, BigDecimal.TEN).setTax(BigDecimal.valueOf(20)));

TestPullProvider provider = new TestPullProvider();

provider.generateXML(invoice);

assertNotNull(provider.getCalculator());
assertTrue(provider.getCalculator().wasCalled());
}
}