Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

cannot print Txt file to dot matrix printer using os.system

By
rudyanto santoso
on 6/17/16, 5:27 PM 265 views

I have create custom module for v8 to print picking list using dot matrix printer.

My server using windows 7, so I run "NET USE LPT1: \\computername\printername", and the server successfully printing txt file to my remote dot matrix printer using command "Type namefile.txt > PRN".

And then from the server i execute "os.system("type namefile.txt > PRN"  using python command-line and also successfull to print the text file.

The problem is when I put that code on odoo custom modul, it is not working

Here is my code :

class stock_picking(models.Model):

_inherit = 'stock.picking'

def cetak(self, cr, uid, ids, context):

# Mendefinikan template report berdasarkan path modul terkait

tpl = tpl_lookup.get_template('picking.txt')

tpl_line = tpl_lookup.get_template('picking_line.txt')

# Mempersiapkan data-data yang diperlukan

user = self.pool.get('res.users').browse(cr, uid, uid)

order = self.browse(cr, uid, ids)[0]

date = time.strftime('%d/%m/%Y %H:%M', time.strptime(order.date,'%Y-%m-%d %H:%M:%S'))

tglo=order.date

no = 0

rows = []

for line in order.move_lines:

no += 1

s = tpl_line.render(no=str(no),

code="Kode Barang", #line.product_id.code,

uom=line.product_uom.name,

name=line.product_id.name_template, #line.product_id.name_template,

desk = line.product_tmpl_id.description.strip()[:49],

qty="{:,.0f}".format(line.product_uom_qty).replace(",","."))

rows.append(s)

# Merender data yang telah disiapkan ke dalam template report text

s = tpl.render(id=order.nomor_do, #order.name,

tgl=tglo[8:10]+"-"+tglo[5:7]+"-"+tglo[:4],

pelanggan=order.partner_id.name,

alamat=order.partner_id.street,

kota=order.partner_id.city,

rows=rows,

po=order.origin,

do=order.no_pesan,

tglp=order.tgl_pesan,

nmp=order.nama_pesan,

user='('+ user.name +')')

# Membuat temporary file yang akan dicetak beserta pathnya

filename = 'c:/temp/%s.txt' % uid

filename2 = '"c:\\temp\%s.txt"' % uid

filename3 = '"c:\\temp\\text.txt"'

# Mengisi file tersebut dengan data yang telah dirender

f = open(filename, 'w')

f.write(s)

f.close()

# Proses cetak dijalankan dan pastikan variabel nama_printer adalah nama printer yang anda setting atau tambahkan dengan webmin diatas

os.system("type %s > PRN:%filename2    #first

os.system('type %s > %s' % (filename2,filename3)) #second

# Hapus file yang telah dicetak

os.remove(filename)

return True

The first one cannot print the text file to remote printer, but the second one successfully create a backup file. Both of them using the same syntax, but different destination.

Are there any solustion ??

0
rudyanto santoso
On 6/17/16, 5:41 PM

there is a typo

the correct one is :

os.system("type %s > PRN"%filename2)    #first

os.system('type %s > %s' % (filename2,filename3)) #second

sorry, i cnnot edit the original post--error 403

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 6/17/16, 5:27 PM
Seen: 265 times
Last updated: 6/17/16, 8:24 PM