nam1962 / returnsworth

Ruby on Rails app & PWA to manage commerce logistics returns
https://returnsworth-0dc66e0a7879.herokuapp.com/
GNU Affero General Public License v3.0
0 stars 1 forks source link

Seed #9

Closed nam1962 closed 1 year ago

nam1962 commented 1 year ago

[Supprimé]

nam1962 commented 1 year ago

@Noreea J'ai reposé la question à Phind en lui fournissant ta seed.

Que penses tu de sa réponse ?

(J'aime bien l'avoir pigée de mon côté)

To refactor the seed file and create 4 client service officers, 6 warehouse operators, and 20 returns with various states, status, additional costs, owners, and item quantity, you can use loops and arrays to generate the necessary data. Here's a step-by-step guide:

  1. First, create 4 client service officers and 6 warehouse operators using loops. To do this, you can use the following code:
officers = 4.times.map do |i|
  User.create!(
    email: "officer#{i + 1}@lewagon.com",
    password: "123456",
    role: "client_service_officer",
    first_name: "Officer",
    last_name: "CSO#{i + 1}"
  )
end

operators = 6.times.map do |i|
  User.create!(
    email: "operator#{i + 1}@lewagon.com",
    password: "123456",
    role: "warehouse_operator",
    first_name: "Operator",
    last_name: "WH#{i + 1}"
  )
end
  1. Next, generate 20 returns with random attributes. You can use the sample method on arrays to randomly pick an element. Use the following code to create 20 returns:
statuses = ["pending", "approved", "rejected"]
states = ["processed", "unprocessed"]
additional_costs = [10, 20, 30, 40, 50]

20.times do |i|
  Return.create!(
    command_number: i + 1000,
    client_name: "Client #{i + 1}",
    status: statuses.sample,
    state: states.sample,
    comment: "OK",
    additional_cost: additional_costs.sample,
    exception: 'none',
    restock: true,
    warehouse_operator_id: operators.sample.id,
    client_service_officer_id: officers.sample.id
  )
end
  1. To create the orders and order items, you can use the following code:
20.times do |i|
  order = Order.create!(
    order_number: i + 2000,
    client_name: "Client #{i + 1}"
  )

  order_item = OrderItem.create!(
    order_id: order.id
  )
end
  1. Finally, you can create return items for each return and order item. Use the following code to do this:
returns = Return.all
order_items = OrderItem.all

returns.each do |return_obj|
  ReturnItem.create!(
    return_id: return_obj.id,
    order_item_id: order_items.sample.id
  )
end

Now, you have refactored the seed file to create the desired number of users, orders, returns, and their respective items.

nam1962 commented 1 year ago

Add emballage

nam1962 commented 1 year ago

Add emballage Add produit