Skip to content

Commit ba3efd4

Browse files
authored
Merge pull request #26 from Purple-Stock/feat/control-clothing-manufacturing
Controle de produção
2 parents d306497 + 5537e04 commit ba3efd4

File tree

62 files changed

+1291
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1291
-60
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ Você pode testar o Open Erp com um clique no Heroku:
115115

116116
Este projeto existe graças a todas as pessoas que contribuem. Fique a vontade para contribuir! Essas aqui são boas [issues](https://github.com/Purple-Stock/open-erp/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) para começar! Se tiver dúvidas ou interesse em utilizar em algum negócio entre em contato em matheus.puppe@purplestock.com.br
117117

118+
118119
## Contribuidores
119120

120121
Esse projeto existe graças ao esforço e dedicação dessas pessoas:
@@ -128,3 +129,4 @@ Esse projeto existe graças ao esforço e dedicação dessas pessoas:
128129
## Licença
129130

130131
[MIT](https://github.com/Purple-Stock/open-erp/blob/master/LICENSE)
132+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
class ProductionsController < ApplicationController
2+
before_action :set_production, only: [:show, :edit, :update, :destroy]
3+
before_action :set_tailor_options, only: [:new, :edit, :create, :update]
4+
5+
def index
6+
@productions = Production.all
7+
end
8+
9+
def show
10+
end
11+
12+
def new
13+
@production = Production.new
14+
@production.production_products.build
15+
end
16+
17+
def edit
18+
end
19+
20+
def create
21+
@production = Production.new(production_params)
22+
if @production.save
23+
redirect_to @production, notice: 'Production was successfully created.'
24+
else
25+
render :new
26+
end
27+
end
28+
29+
def update
30+
if @production.update(production_params)
31+
redirect_to @production, notice: 'Production was successfully updated.'
32+
else
33+
render :edit
34+
end
35+
end
36+
37+
def destroy
38+
begin
39+
ProductionProduct.where(production_id: @production.id).destroy_all
40+
@production.destroy
41+
respond_to do |format|
42+
format.html { redirect_to productions_path, notice: 'Produção deletado.' }
43+
format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@production)) }
44+
end
45+
rescue ActiveRecord::InvalidForeignKey
46+
# Handle invalid foreign key by raising a custom error message
47+
raise "Can't delete production because it has associated records"
48+
end
49+
end
50+
51+
private
52+
53+
def set_production
54+
@production = Production.find(params[:id])
55+
end
56+
57+
def production_params
58+
params.require(:production).permit(:cut_date, :deliver_date, :quantity, :tailor_id, :consider, production_products_attributes: [:id, :product_id, :quantity, :_destroy])
59+
end
60+
61+
def set_tailor_options
62+
@tailors = Tailor.all
63+
end
64+
end

app/controllers/tailors_controller.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
class TailorsController < ApplicationController
2+
before_action :set_tailor, only: [:show, :edit, :update, :destroy]
3+
4+
def index
5+
@tailors = Tailor.all
6+
end
7+
8+
def show
9+
end
10+
11+
def new
12+
@tailor = Tailor.new
13+
end
14+
15+
def edit
16+
end
17+
18+
def create
19+
@tailor = Tailor.new(tailor_params)
20+
if @tailor.save
21+
redirect_to @tailor, notice: 'Costureiro Criado com sucesso.'
22+
else
23+
render :new
24+
end
25+
end
26+
27+
def update
28+
if @tailor.update(tailor_params)
29+
redirect_to @tailor, notice: 'Costureiro Atualizado com sucesso.'
30+
else
31+
render :edit
32+
end
33+
end
34+
35+
def destroy
36+
@tailor.destroy
37+
redirect_to tailors_url, notice: 'Costureiro Removido com sucesso.'
38+
end
39+
40+
private
41+
42+
def set_tailor
43+
@tailor = Tailor.find(params[:id])
44+
end
45+
46+
def tailor_params
47+
params.require(:tailor).permit(:name, :production_id)
48+
end
49+
end

