]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/TransactionAccount.java
fix copying ensuring currency is not null
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / TransactionAccount.java
index 730a866a1daf2d2da48cefc491ab6ed3137b487e..d6417cd651336c43455c2637a14d5623969a9527 100644 (file)
@@ -24,11 +24,13 @@ import androidx.room.ForeignKey;
 import androidx.room.Index;
 import androidx.room.PrimaryKey;
 
+import net.ktnx.mobileledger.utils.Misc;
+
 @Entity(tableName = "transaction_accounts", foreignKeys = {
         @ForeignKey(entity = Transaction.class, parentColumns = {"id"},
                     childColumns = {"transaction_id"}, onDelete = ForeignKey.CASCADE,
-                    onUpdate = ForeignKey.RESTRICT),
-}, indices = {@Index(name = "fk_tran_acc_trans", value = {"transaction_id"}),
+                    onUpdate = ForeignKey.RESTRICT)
+}, indices = {@Index(name = "fk_trans_acc_trans", value = {"transaction_id"}),
               @Index(name = "un_transaction_accounts", unique = true,
                      value = {"transaction_id", "order_no"})
 })
@@ -37,7 +39,7 @@ public class TransactionAccount {
     @PrimaryKey(autoGenerate = true)
     private long id;
     @ColumnInfo(name = "transaction_id")
-    private int transactionId;
+    private long transactionId;
     @ColumnInfo(name = "order_no")
     private int orderNo;
     @ColumnInfo(name = "account_name")
@@ -51,7 +53,7 @@ public class TransactionAccount {
     @ColumnInfo
     private String comment;
     @ColumnInfo(defaultValue = "0")
-    private int generation = 0;
+    private long generation = 0;
     public long getId() {
         return id;
     }
@@ -59,10 +61,10 @@ public class TransactionAccount {
         this.id = id;
     }
     @NonNull
-    public int getTransactionId() {
+    public long getTransactionId() {
         return transactionId;
     }
-    public void setTransactionId(int transactionId) {
+    public void setTransactionId(long transactionId) {
         this.transactionId = transactionId;
     }
     public int getOrderNo() {
@@ -97,10 +99,21 @@ public class TransactionAccount {
     public void setComment(String comment) {
         this.comment = comment;
     }
-    public int getGeneration() {
+    public long getGeneration() {
         return generation;
     }
-    public void setGeneration(int generation) {
+    public void setGeneration(long generation) {
         this.generation = generation;
     }
+
+    public void copyDataFrom(TransactionAccount o) {
+        // id = o.id
+        transactionId = o.transactionId;
+        orderNo = o.orderNo;
+        accountName = o.accountName;
+        currency = Misc.nullIsEmpty(o.currency);
+        amount = o.amount;
+        comment = o.comment;
+        generation = o.generation;
+    }
 }