Module: Magelex::MagentoCSV
- Defined in:
- lib/magelex/magento_csv.rb
Constant Summary collapse
- MONEY_FIELDS =
['Order Shipping', 'Order Grand Total', 'Item Original Price', 'Item Total', 'Item Tax', 'Item Discount']
Class Method Summary collapse
-
.init_bill(row) ⇒ Object
Creates a bill with basic information from csv line.
- .parse(string) ⇒ Object
-
.read(filename) ⇒ Object
Reads file and returns lexware_bills.
Class Method Details
.init_bill(row) ⇒ Object
Creates a bill with basic information from csv line
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/magelex/magento_csv.rb', line 30 def self.init_bill row bill = Magelex::LexwareBill.new # TODO: defining a attribute|colum- map would be nicer bill.order_nr = row['Order Number'] bill.customer_name = row['Billing Name'] bill.country_code = row['Shipping Country'] bill.date = row['Order Date'] bill.status = row['Order Status'] bill.shipping_cost = row['Order Shipping'] if (12.59..12.61).include? bill.shipping_cost Magelex::logger.info "Correcting shipping cost of #{bill.order_nr} (12.6 -> 15 / 1.19 €)" bill.shipping_cost = 15 / 1.19 elsif bill.shipping_cost == 4.15 Magelex::logger.info "Correcting shipping cost of #{bill.order_nr} (4.15 -> 4.95 / 1.19 €)" bill.shipping_cost = 4.95 / 1.19 end bill.total = row['Order Grand Total'] bill end |
.parse(string) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/magelex/magento_csv.rb', line 53 def self.parse string bills = [] current_bill = Magelex::LexwareBill.new CSV::parse(string, :headers => :first_row, converters: [:all, :german_money_amount, :order_date]) do |row| # Multiple rows (with same order_nr) define one order # One order will be mapped to one bill if current_bill.order_nr != row['Order Number'] current_bill = init_bill row end current_bill.add_item(row['Item Total'], row['Item Tax'], row['Item Name'], row['Item Discount'], row['Item Original Price'].to_f * row['Item Qty Ordered'].to_i) if !bills.include? (current_bill) bills << current_bill end end bills end |
.read(filename) ⇒ Object
Reads file and returns lexware_bills
25 26 27 |
# File 'lib/magelex/magento_csv.rb', line 25 def self.read filename self.parse(File.read filename) end |