app/helpers/productions_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ProductionsHelper
2+
end

app/helpers/tailors_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module TailorsHelper
2+
end

app/models/product.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ class Product < ApplicationRecord
3535
has_many :purchase_products
3636
has_many :sale_products
3737
has_many :group_products
38+
has_many :production_products
39+
has_many :productions, through: :production_products
40+
has_one_attached :image
41+
3842
has_one_attached :image do |attachable|
3943
attachable.variant :thumb, resize_to_limit: [50, 50]
4044
end
45+
4146
has_many :simplo_items
4247
has_one :store
4348
has_one :stock, dependent: :destroy

app/models/production.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# == Schema Information
2+
#
3+
# Table name: productions
4+
#
5+
# id :bigint not null, primary key
6+
# consider :boolean default(FALSE)
7+
# cut_date :datetime
8+
# deliver_date :datetime
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
11+
# account_id :integer
12+
# tailor_id :bigint
13+
#
14+
# Indexes
15+
#
16+
# index_productions_on_account_id (account_id)
17+
# index_productions_on_tailor_id (tailor_id)
18+
#
19+
# Foreign Keys
20+
#
21+
# fk_rails_... (tailor_id => tailors.id)
22+
#
23+
class Production < ApplicationRecord
24+
acts_as_tenant :account
25+
has_many :production_products
26+
has_many :products, through: :production_products
27+
28+
accepts_nested_attributes_for :production_products, allow_destroy: true
29+
30+
belongs_to :tailor, optional: true
31+
end

app/models/production_product.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# == Schema Information
2+
#
3+
# Table name: production_products
4+
#
5+
# id :bigint not null, primary key
6+
# quantity :integer
7+
# created_at :datetime not null
8+
# updated_at :datetime not null
9+
# product_id :bigint not null
10+
# production_id :bigint not null
11+
#
12+
# Indexes
13+
#
14+
# index_production_products_on_product_id (product_id)
15+
# index_production_products_on_production_id (production_id)
16+
#
17+
# Foreign Keys
18+
#
19+
# fk_rails_... (product_id => products.id)
20+
# fk_rails_... (production_id => productions.id)
21+
#
22+
class ProductionProduct < ApplicationRecord
23+
belongs_to :product
24+
belongs_to :production
25+
26+
validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 }
27+
end

app/models/revenue_estimation.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
# created_at :datetime not null
1313
# updated_at :datetime not null
1414
#
15-
# RevenueEstimation exists to answer a question:
16-
# How much Order Items to sale in order to achieve the average ticket
17-
# for the given month?
1815
class RevenueEstimation < ApplicationRecord
1916
attr_accessor :month
2017

app/models/shein_order.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# Indexes
1212
#
1313
# index_shein_orders_on_account_id (account_id)
14-
#
14+
1515
require 'zip'
1616

1717
class SheinOrder < ApplicationRecord

app/models/tailor.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# == Schema Information
2+
#
3+
# Table name: tailors
4+
#
5+
# id :bigint not null, primary key
6+
# name :string
7+
# created_at :datetime not null
8+
# updated_at :datetime not null
9+
# account_id :integer
10+
#
11+
# Indexes
12+
#
13+
# index_tailors_on_account_id (account_id)
14+
#
15+
class Tailor < ApplicationRecord
16+
acts_as_tenant :account
17+
has_many :productions
18+
end

