Skip to content

Commit 02e2499

Browse files
committed
Add support for tax codes
1 parent f601bf6 commit 02e2499

File tree

14 files changed

+56
-1
lines changed

14 files changed

+56
-1
lines changed

libpretixsync/src/main/java/eu/pretix/libpretixsync/db/AbstractOrderPosition.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public BigDecimal getPrice() {
101101
}
102102
}
103103

104+
public String getTaxCode() {
105+
try {
106+
return getJSON().optString("tax_code", null);
107+
} catch (JSONException e) {
108+
e.printStackTrace();
109+
return null;
110+
}
111+
}
112+
104113
public BigDecimal getTaxRate() {
105114
try {
106115
return new BigDecimal(getJSON().getString("tax_rate"));

libpretixsync/src/main/java/eu/pretix/libpretixsync/db/AbstractReceiptLine.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ public class AbstractReceiptLine implements LocalObject {
6363

6464
public Long tax_rule;
6565

66+
public String tax_code;
67+
6668
public BigDecimal tax_value;
6769

6870
@Nullable
@@ -196,6 +198,7 @@ public JSONObject toJSON() throws JSONException {
196198
jo.put("tax_rate", tax_rate != null ? tax_rate.setScale(2, RoundingMode.HALF_UP) : "0.00");
197199
jo.put("tax_value", tax_value != null ? tax_value.setScale(2, RoundingMode.HALF_UP) : "0.00");
198200
jo.put("tax_rule", tax_rule != null ? tax_rule : JSONObject.NULL);
201+
jo.put("tax_code", tax_code != null ? tax_code : JSONObject.NULL);
199202
jo.put("secret", secret);
200203
jo.put("seat", seat_guid != null ? seat_guid : JSONObject.NULL);
201204
jo.put("subevent", subevent_id);

libpretixsync/src/main/java/eu/pretix/libpretixsync/db/AbstractTaxRule.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public boolean includesTax() {
3434
}
3535
}
3636

37+
public String getCode() {
38+
try {
39+
if (!getJSON().has("code") || getJSON().isNull("code")) {
40+
return null;
41+
}
42+
return getJSON().getString("code");
43+
} catch (JSONException e) {
44+
e.printStackTrace();
45+
return null;
46+
}
47+
}
48+
3749
public BigDecimal getRate() {
3850
try {
3951
return new BigDecimal(getJSON().getString("rate"));

libpretixsync/src/main/java/eu/pretix/libpretixsync/db/Migrations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
public class Migrations {
1717
private static EntityModel model = Models.DEFAULT;
18-
public static int CURRENT_VERSION = 105;
18+
public static int CURRENT_VERSION = 106;
1919

2020
private static void createVersionTable(Connection c, int version) throws SQLException {
2121
Statement s2 = c.createStatement();

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/OrderPosition.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class OrderPosition(
2424
val price: BigDecimal? = null,
2525
val taxRate: BigDecimal? = null,
2626
val taxValue: BigDecimal? = null,
27+
val taxCode: String? = null,
2728
val seatName: String? = null,
2829
val addonToServerId: Long? = null,
2930
val blocked: Boolean = false,

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/ReceiptLine.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ data class ReceiptLine(
2828
val taxRate: BigDecimal? = null,
2929
val taxRule: Long? = null,
3030
val taxValue: BigDecimal? = null,
31+
val taxCode: String? = null,
3132
val eventDateFrom: OffsetDateTime? = null,
3233
val eventDateTo: OffsetDateTime? = null,
3334
val subEventServerId: Long? = null,

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/TaxRule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ data class TaxRule(
77
val serverId: Long,
88
val rate: BigDecimal = BigDecimal("0.00"),
99
val includesTax: Boolean = false,
10+
val code: String?,
1011
)

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/db/OrderPositionExtensions.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ private fun parsePrice(json: JSONObject): BigDecimal? {
5050
}
5151
}
5252

53+
private fun parseTaxCode(json: JSONObject): String? {
54+
try {
55+
return json.optString("tax_code", null)
56+
} catch (e: JSONException) {
57+
e.printStackTrace()
58+
return null
59+
}
60+
}
61+
5362
private fun parseTaxRate(json: JSONObject): BigDecimal? {
5463
try {
5564
return BigDecimal(json.getString("tax_rate"))

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/db/ReceiptLineExtensions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ fun ReceiptLine.toModel() =
2525
voucherCode = voucher_code,
2626
useReusableMedium = use_reusable_medium,
2727
taxRate = tax_rate,
28+
taxCode = tax_code,
2829
taxRule = tax_rule,
2930
taxValue = tax_value,
3031
eventDateFrom = SafeOffsetDateTimeMapper.decode(event_date_from),

libpretixsync/src/main/java/eu/pretix/libpretixsync/models/db/TaxRuleExtensions.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ fun TaxRule.toModel(): TaxRuleModel {
1414
serverId = this.server_id!!,
1515
rate = parseRate(json),
1616
includesTax = parseIncludesTax(json),
17+
code = parseCode(json),
1718
)
1819
}
1920

@@ -34,3 +35,15 @@ private fun parseIncludesTax(json: JSONObject): Boolean {
3435
return false
3536
}
3637
}
38+
39+
private fun parseCode(json: JSONObject): String? {
40+
try {
41+
if (!json.has("code") or json.isNull("code")) {
42+
return null
43+
}
44+
return json.getString("code")
45+
} catch (e: JSONException) {
46+
e.printStackTrace()
47+
return null
48+
}
49+
}

0 commit comments

Comments
 (0)