Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Daisy auto fix open doc
  • Loading branch information
AlexVangelov committed Dec 20, 2015
1 parent 1c208ba commit db54c72
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,6 @@
## 0.5.4
- Daisy auto fix open doc

## 0.5.3
- Daisy/Datecs do not stop on invalid sequence if correct one is next

Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
extface (0.5.3)
extface (0.5.4)
redis
redis-namespace

Expand Down
4 changes: 4 additions & 0 deletions app/models/extface/driver/base/fiscal.rb
Expand Up @@ -54,6 +54,8 @@ def sale_and_pay_items_session(sale_items = [], operator = '', password = '') ra

#other
def payed_recv_account(value = 0.00, payment_type_num = 0) raise_not_implemented end

def autofix_unclosed_doc() nil end #if applicable

class SaleItem
include ActiveModel::Validations
Expand All @@ -78,6 +80,7 @@ def fiscalize(bill, detailed = false)
if detailed
device.session("Fiscal Doc") do |s|
s.notify "Fiscal Doc Start"
s.autofix_unclosed_doc
s.open_fiscal_doc(operator_mapping.try(:mapping), operator_mapping.try(:pwd))
s.notify "Register Sale"
bill.charges.each do |charge|
Expand Down Expand Up @@ -117,6 +120,7 @@ def fiscalize(bill, detailed = false)
else #not detailed
device.session("Fiscal Doc") do |s|
s.notify "Fiscal Doc Start"
s.autofix_unclosed_doc
s.open_fiscal_doc(operator_mapping.try(:mapping), operator_mapping.try(:pwd))
s.notify "Register Sale"
total_modifier = nil # send payments sum, so modifier make no sence! think
Expand Down
11 changes: 11 additions & 0 deletions app/models/extface/driver/daisy_fx1200.rb
Expand Up @@ -175,6 +175,15 @@ def cancel_doc_session
s.notify "Doc Cancel End"
end
end

def autofix_unclosed_doc
if @last_fp_status
unless (@last_fp_status[2].ord & 0x20).zero? and (@last_fp_status[2].ord & 0x08).zero?
fsend Sales::CANCEL_DOC
autocut
end
end
end

#other
def autocut(partial = true) # return "P" - success, "F" - failed
Expand Down Expand Up @@ -212,8 +221,10 @@ def fsend(cmd, data = "") #return data or nil
push packet_data
ACKS_MAX_WAIT.times do |retries|
errors.clear
@last_fp_status = nil
if resp = frecv(RESPONSE_TIMEOUT)
if resp.valid?
@last_fp_status = resp.status
human_status_errors(resp.status)
if errors.empty?
result = resp.data
Expand Down
2 changes: 1 addition & 1 deletion lib/extface/version.rb
@@ -1,3 +1,3 @@
module Extface
VERSION = "0.5.3"
VERSION = "0.5.4"
end
21 changes: 20 additions & 1 deletion test/models/extface/driver/daisy_fx1200_test.rb
Expand Up @@ -46,7 +46,8 @@ class Driver::DaisyFx1200Test < ActiveSupport::TestCase
job = extface_jobs(:one)
job_thread = Thread.new do
@driver.set_job(job)
result = @driver.fsend(0x2C) # paper move command
@driver.autofix_unclosed_doc #should not affect test
@driver.fsend(0x2C) # paper move command
end
simulate_device_pull(job)
@driver.handle("\x01\x31\x20\x4A\x88\x80\xC0\x80\x80\xB8\x04\x88\x80\xC0\x80\x80\xB8\x05\x30\x37\x3A\x34\x03\x01\x31\x20\x4A\x88\x80\xC0\x80\x80\xB8\x04\x88\x80\xC0\x80\x80\xB8\x05\x30\x37\x3A\x34\x03".b)
Expand All @@ -60,6 +61,7 @@ class Driver::DaisyFx1200Test < ActiveSupport::TestCase
job = extface_jobs(:one)
job_thread = Thread.new do
@driver.set_job(job)
@driver.autofix_unclosed_doc #should not affect test
result = @driver.fsend(0x2C) # paper move command
end
simulate_device_pull(job)
Expand All @@ -71,6 +73,23 @@ class Driver::DaisyFx1200Test < ActiveSupport::TestCase
job_thread.join
assert @driver.errors.empty?
end

test "autofix unclosed doc" do
job = extface_jobs(:one)
job_thread = Thread.new do
@driver.set_job(job)
@driver.autofix_unclosed_doc
end
# status byte 2 bit 3 (fiscal doc open) 80 80 88 80 80 B8
assert_equal simulate_device_pull(job).b[3].ord, @driver.class::Info::STATUS
@driver.handle("\x01\x31\x20\x4A\x80\x80\x88\x80\x80\xB8\x04\x80\x80\x88\x80\x80\xB8\x05\x30\x37\x32\x34\x03")
assert_equal simulate_device_pull(job).b[3].ord, @driver.class::Sales::CANCEL_DOC
@driver.handle("\x01\x38\x21\x30\x30\x30\x30\x30\x31\x36\x2C\x30\x30\x30\x30\x31\x35\x04\x80\x80\x88\x80\x80\xB8\x05\x30\x36\x34\x3B\x03")
assert_equal simulate_device_pull(job).b[3].ord, @driver.class::Printer::CUT
@driver.handle("\x01\x2B\x22\x34\x04\x80\x80\x88\x80\x80\xB8\x05\x30\x33\x3C\x3A\x03")
job_thread.join
assert @driver.errors.empty?
end
end
end

Expand Down
11 changes: 10 additions & 1 deletion test/test_helper.rb
Expand Up @@ -21,7 +21,16 @@ class ActiveSupport::TestCase
fixtures :all

def simulate_device_pull(job)
Extface.redis_block{ |r| sleep 1; r.publish(job.id, "OK") } #simulate send to device
result = nil
Extface.redis_block do |r|
list, data = r.blpop(job.id, timeout: 1)
while data
result = data
r.publish(job.id, "OK")
list, data = r.blpop(job.id, timeout: 1)
end
end #simulate send to device
result
end
end
module Extface
Expand Down

0 comments on commit db54c72

Please sign in to comment.