use chrono::datetime::DateTime;
use chrono::offset::utc::UTC;
use gen::column;
use gen::schema;
use gen::table;
use rustc_serialize::json::Json;
use rustc_serialize::json::ToJson;
use rustorm::dao::Dao;
use rustorm::dao::IsDao;
use rustorm::dao::Type;
use rustorm::dao::Value;
use rustorm::query::Operand;
use rustorm::table::Column;
use rustorm::table::Foreign;
use rustorm::table::IsTable;
use rustorm::table::Table;
use uuid::Uuid;
use gen::bazaar::Product;
use gen::payment::Country;
use gen::payment::ExchangeRate;
#[derive(RustcEncodable)]
#[derive(Debug, Clone)]
pub struct Currency {
pub currency_id: Uuid,
pub country_id: Option<Uuid>,
pub symbol: Option<String>,
pub unicode: Option<String>,
pub active: bool,
pub client_id: Option<Uuid>,
pub created: DateTime<UTC>,
pub created_by: Option<Uuid>,
pub description: Option<String>,
pub help: Option<String>,
pub name: Option<String>,
pub organization_id: Option<Uuid>,
pub priority: Option<f64>,
pub updated: DateTime<UTC>,
pub updated_by: Option<Uuid>,
pub country: Option<Country>,
pub exchange_rate: Vec<ExchangeRate>,
pub product: Vec<Product>,
}
impl IsDao for Currency {
fn from_dao(dao: &Dao) -> Self {
Currency {
organization_id: dao.get_opt(column::organization_id),
client_id: dao.get_opt(column::client_id),
created: dao.get(column::created),
created_by: dao.get_opt(column::created_by),
updated: dao.get(column::updated),
updated_by: dao.get_opt(column::updated_by),
priority: dao.get_opt(column::priority),
name: dao.get_opt(column::name),
description: dao.get_opt(column::description),
help: dao.get_opt(column::help),
active: dao.get(column::active),
currency_id: dao.get(column::currency_id),
country_id: dao.get_opt(column::country_id),
symbol: dao.get_opt(column::symbol),
unicode: dao.get_opt(column::unicode),
country: None,
exchange_rate: vec![],
product: vec![],
}
}
fn to_dao(&self) -> Dao {
let mut dao = Dao::new();
match self.organization_id {
Some(ref _value) => dao.set(column::organization_id, _value),
None => dao.set_null(column::organization_id)
}
match self.client_id {
Some(ref _value) => dao.set(column::client_id, _value),
None => dao.set_null(column::client_id)
}
dao.set(column::created, &self.created);
match self.created_by {
Some(ref _value) => dao.set(column::created_by, _value),
None => dao.set_null(column::created_by)
}
dao.set(column::updated, &self.updated);
match self.updated_by {
Some(ref _value) => dao.set(column::updated_by, _value),
None => dao.set_null(column::updated_by)
}
match self.priority {
Some(ref _value) => dao.set(column::priority, _value),
None => dao.set_null(column::priority)
}
match self.name {
Some(ref _value) => dao.set(column::name, _value),
None => dao.set_null(column::name)
}
match self.description {
Some(ref _value) => dao.set(column::description, _value),
None => dao.set_null(column::description)
}
match self.help {
Some(ref _value) => dao.set(column::help, _value),
None => dao.set_null(column::help)
}
dao.set(column::active, &self.active);
dao.set(column::currency_id, &self.currency_id);
match self.country_id {
Some(ref _value) => dao.set(column::country_id, _value),
None => dao.set_null(column::country_id)
}
match self.symbol {
Some(ref _value) => dao.set(column::symbol, _value),
None => dao.set_null(column::symbol)
}
match self.unicode {
Some(ref _value) => dao.set(column::unicode, _value),
None => dao.set_null(column::unicode)
}
dao
}
}
impl ToJson for Currency {
fn to_json(&self) -> Json {
self.to_dao().to_json()
}
}
impl Default for Currency {
fn default() -> Self {
Currency{
organization_id: Default::default(),
client_id: Default::default(),
created: UTC::now(),
created_by: Default::default(),
updated: UTC::now(),
updated_by: Default::default(),
priority: Default::default(),
name: Default::default(),
description: Default::default(),
help: Default::default(),
active: Default::default(),
currency_id: Default::default(),
country_id: Default::default(),
symbol: Default::default(),
unicode: Default::default(),
country: Default::default(),
exchange_rate: Default::default(),
product: Default::default(),
}
}
}
impl IsTable for Currency {
fn table() -> Table {
Table {
schema: Some(schema::payment.to_owned()),
name: table::currency.to_owned(),
parent_table: Some(table::record.to_owned()),
sub_table: vec![],
comment: None,
columns: vec![
Column {
name: column::organization_id.to_owned(),
data_type: Type::Uuid,
db_data_type: "uuid".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::client_id.to_owned(),
data_type: Type::Uuid,
db_data_type: "uuid".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::created.to_owned(),
data_type: Type::DateTime,
db_data_type: "timestamp with time zone".to_owned(),
is_primary: false, is_unique: false, not_null: true, is_inherited: true,
default: Some(Operand::Value(Value::String("'now()'".to_owned()))),
comment: None,
foreign: None,
},
Column {
name: column::created_by.to_owned(),
data_type: Type::Uuid,
db_data_type: "uuid".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::updated.to_owned(),
data_type: Type::DateTime,
db_data_type: "timestamp with time zone".to_owned(),
is_primary: false, is_unique: false, not_null: true, is_inherited: true,
default: Some(Operand::Value(Value::String("'now()'".to_owned()))),
comment: None,
foreign: None,
},
Column {
name: column::updated_by.to_owned(),
data_type: Type::Uuid,
db_data_type: "uuid".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::priority.to_owned(),
data_type: Type::F64,
db_data_type: "double precision".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::name.to_owned(),
data_type: Type::String,
db_data_type: "character varying".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::description.to_owned(),
data_type: Type::String,
db_data_type: "character varying".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::help.to_owned(),
data_type: Type::String,
db_data_type: "text".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: true,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::active.to_owned(),
data_type: Type::Bool,
db_data_type: "boolean".to_owned(),
is_primary: false, is_unique: false, not_null: true, is_inherited: true,
default: Some(Operand::Value(Value::String("'true'".to_owned()))),
comment: None,
foreign: None,
},
Column {
name: column::currency_id.to_owned(),
data_type: Type::Uuid,
db_data_type: "uuid".to_owned(),
is_primary: true, is_unique: false, not_null: true, is_inherited: false,
default: Some(Operand::Value(Value::String("'uuid_generate_v4()'".to_owned()))),
comment: None,
foreign: None,
},
Column {
name: column::country_id.to_owned(),
data_type: Type::Uuid,
db_data_type: "uuid".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: false,
default: None,
comment: Some("which country uses this currency".to_owned()),
foreign: Some(
Foreign {
schema: Some("payment".to_owned()),
table: "country".to_owned(),
column: "country_id".to_owned(),
}),
},
Column {
name: column::symbol.to_owned(),
data_type: Type::String,
db_data_type: "character varying".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: false,
default: None,
comment: None,
foreign: None,
},
Column {
name: column::unicode.to_owned(),
data_type: Type::String,
db_data_type: "character varying".to_owned(),
is_primary: false, is_unique: false, not_null: false, is_inherited: false,
default: None,
comment: None,
foreign: None,
},
],
is_view: false,
}
}
}
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static organization_id: &'static str = "currency.organization_id";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static client_id: &'static str = "currency.client_id";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static created: &'static str = "currency.created";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static created_by: &'static str = "currency.created_by";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static updated: &'static str = "currency.updated";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static updated_by: &'static str = "currency.updated_by";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static priority: &'static str = "currency.priority";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static name: &'static str = "currency.name";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static description: &'static str = "currency.description";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static help: &'static str = "currency.help";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static active: &'static str = "currency.active";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static currency_id: &'static str = "currency.currency_id";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static country_id: &'static str = "currency.country_id";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static symbol: &'static str = "currency.symbol";
#[allow(non_upper_case_globals)]
#[allow(dead_code)]
pub static unicode: &'static str = "currency.unicode";