Skip to content

Commit

Permalink
Price commodities not null.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnemonic78 committed Jan 2, 2025
1 parent 82cf3ad commit 9845fac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,16 +647,9 @@ private void exportPrices(XmlSerializer xmlSerializer) throws IOException {
Timber.i("export prices");
xmlSerializer.startTag(null, TAG_PRICEDB);
xmlSerializer.attribute(null, ATTR_KEY_VERSION, "1");
Cursor cursor = mPricesDbAdapter.fetchAllRecords();
try {
while (cursor.moveToNext()) {
Price price = mPricesDbAdapter.buildModelInstance(cursor);
exportPrice(xmlSerializer, price);
}
} finally {
if (cursor != null) {
cursor.close();
}
List<Price> prices = mPricesDbAdapter.getAllRecords();
for (Price price : prices) {
exportPrice(xmlSerializer, price);
}
xmlSerializer.endTag(null, TAG_PRICEDB);
}
Expand All @@ -669,8 +662,8 @@ private void exportPrice(XmlSerializer xmlSerializer, Price price) throws IOExce
xmlSerializer.text(price.getUID());
xmlSerializer.endTag(null, TAG_PRICE_ID);
// commodity
String commodityId = price.getCommodityUID();
Commodity commodity = mCommoditiesDbAdapter.getRecord(commodityId);
String commodityUID = price.getCommodityUID();
Commodity commodity = mCommoditiesDbAdapter.getRecord(commodityUID);
xmlSerializer.startTag(null, TAG_PRICE_COMMODITY);
xmlSerializer.startTag(null, TAG_COMMODITY_SPACE);
xmlSerializer.text(commodity.getNamespace());
Expand Down
21 changes: 10 additions & 11 deletions app/src/main/kotlin/org/gnucash/android/model/Price.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@ import java.text.NumberFormat
* Model for commodity prices
*/
class Price : BaseModel {
var commodity: Commodity? = null
var currency: Commodity? = null
var date: Timestamp
var commodity: Commodity
var currency: Commodity
var date: Timestamp = TimestampHelper.getTimestampFromNow()
var source: String? = null
var type: String? = null

constructor() : this(null, null)
constructor() : this(Commodity.DEFAULT_COMMODITY, Commodity.DEFAULT_COMMODITY)

/**
* Create new instance with the GUIDs of the commodities
*
* @param commodity the origin commodity
* @param currency the target commodity
* @param commodity1 the origin commodity
* @param commodity2 the target commodity
*/
constructor(commodity: Commodity?, currency: Commodity?) {
this.commodity = commodity
this.currency = currency
date = TimestampHelper.getTimestampFromNow()
constructor(commodity1: Commodity, commodity2: Commodity) {
this.commodity = commodity1
this.currency = commodity2
}

/**
Expand All @@ -38,7 +37,7 @@ class Price : BaseModel {
* @param commodity2 the target commodity
* @param exchangeRate exchange rate between the commodities
*/
constructor(commodity1: Commodity?, commodity2: Commodity?, exchangeRate: BigDecimal) :
constructor(commodity1: Commodity, commodity2: Commodity, exchangeRate: BigDecimal) :
this(commodity1, commodity2) {
// Store 0.1234 as 1234/10000
valueNum = exchangeRate.unscaledValue().toLong()
Expand Down

0 comments on commit 9845fac

Please sign in to comment.