Browse Source

bugfix: it was not possible to create documents with customers not havin a tax ID. But the customer tax id should not be required! …altered some code…

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
dev
Stephan Richter 4 days ago
parent
commit
dc0b381aba
  1. 20
      core/src/main/java/de/srsoftware/umbrella/core/model/Customer.java
  2. 2
      frontend/src/Components/ContactSelector.svelte

20
core/src/main/java/de/srsoftware/umbrella/core/model/Customer.java

@ -1,16 +1,14 @@
/* © SRSoftware 2025 */ /* © SRSoftware 2025 */
package de.srsoftware.umbrella.core.model; package de.srsoftware.umbrella.core.model;
import static de.srsoftware.tools.Optionals.emptyIfNull;
import static de.srsoftware.umbrella.core.Constants.*; import static de.srsoftware.umbrella.core.Constants.*;
import static de.srsoftware.umbrella.core.Field.*; import static de.srsoftware.umbrella.core.Field.*;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException; import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
import de.srsoftware.tools.Mappable; import de.srsoftware.tools.Mappable;
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
import java.util.HashSet; import java.util.*;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import org.json.JSONObject; import org.json.JSONObject;
public final class Customer implements Mappable { public final class Customer implements Mappable {
@ -73,7 +71,7 @@ public final class Customer implements Mappable {
if (!json.has(ID) || !(json.get(ID) instanceof String id)) throw missingFieldException(ID); if (!json.has(ID) || !(json.get(ID) instanceof String id)) throw missingFieldException(ID);
if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingFieldException(NAME); if (!json.has(NAME) || !(json.get(NAME) instanceof String name)) throw missingFieldException(NAME);
if (!json.has(EMAIL) || !(json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL); if (!json.has(EMAIL) || !(json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL);
if (!json.has(TAX_ID) || !(json.get(TAX_ID) instanceof String taxId)) throw missingFieldException(TAX_ID); var taxId = json.has(TAX_ID) && json.get(TAX_ID) instanceof String tid ? tid : null;
var lang = json.has(LANGUAGE) && json.get(LANGUAGE) instanceof String l ? l : FALLBACK_LANG; var lang = json.has(LANGUAGE) && json.get(LANGUAGE) instanceof String l ? l : FALLBACK_LANG;
return new Customer(id,name,email,taxId,lang); return new Customer(id,name,email,taxId,lang);
} }
@ -104,11 +102,11 @@ public final class Customer implements Mappable {
@Override @Override
public Map<String, Object> toMap() { public Map<String, Object> toMap() {
return Map.of( var map = new HashMap<String,Object>();
"id", id, map.put("id", id);
"name", name, map.put("name", name);
"email", email, map.put("email", email);
"tax_id", taxNumber map.put("tax_id", emptyIfNull(taxNumber));
); return map;
} }
} }

2
frontend/src/Components/ContactSelector.svelte

@ -26,6 +26,7 @@
contact.FN = fn(contact.vcard); contact.FN = fn(contact.vcard);
contact.ORG = org(contact.vcard); contact.ORG = org(contact.vcard);
const extras = contact.vcard.match(/^X-.*:.+/gm); const extras = contact.vcard.match(/^X-.*:.+/gm);
if (extras) {
for (let ex of extras){ for (let ex of extras){
ex = extra(ex); ex = extra(ex);
switch (ex.name){ switch (ex.name){
@ -45,6 +46,7 @@
console.log(ex); console.log(ex);
} }
} }
}
delete contact.vcard; delete contact.vcard;
console.log(contact); console.log(contact);
return contact; return contact;

Loading…
Cancel
Save