Skip to content

Commit 0839790

Browse files
authored
Merge branch 'main' into feat/control-clothing-manufacturing
2 parents 92895b8 + f2100ba commit 0839790

15 files changed

+264
-14
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,20 @@ Você pode testar o Open Erp com um clique no Heroku:
113113

114114
## Contribuindo
115115

116-
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/puppe1990/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@gmail.com
116+
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@gmail.com
117+
117118

118119
## Contribuidores
119120

120121
Esse projeto existe graças ao esforço e dedicação dessas pessoas:
121122

122123
**Desenvolvimento**
123124

124-
<a href="https://github.com/puppe1990/open-erp/graphs/contributors">
125-
<img src="https://contrib.rocks/image?repo=puppe1990/open-erp" />
125+
<a href="https://github.com/Purple-Stock/open-erp/graphs/contributors">
126+
<img src="https://contrib.rocks/image?repo=Purple-Stock/open-erp" />
126127
</a>
127128

128129
## Licença
129130

130-
[MIT](https://github.com/puppe1990/open-erp/blob/master/LICENSE)
131+
[MIT](https://github.com/Purple-Stock/open-erp/blob/master/LICENSE)
132+

app/jobs/daily_canceled_order_job.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
# DailyCanceledOrderJob perform against created orders set previously
4+
# with another status.
5+
# For this reason, we should call this job as an updater job.
6+
# The crucial difference here is the absence of the alteration date in the bling API response.
7+
# It is possible to filter by alteration date, however the alteration date (dataAlteraçãoInicial) is not
8+
# present in the response. Our solution is querying by alteration date assuming it is the same in bling API
9+
# setting this assumed value directly on our database.
10+
# Motives to run this job:
11+
# There are orders status over counted. There are possibilities they became canceled on bling API
12+
class DailyCanceledOrderJob < BlingOrderItemCreatorBaseJob
13+
STATUS = BlingOrderItem::Status::CANCELED.freeze
14+
15+
attr_accessor :account_id
16+
17+
def perform(account_id, initial_alteration_date = nil)
18+
@status = STATUS
19+
@account_id = account_id
20+
@initial_date = initial_alteration_date || Date.today
21+
@final_date = Date.today
22+
date_range = (@initial_date..@final_date)
23+
date_range.each do |alteration_date|
24+
@alteration_date = alteration_date
25+
final_alteration_date = (alteration_date + 1.day).strftime
26+
options = { dataAlteracaoInicial: @alteration_date.strftime, dataAlteracaoFinal: final_alteration_date }
27+
orders = Services::Bling::Order.call(order_command: 'find_orders', tenant: account_id,
28+
situation: STATUS, options: options)
29+
orders = orders['data']
30+
31+
create_orders(orders)
32+
end
33+
end
34+
end

app/models/revenue_estimation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class RevenueEstimation < ApplicationRecord
1717

1818
validates :revenue, :average_ticket, :date, presence: :true
1919
validates :revenue, numericality: :true
20+
validates :average_ticket, numericality: { greater_than: 0 }
2021

2122
before_save :calculate_quantity
2223
before_validation :set_date

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/views/revenue_estimations/_form.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
<div class="form-row">
3131
<div class="form-group col-6">
3232
<%= f.label :month, :class => 'control-label' %>
33-
<%= f.number_field :month, :class => 'form-control', value: f.object.date&.month %>
33+
<%= f.select :month, options_for_select((1..12).map { |m| [I18n.t("date.month_names")[m], m] }, Time.now.month), {}, class: 'form-control' %>
3434
</div>
3535

3636
<div class="form-group col-6">
3737
<%= f.label :revenue, :class => 'control-label' %>
38-
<%= f.text_field :revenue, :class => 'form-control' %>
38+
<%= f.text_field :revenue, value: number_to_currency(f.object.revenue, precision: 2), class: 'form-control' %>
3939
</div>
4040

4141
<div class="form-group col-6">
@@ -45,7 +45,7 @@
4545

4646
<div class="form-group col-6">
4747
<%= f.label :average_ticket, :class => 'control-label' %>
48-
<%= f.text_field :average_ticket, :class => 'form-control' %>
48+
<%= f.text_field :average_ticket, value: number_to_currency(f.object.average_ticket, precision: 2), class: 'form-control' %>
4949
</div>
5050

5151
<div class="form-group">

config/environments/development.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
set: { priority: 1 }, # additional Active Job properties; can also be a lambda/proc e.g. `-> { { priority: [1,2].sample } }`
131131
description: "Create Order Items statuses are canceled" # optional description that appears in Dashboard
132132
},
133-
134133
checked_order_items_task: {
135134
cron: "@weekly",
136135
class: "CheckedBlingOrderItemsJob",

config/environments/production.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@
156156
set: { priority: 1 }, # additional Active Job properties; can also be a lambda/proc e.g. `-> { { priority: [1,2].sample } }`
157157
description: "Create Order Items statuses are canceled" # optional description that appears in Dashboard
158158
},
159-
160159
checked_order_items_task: {
161160
cron: "@weekly",
162161
class: "CheckedBlingOrderItemsJob",

config/locales/pt-BR.models.revenue_estimations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ pt-BR:
1818
updated: Estimativa da Receita Atualizada
1919
deleted: Estimativa da Receita Deletada
2020
new: Nova Estimativa da Receita
21-
month: Número do Mês
21+
month: Mês

config/locales/pt-BR.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ pt-BR:
224224
tailor:
225225
edit:
226226
title: "Editar Costureiro"
227+
new: Criar %{model}
228+
edit: Editar %{model}
227229
actions: Ações
228230
number:
229231
currency:
@@ -295,13 +297,13 @@ pt-BR:
295297
long: "%d de %B de %Y, %H:%M"
296298
short: "%d de %B, %H:%M"
297299
pm: ''
298-
300+
299301
date:
300302
formats:
301303
default: "%d-%m-%Y"
302304
long: "%d de %B de %Y"
303305
short: "%d de %B"
304-
306+
305307
January: Janeiro
306308
February: Fevereiro
307309
March: Março
@@ -326,3 +328,4 @@ helpers:
326328
add_product: "Adicionar Produto"
327329
consider: "Considerar"
328330
submit_button: "Enviar"
331+

spec/factories/shein_orders.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
# Indexes
1212
#
1313
# index_shein_orders_on_account_id (account_id)
14-
#
14+
# data :json
15+
# created_at :datetime not null
16+
# updated_at :datetime not null
17+
1518
FactoryBot.define do
1619
factory :shein_order do
1720
data { "" }
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# frozen_string_literal: true
2+
3+
require 'rails_helper'
4+
5+
RSpec.describe DailyCanceledOrderJob, type: :job do
6+
let(:user) { FactoryBot.create(:user) }
7+
let(:date) { Date.new(2023, 11, 22) }
8+
let(:alteration_date) { Date.new(2023, 12, 14) }
9+
let(:situation_id) { BlingOrderItem::Status::PENDING }
10+
let(:bling_order_id) { '19341921284' }
11+
12+
describe '#perform' do
13+
before do
14+
allow(Date).to receive(:today).and_return Date.new(2023, 12, 14)
15+
FactoryBot.create(:bling_datum, account_id: user.account.id, expires_at: Time.zone.now + 2.days)
16+
FactoryBot.create(:bling_order_item, bling_order_id:, date:, situation_id:)
17+
end
18+
19+
it 'has status canceled' do
20+
VCR.use_cassette('canceled_by_initial_alteration_date', erb: true) do
21+
subject.perform(user.account.id)
22+
expect(BlingOrderItem.find_by(bling_order_id:).situation_id.to_i)
23+
.to eq(BlingOrderItem::Status::CANCELED)
24+
end
25+
end
26+
27+
it 'is equal to alteration_date' do
28+
VCR.use_cassette('canceled_by_initial_alteration_date', erb: true) do
29+
subject.perform(user.account.id)
30+
expect(BlingOrderItem.find_by(bling_order_id:).alteration_date.to_date)
31+
.to eq(alteration_date)
32+
end
33+
end
34+
end
35+
end

spec/models/revenue_estimation_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
it { is_expected.to validate_presence_of(:revenue) }
2020
it { is_expected.to validate_presence_of(:date) }
2121
it { is_expected.to validate_numericality_of(:revenue) }
22+
it { is_expected.to validate_numericality_of(:average_ticket).is_greater_than(0) }
2223
end
2324

2425
describe '#save' do

spec/models/shein_order_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
# Indexes
1212
#
1313
# index_shein_orders_on_account_id (account_id)
14+
# data :json
15+
# created_at :datetime not null
16+
# updated_at :datetime not null
1417
#
1518
require 'rails_helper'
1619

spec/spec_helper.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
# https://github.com/vcr/vcr/discussions/887 ways to hide sensitive data.
1313
interaction.request.headers['Authorization'][0] = "Bearer <%= ENV['ACCESS_TOKEN'] %>"
1414
interaction.response.body.gsub!(/\d{3}[.]\d{3}[.]\d{3}[-]\d{2}/, '999.999.999-99')
15+
# Some names with latin punctuation had escaped
16+
interaction.response.body.gsub!(/\\u00ed/, '')
17+
interaction.response.body.gsub!(/\\u00f3/, '')
18+
interaction.response.body.gsub!(/\\u00fa/, '')
19+
interaction.response.body.gsub!(/\\u00e3/, '')
20+
interaction.response.body.gsub!(/\\u00e7/, '')
21+
interaction.response.body.gsub!('******', 'Aa Bb')
22+
interaction.response.body.gsub!('****', 'Aa Bb')
1523
interaction.response.body.gsub!(/"nome\":["^\"][a-z-A-Z]+[\s][a-z-A-Z | \s]+/, "\"nome\":\"Faker Name Souza")
1624
end
1725
end

0 commit comments

Comments
 (0)