app/views/productions/_form.html.erb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<%= form_with(model: production, local: true) do |form| %>
2+
3+
<!-- Fields for production -->
4+
5+
<div class="form-group">
6+
<%= form.label :tailor_id, 'Select Tailor' %>
7+
<%= form.collection_select :tailor_id, Tailor.all, :id, :name, include_blank: true %>
8+
</div>
9+
10+
<h3>Products</h3>
11+
<div id="products">
12+
<%= form.fields_for :products do |product_form| %>
13+
<%= render 'product_fields', f: product_form %>
14+
<% end %>
15+
16+
<div class="links">
17+
<%= link_to_add_association 'Add Product', form, :products %>
18+
</div>
19+
</div>
20+
21+
<%= form.submit %>
22+
<% end %>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- app/views/productions/_product_fields.html.erb -->
2+
<div class="nested-fields">
3+
<%= f.label :name %>
4+
<%= f.text_field :name %>
5+
6+
<!-- other product fields -->
7+
8+
<%= link_to_remove_association "Remove Product", f %>
9+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div id="<%= dom_id production %>">
2+
<p>
3+
<strong>Quantity:</strong>
4+
<%= production.quantity %>
5+
</p>
6+
7+
<p>
8+
<strong>Cut date:</strong>
9+
<%= production.cut_date %>
10+
</p>
11+
12+
<p>
13+
<strong>Deliver date:</strong>
14+
<%= production.deliver_date %>
15+
</p>
16+
17+
</div>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
json.extract! production, :id, :quantity, :cut_date, :deliver_date, :created_at, :updated_at
2+
json.url production_url(production, format: :json)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<div class="nested-fields">
2+
<div class="col-md-12">
3+
<div class="row mb-3">
4+
<!-- Product Select Dropdown -->
5+
<div class="col-md-6">
6+
<%= f.label :product_id, t('activerecord.attributes.production_product.product_id') %>
7+
<%= f.collection_select :product_id, Product.all, :id, :name, { include_blank: true }, { class: 'form-control' } %>
8+
</div>
9+
10+
<!-- Quantity Input -->
11+
<div class="col-md-2">
12+
<%= f.label :quantity, t('activerecord.attributes.production_product.quantity') %>
13+
<%= f.number_field :quantity, class: 'form-control' %>
14+
</div>
15+
16+
<!-- Remove Button -->
17+
<div class="col-md-2 d-flex align-items-end">
18+
<%= link_to_remove_association t('actions.remove_product'), f, class: 'btn btn-danger' %>
19+
</div>
20+
</div>
21+
</div>
22+
</div>

app/views/productions/edit.html.erb

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<br><br>
2+
<%= form_with(model: @production, local: true, html: { class: 'needs-validation', novalidate: '' }) do |form| %>
3+
4+
<!-- Row 1: Tailor Selection -->
5+
<div class="row mb-3">
6+
<div class="col-3">
7+
<%= form.label :tailor_id, t('productions.form.tailor_selection'), class: 'form-label' %>
8+
<%= form.collection_select :tailor_id, @tailors, :id, :name, { include_blank: true }, { class: 'form-control' } %>
9+
</div>
10+
</div>
11+
12+
<!-- Row 2: Dates -->
13+
<div class="row mb-3">
14+
<div class="col-md-6">
15+
<%= form.label :cut_date, t('productions.form.cut_date'), class: 'form-label' %>
16+
<%= form.date_field :cut_date, class: 'form-control' %>
17+
</div>
18+
<div class="col-md-6">
19+
<%= form.label :deliver_date, t('productions.form.deliver_date'), class: 'form-label' %>
20+
<%= form.date_field :deliver_date, class: 'form-control' %>
21+
</div>
22+
</div>
23+
24+
<!-- Row 3: Production Products -->
25+
<div class="mb-3">
26+
<%= form.fields_for :production_products do |pp_form| %>
27+
<%= render 'production_product_fields', f: pp_form %>
28+
<% end %>
29+
<%= link_to_add_association t('productions.form.add_product'), form, :production_products, class: 'btn btn-primary' %>
30+
</div>
31+
32+
<div class="row mb-3 form-check">
33+
<%= form.check_box :consider, class: 'form-check-input' %>
34+
<%= form.label :consider, t('productions.form.consider'), class: 'form-check-label' %>
35+
</div>
36+
37+
<!-- Submit Button -->
38+
<div class="row">
39+
<div class="col">
40+
<%= form.submit @production.new_record? ? t('helpers.submit.create') : t('helpers.submit.update'), class: 'btn btn-success' %>
41+
</div>
42+
</div>
43+
44+
<% end %>

0 commit comments

Comments
 (0)