Skip to content

Commit a8a9c7e

Browse files
committed
feat: add pinter model to company
1 parent db42d47 commit a8a9c7e

File tree

6 files changed

+63
-5
lines changed

6 files changed

+63
-5
lines changed

app/controllers/admin/configurations_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def handle_configuration_update
1717
end
1818

1919
# Permit only the specific parameters we want to update
20-
permitted_params = params.require(:company).permit(:name, :serial_service_url)
20+
permitted_params = params.require(:company).permit(:name, :serial_service_url, :printer_model)
2121

2222
if @admin.company.update(permitted_params)
2323
redirect_to admin_configurations_path, notice: "Configuración actualizada exitosamente."
@@ -194,9 +194,9 @@ def auto_save
194194

195195
# Handle both formats: direct parameters and nested under company
196196
params_to_update = if params[:company].present?
197-
params.require(:company).permit(:serial_port, :printer_port, :serial_baud_rate, :printer_baud_rate, :serial_parity, :printer_parity, :serial_stop_bits, :printer_stop_bits, :serial_data_bits, :printer_data_bits, :auto_save_consecutivo, :serial_service_url)
197+
params.require(:company).permit(:serial_port, :printer_port, :serial_baud_rate, :printer_baud_rate, :serial_parity, :printer_parity, :serial_stop_bits, :printer_stop_bits, :serial_data_bits, :printer_data_bits, :auto_save_consecutivo, :serial_service_url, :printer_model)
198198
else
199-
params.permit(:serial_port, :printer_port, :serial_baud_rate, :printer_baud_rate, :serial_parity, :printer_parity, :serial_stop_bits, :printer_stop_bits, :serial_data_bits, :printer_data_bits, :auto_save_consecutivo, :serial_service_url)
199+
params.permit(:serial_port, :printer_port, :serial_baud_rate, :printer_baud_rate, :serial_parity, :printer_parity, :serial_stop_bits, :printer_stop_bits, :serial_data_bits, :printer_data_bits, :auto_save_consecutivo, :serial_service_url, :printer_model)
200200
end
201201

202202
# Solo actualizar los campos que se envían

app/models/company.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ class Company < ApplicationRecord
77

88
# Validations
99
validates :serial_service_url, format: { with: URI::DEFAULT_PARSER.make_regexp(%w[http https]), message: "debe ser una URL válida" }, allow_blank: true
10+
11+
# Printer model enum
12+
validates :printer_model, inclusion: { in: %w[zebra tsc], message: "must be either 'zebra' or 'tsc'" }, allow_nil: true
13+
14+
# Set default printer model
15+
after_initialize :set_default_printer_model
16+
17+
private
18+
19+
def set_default_printer_model
20+
self.printer_model ||= 'zebra'
21+
end
1022

1123
# Google Sheets Configuration
1224
def google_sheets_configured?

app/views/admin/configurations/show.html.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@
7878
La URL del servicio serial para la báscula e impresora.
7979
</p>
8080
</div>
81+
82+
<div>
83+
<label for="printer_model" class="block text-sm font-medium text-gray-700 mb-2">
84+
Modelo de Impresora
85+
</label>
86+
<%= form.select :printer_model,
87+
options_for_select([['Zebra', 'zebra'], ['TSC', 'tsc']], @admin.company&.printer_model),
88+
{ prompt: 'Seleccionar modelo de impresora' },
89+
{ class: "block w-full text-sm rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500" } %>
90+
<p class="mt-1 text-xs text-gray-500">
91+
Seleccione el modelo de su impresora de etiquetas.
92+
</p>
93+
</div>
8194
</div>
8295

8396
<div class="mt-6">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddPrinterModelToCompanies < ActiveRecord::Migration[8.0]
2+
def change
3+
add_column :companies, :printer_model, :string, default: 'zebra'
4+
end
5+
end

db/schema.rb

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/models/company_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe Company, type: :model do
4+
describe 'validations' do
5+
it 'allows valid printer_model values' do
6+
company = Company.new(name: 'Test Company')
7+
8+
company.printer_model = 'zebra'
9+
expect(company).to be_valid
10+
11+
company.printer_model = 'tsc'
12+
expect(company).to be_valid
13+
end
14+
15+
it 'does not allow invalid printer_model values' do
16+
company = Company.new(name: 'Test Company', printer_model: 'invalid')
17+
expect(company).not_to be_valid
18+
expect(company.errors[:printer_model]).to include("must be either 'zebra' or 'tsc'")
19+
end
20+
21+
it 'allows printer_model to be nil initially' do
22+
company = Company.new(name: 'Test Company')
23+
expect(company).to be_valid
24+
end
25+
end
26+
end

0 commit comments

Comments
 (0)