Rails Admin并处理总计,小计和折扣字段

时间:2019-01-05 09:47:35

标签: ruby-on-rails activerecord ruby-on-rails-5 rails-admin

好,所以我有一个表orders,order_items和items。一切正常,除了1件事。

    class CreateOrders < ActiveRecord::Migration[5.0]
      def change
        create_table :orders do |t|
          t.integer :seller_id
          t.integer :customer_id
          t.string :shipping_method
          t.string :shipping_terms
          t.string :payment_method
          t.date :delivery_date
          t.date :due_date
          t.decimal :total_discount, :precision =>8, :scale => 2
          t.decimal :subtotal, :precision =>8, :scale => 2
          t.decimal :sales_tax, :precision =>8, :scale => 2
          t.decimal :total, :precision =>8, :scale => 2

          t.timestamps
        end
      end
    end
    class CreateOrderItems < ActiveRecord::Migration[5.0]
      def change
        create_table :order_items do |t|
          t.integer :order_id
          t.integer :item_id
          t.integer :quantity
          t.decimal :discount, :precision =>8, :scale => 2
          t.decimal :line_total, :precision =>8, :scale => 2
          t.boolean :packed
          t.string :packed_by
          t.string :ffr

          t.timestamps
        end
      end
    end
    class CreateItems < ActiveRecord::Migration[5.0]
      def change
        create_table :items do |t|
          t.integer :sku
          t.string :name
          t.decimal :price, :precision =>8, :scale => 2
          t.string :description
          t.decimal :weight, :precision =>8, :scale => 2
          t.timestamps
        end
      end
    end

基本上,需要在将项目添加到订单中或在保​​存所有内容之前进行计算。

在“订单”表上,需要进行以下操作

  

计算:总折扣(美元金额),小计,:销售税,:总计

在OrderItems表上,需要进行以下操作

  

计算:line_total,折扣(美元金额)

必须有一个理智的方法来做到这一点,但我还没有弄清楚。我真的不知道我在寻找什么,或者我正在搜索所有错误的东西。

0 个答案:

没有答案