Skip to content
  • Categories
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse

Odoo 中文社区

  1. Home
  2. Categories
  3. Odoo 开发与实施交流
  4. ODOO14 批次列印QR碼

ODOO14 批次列印QR碼

Scheduled Pinned Locked Moved Odoo 开发与实施交流
7 Posts 3 Posters 938 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samchou
    wrote on last edited by
    #1

    現行完成報表列印QR碼
    是先轉成PDF再列印
    要一張一張展開PDF然後列印到印表機
    效率極差
    請問有甚麼辦法批次列印不透過轉成PDF直接丟去印表機列印嗎?

    digitalsatoriD 1 Reply Last reply
    0
    • digitalsatoriD Offline
      digitalsatoriD Offline
      digitalsatori 管理员
      replied to samchou on last edited by
      #2

      @samchou 用下面这个addons就可以啊:

      https://github.com/OCA/report-print-send/tree/14.0/base_report_to_printer

      【上海先安科技】(tony AT openerp.cn)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        samchou
        wrote on last edited by
        #3

        windows 下無法安裝pycups套件
        導致無法安裝base_report_to_printer套件

        S 1 Reply Last reply
        0
        • S Offline
          S Offline
          samchou
          replied to samchou on last edited by samchou
          #4

          已解決
          使用
          c1394da5-0411-41b6-b2d7-409732a4b8de-圖片.png

          1 Reply Last reply
          0
          • S Offline
            S Offline
            samchou
            wrote on last edited by samchou
            #5
            ### 連續產生QR碼並直接列印至印表機
            import win32print
            import win32ui
            import win32con
            import qrcode
            import odoorpc
            from PIL import Image,ImageWin
            
            db_ip = '192.168.122.X'
            db_name = 'test'
            user_name = ''
            user_password = ''
            
            # Prepare the connection to the server
            odoo = odoorpc.ODOO(db_ip, port=8069)
            # Login
            odoo.login(db_name,user_name,user_password)
            Wt = odoo.env['workticket.wt']
            wt_ids = Wt.search([('wt_status', '=', 'Y')])
            for wt in Wt.browse(wt_ids):
                if wt.wk_status == 'N' :
                    total_prt = wt.total_prt + 1
                    part_descp = wt.parts.part_descp
                    pack_qty = format(int(wt.pack_qty), '.3f')  ##顯示小數點下三位
                    NQRCode = wt.name+'_'+wt.style+'_'+part_descp+'_'+wt.color+'_'+wt.size+'_'+wt.materiel+'_'+str(pack_qty)+'_'+str(total_prt)
                    qr = qrcode.QRCode(
                        version=3,
                        error_correction=qrcode.constants.ERROR_CORRECT_L,
                        box_size=100,
                        border=4,
                    )
                    qr.make(fit=True)
                    qr.add_data(NQRCode)
                    img = qr.make_image(fill_color="black", back_color="white")
                    printer_name = win32print.GetDefaultPrinter ()
                    hDC = win32ui.CreateDC ()
                    hDC.CreatePrinterDC (printer_name)
                    hDC.StartDoc ('QR')
                    hDC.StartPage ()
                    dib = ImageWin.Dib (img)
                    # 第一行
                    x1 = 15
                    y1 = 5
                    x2 = 485
                    y2 = 50
                    # 圖片
                    x11 = 305
                    y11 = 50
                    x12 = 485
                    y12 = 230
                    font = win32ui.CreateFont({
                        "name": "Arial",
                        # "underline": True, 底線
                        "height": 42,
                        "weight": 42,
                    })
                    show = wt.style 
                    hDC.SelectObject(font)
                    hDC.DrawText (show,(x1,y1,x2,y2), win32con.DT_LEFT)
                    
                    dib.draw (hDC.GetHandleOutput (),(x11,y11,x12,y12))
            
                    hDC.EndPage ()
                    hDC.EndDoc ()
                    hDC.DeleteDC ()
            

            直接寫成一個PY檔能確實執行
            但是把同樣程式寫入odoo內
            列印卻出現空白

            1 Reply Last reply
            0
            • S Offline
              S Offline
              samchou
              wrote on last edited by
              #6

              已解決
              要在程式內設定紙張格式大小

              digitalsatoriD 1 Reply Last reply
              0
              • digitalsatoriD Offline
                digitalsatoriD Offline
                digitalsatori 管理员
                replied to samchou on last edited by
                #7

                @samchou 感谢你的信息更新

                【上海先安科技】(tony AT openerp.cn)

                1 Reply Last reply
                0

                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Tags
                • Popular
                • Users
                • Groups