Exemple #1
0
    def create(self, cr, uid, ids, datas, context={}):
        pool = pooler.get_pool(cr.dbname)
        res = pool.get("res.lang").search(cr, uid, [("code", "=", "th_TH")])
        if not res:
            raise Exception("Thai language not installed")
        lang_id = res[0]
        lang = pool.get("res.lang").browse(cr, uid, lang_id)

        period_id = datas["form"]["period_id"]
        period = pool.get("account.period").browse(cr, uid, period_id)
        fy = period.fiscalyear_id
        user = pool.get("res.users").browse(cr, uid, uid)

        year = int(fy.date_stop[:4]) + 543
        month = int(period.date_stop[5:7])

        partner = user.company_id.partner_id
        vals = {
            "place_name": partner.name,
            "year": year,
            "branch_code": "00000",
            "cb_pnd_attach": "Yes",
            "cb_tredecim": "Yes",
            "cb_ordinary_filling": "Yes",
        }

        addr = partner.address[0]
        vals.update({
            "road": addr.street,
            "district": addr.city,
            "province": addr.state_id.name or "",
            "tel": addr.phone,
        })

        ids = pool.get("account.tax.code").search(cr, uid,
                                                  [("code", "like", "PP30_")])
        for tc in pool.get("account.tax.code").browse(
                cr, uid, ids, {"period_id": period_id}):
            vals[tc.code.replace("PP30_", "tax")] = tc.sum_period

        vals.update({
            "tax1": vals["tax4"],
            "tax2": 0.0,
            "tax3": 0.0,
        })
        vals.update({
            "tax8":
            vals["tax5"] > vals["tax7"] and vals["tax5"] - vals["tax7"] or 0.0,
            "tax9":
            vals["tax7"] > vals["tax5"] and vals["tax7"] - vals["tax5"] or 0.0,
            "tax10":
            0.0,
        })
        vals.update({
            "tax11": vals["tax8"],
            "tax12": vals["tax9"],
        })
        set_satang(vals)

        vals.update({
            "head_office": "Yes",
            "ordinary_filing": "Yes",
            "zipcode": addr.zip,
            "%d" % month: "Yes",
            "tin": partner.tin and fmt_tin(partner.tin) or "",
            "tax1": str(vals["tax1"]) + " " + "%.2d" % (vals["st1"]),
            "tax2": str(vals["tax2"]) + " " + "%.2d" % (vals["st2"]),
            "tax3": str(vals["tax3"]) + " " + "%.2d" % (vals["st3"]),
            "tax4": str(vals["tax4"]) + " " + "%.2d" % (vals["st4"]),
            "tax5": str(vals["tax5"]) + " " + "%.2d" % (vals["st5"]),
            "tax6": str(vals["tax6"]) + " " + "%.2d" % (vals["st6"]),
            "tax7": str(vals["tax7"]) + " " + "%.2d" % (vals["st7"]),
            "tax8": str(vals["tax8"]) + " " + "%.2d" % (vals["st8"]),
            "tax9": str(vals["tax9"]) + " " + "%.2d" % (vals["st9"]),
            "tax10": str(vals["tax10"]) + " " + "%.2d" % (vals["st10"]),
            "tax11": str(vals["tax11"]) + " " + "%.2d" % (vals["st11"]),
            "tax12": str(vals["tax12"]) + " " + "%.2d" % (vals["st12"]),
            "pay_more": vals["tax12"] and "Yes" or "No",
        })

        pdf = pdf_fill("addons/ac_account_thai/report/pdf/vat_pp30.pdf", vals)

        # attachments for output vat
        ids = pool.get("account.move.line").search(
            cr, uid, [("tax_code_id.code", "=", "PP30_5"),
                      ("period_id", "=", period_id)])
        item_no = 0
        PAGE_SIZE = 20
        for p in range(0, len(ids), PAGE_SIZE):
            ids2 = ids[p:p + PAGE_SIZE]
            if not ids2:
                break
            vals = {
                "year": year,
                "month": month,
                "name": partner.name,
                "tin": partner.tin and partner.tin or "",
                "page_no": p / PAGE_SIZE + 1,
                "page_total": (len(ids) + PAGE_SIZE - 1) / PAGE_SIZE,
                "date": time.strftime("%d-%m-%Y"),
                "repeatIn": repeatIn,
            }
            lines = []
            total_base = 0.0
            total_tax = 0.0
            for ml in pool.get("account.move.line").browse(cr, uid, ids2):
                cust = ml.partner_id
                addr = cust.address[0]
                res = pool.get("account.move.line").search(
                    cr, uid, [("tax_code_id.code", "=", "PP30_4"),
                              ("move_id", "=", ml.move_id.id)])
                ml2_id = res[0]
                ml2 = pool.get("account.move.line").browse(cr, uid, ml2_id)
                item_no += 1
                lines.append({
                    "item_no":
                    item_no,
                    "invoice":
                    ml.invoice and ml.invoice.number or "N/A",
                    "date":
                    ml.date,
                    "customer":
                    cust.name,
                    "base":
                    lang.format("%.2f", ml2.tax_amount, grouping=True),
                    "tax":
                    lang.format("%.2f", ml.tax_amount, grouping=True),
                })
                total_base += ml2.tax_amount
                total_tax += ml.tax_amount
            vals.update({
                "lines":
                lines,
                "total_base":
                lang.format("%.2f", total_base, grouping=True),
                "total_tax":
                lang.format("%.2f", total_tax, grouping=True),
            })
            pdf2 = rml2pdf("addons/ac_account_thai/report/rml/output_vat.rml",
                           vals)
            pdf = pdf_merge(pdf, pdf2)

        # attachments for input vat
        ids = pool.get("account.move.line").search(
            cr, uid, [("tax_code_id.code", "=", "PP30_7"),
                      ("period_id", "=", period_id)])
        item_no = 0
        PAGE_SIZE = 20
        for p in range(0, len(ids), PAGE_SIZE):
            ids2 = ids[p:p + PAGE_SIZE]
            if not ids2:
                break
            vals = {
                "year": year,
                "month": month,
                "name": partner.name,
                "tin": partner.tin,
                "page_no": p / PAGE_SIZE + 1,
                "page_total": (len(ids) + PAGE_SIZE - 1) / PAGE_SIZE,
                "date": time.strftime("%Y-%m-%d"),
                "repeatIn": repeatIn,
            }
            lines = []
            total_base = 0.0
            total_tax = 0.0
            for ml in pool.get("account.move.line").browse(cr, uid, ids2):
                supp = ml.partner_id
                addr = supp.address[0]
                res = pool.get("account.move.line").search(
                    cr, uid, [("tax_code_id.code", "=", "PP30_6"),
                              ("move_id", "=", ml.move_id.id)])
                ml2_id = res[0]
                ml2 = pool.get("account.move.line").browse(cr, uid, ml2_id)
                item_no += 1
                lines.append({
                    "item_no":
                    item_no,
                    "invoice":
                    ml.invoice and ml.invoice.number or "N/A",
                    "date":
                    ml.date,
                    "supplier":
                    supp.name,
                    "base":
                    lang.format("%.2f", ml2.tax_amount, grouping=True),
                    "tax":
                    lang.format("%.2f", ml.tax_amount, grouping=True),
                })
                total_base += ml2.tax_amount
                total_tax += ml.tax_amount
            vals.update({
                "lines":
                lines,
                "total_base":
                lang.format("%.2f", total_base, grouping=True),
                "total_tax":
                lang.format("%.2f", total_tax, grouping=True),
            })
            pdf2 = rml2pdf("addons/ac_account_thai/report/rml/input_vat.rml",
                           vals)
            pdf = pdf_merge(pdf, pdf2)

        return (pdf, "pdf")
    def create(self,cr,uid,ids,datas,context={}):        
        print "WHT PND3 Attach Report" 
        pool=pooler.get_pool(cr.dbname)
        lang=pool.get("res.lang").browse(cr,uid,1)              
        user=pool.get("res.users").browse(cr,uid,uid)
        pdf = False        
        pdf2 = False
        vouch = pool.get("ineco.wht.pnd").browse(cr,uid,ids[0])          
        company = vouch.company_id        
        
        year=int(vouch.date_pnd[0:4])+543
        month=int(vouch.date_pnd[5:7]) - 1
        day=int(vouch.date_pnd[8:10])
                        
        daynow = datetime.datetime.now().day
        monthnow  = datetime.datetime.now().month
        yearnow = int(datetime.datetime.now().year)+543
        
        i = 1
        j = 1
        k = 0
        no = {}
        vat = {}
        sup_name = {}
        sup_address = {}
        sup_address2 = {}
        branch_no = {}
        wht_date = {}
        wht_name_line = {}
        wht_percent_line = {}
        wht_base_amount = {}
        wht_tax_line = {}
        vals = {}
        amount = {}
        vat_amount = {}
        
        count_line = vouch.attach_count
        pages = 1
        for line in vouch.wht_ids:
            k += 1
            no[i] = k
            vat[i] = line.partner_id.pid and fmt_tin(line.partner_id.pid) or ""
            sup_name[i] = line.partner_id.name 
            province = line.partner_id.state_id and line.partner_id.state_id.name or ""
            sup_address[i]= (line.partner_id.street or "") +"  "+ (line.partner_id.street2 or "")
            sup_address2[i]= (line.partner_id.city or "")  +"  "+ (province or "")
            branch_no[i] = line.partner_id.tax_detail or "00000"
            for wht_line in line.line_ids:
                wht_date[j] = line.date_doc and fmt_thaidate(line.date_doc) or ""                
                wht_name_line[j] = wht_line.note or ""
                wht_percent_line[j] = wht_line.percent
                wht_base_amount[j] = wht_line.base_amount
                wht_tax_line[j] =   wht_line.tax
                if amount.has_key(pages) and amount[pages]:
                    amount[pages] = amount[pages] + wht_line.base_amount
                else:
                    amount[pages] = wht_line.base_amount
                if vat_amount.has_key(pages) and vat_amount[pages]:
                    vat_amount[pages] = vat_amount[pages] + wht_line.tax
                else:
                    vat_amount[pages] = wht_line.tax

                j += 1
            j = (3 * i) + 1
            i += 1
            vals={
                    "Text42":  company.vat and fmt_tin(company.vat) or "",
                    "Text30":  company.ineco_branch or "",
                    "Text31":   pages,
                    "Text32":   vouch.attach_no,  
                    "Text46":"      "+ company.ineco_name,   
                    "Text47":"        "+ company.ineco_position,     
                    "Text48":   day,
                    "Text49":"    "+ str(month+1),  
                    "Text50":   year,   
                    "Text44":  lang.format("%.2f",amount[pages],grouping=True).replace("."," "),
                    "Text45": lang.format("%.2f", vat_amount[pages],grouping=True).replace("."," "),
#                    "Text44":  lang.format("%.2f",vouch.total_amount,grouping=True).replace("."," "),
#                    "Text45":  lang.format("%.2f", vouch.total_tax_send,grouping=True).replace("."," "),
                    "Text33.0.0": no.has_key(1) and no[1] or "",
                    "Text33.0.1": no.has_key(2) and no[2] or "",
                    "Text33.0.2": no.has_key(3) and no[3] or "",
                    "Text33.0.3": no.has_key(4) and no[4] or "",
                    "Text33.0.4": no.has_key(5) and no[5] or "",
                    "Text33.0.5": no.has_key(6) and no[6] or "",
                    "Text13.0": vat.has_key(1) and vat[1] or "",
                    "Text13.1": vat.has_key(2) and vat[2] or "",
                    "Text13.2": vat.has_key(3) and vat[3] or "",
                    "Text13.3": vat.has_key(4) and vat[4] or "",
                    "Text13.4": vat.has_key(5) and vat[5] or "",
                    "Text13.5": vat.has_key(6) and vat[6] or "",
                    #Branch No
                    "Text14.0": branch_no.has_key(1) and branch_no[1] or "",
                    "Text14.1": branch_no.has_key(2) and branch_no[2] or "",
                    "Text14.2": branch_no.has_key(3) and branch_no[3] or "",
                    "Text14.3": branch_no.has_key(4) and branch_no[4] or "",
                    "Text14.4": branch_no.has_key(5) and branch_no[5] or "",
                    "Text14.5": branch_no.has_key(6) and branch_no[6] or "",

                    "Text16.0": sup_name.has_key(1) and sup_name[1] or "",
                    "Text16.1": sup_name.has_key(2) and sup_name[2] or "",
                    "Text16.2": sup_name.has_key(3) and sup_name[3] or "",
                    "Text16.3": sup_name.has_key(4) and sup_name[4] or "",
                    "Text16.4": sup_name.has_key(5) and sup_name[5] or "",
                    "Text16.5": sup_name.has_key(6) and sup_name[6] or "",
                    "Text17.0": sup_address.has_key(1) and sup_address[1] or "",
                    "Text17.1": sup_address.has_key(2) and sup_address[2] or "",
                    "Text17.2": sup_address.has_key(3) and sup_address[3] or "",
                    "Text17.3": sup_address.has_key(4) and sup_address[4] or "",
                    "Text17.4": sup_address.has_key(5) and sup_address[5] or "",
                    "Text17.5": sup_address.has_key(6) and sup_address[6] or "",   
                    "Text18.0": sup_address2.has_key(1) and sup_address2[1] or "",
                    "Text18.1": sup_address2.has_key(2) and sup_address2[2] or "",
                    "Text18.2": sup_address2.has_key(3) and sup_address2[3] or "",
                    "Text18.3": sup_address2.has_key(4) and sup_address2[4] or "",
                    "Text18.4": sup_address2.has_key(5) and sup_address2[5] or "",
                    "Text18.5": sup_address2.has_key(6) and sup_address2[6] or "",

                    "Text19.0": wht_date.has_key(1) and wht_date[1] or "",
                    "Text25.0": wht_date.has_key(2) and wht_date[2] or "",
                    "Text36.0": wht_date.has_key(3) and wht_date[3] or "",
                    "Text19.1": wht_date.has_key(4) and wht_date[4] or "",
                    "Text25.1": wht_date.has_key(5) and wht_date[5] or "",
                    "Text36.1": wht_date.has_key(6) and wht_date[6] or "",
                    "Text19.2": wht_date.has_key(7) and wht_date[7] or "",
                    "Text25.2": wht_date.has_key(8) and wht_date[8] or "",            
                    "Text36.2": wht_date.has_key(9) and wht_date[9] or "",   
                    "Text19.3": wht_date.has_key(10) and wht_date[10] or "",  
                    "Text25.3": wht_date.has_key(11) and wht_date[11] or "",              
                    "Text36.3": wht_date.has_key(12) and wht_date[12] or "",
                    "Text19.4": wht_date.has_key(13) and wht_date[13] or "",
                    "Text25.4": wht_date.has_key(14) and wht_date[14] or "",                       
                    "Text36.4": wht_date.has_key(15) and wht_date[15] or "",                
                    "Text19.5": wht_date.has_key(16) and wht_date[16] or "",                  
                    "Text25.5": wht_date.has_key(17) and wht_date[17] or "",      
                    "Text36.5": wht_date.has_key(18) and wht_date[18] or "",

                    "Text20.0": wht_name_line.has_key(1) and wht_name_line[1] or "",
                    "Text26.0": wht_name_line.has_key(2) and wht_name_line[2] or "",
                    "Text37.0": wht_name_line.has_key(3) and wht_name_line[3] or "",
                    "Text20.1": wht_name_line.has_key(4) and wht_name_line[4] or "",
                    "Text26.1": wht_name_line.has_key(5) and wht_name_line[5] or "",
                    "Text37.1": wht_name_line.has_key(6) and wht_name_line[6] or "",
                    "Text20.2": wht_name_line.has_key(7) and wht_name_line[7] or "",
                    "Text26.2": wht_name_line.has_key(8) and wht_name_line[8] or "",
                    "Text37.2": wht_name_line.has_key(9) and wht_name_line[9] or "",  
                    "Text20.3": wht_name_line.has_key(10) and wht_name_line[10] or "",      
                    "Text26.3": wht_name_line.has_key(11) and wht_name_line[11] or "", 
                    "Text37.3": wht_name_line.has_key(12) and wht_name_line[12] or "",      
                    "Text20.4": wht_name_line.has_key(13) and wht_name_line[13] or "", 
                    "Text26.4": wht_name_line.has_key(14) and wht_name_line[14] or "", 
                    "Text37.4": wht_name_line.has_key(15) and wht_name_line[15] or "",                    
                    "Text20.5": wht_name_line.has_key(16) and wht_name_line[16] or "", 
                    "Text26.5": wht_name_line.has_key(17) and wht_name_line[17] or "", 
                    "Text37.5": wht_name_line.has_key(18) and wht_name_line[18] or "",

                    "Text21.0": wht_percent_line.has_key(1) and wht_percent_line[1] or "",
                    "Text27.0": wht_percent_line.has_key(2) and wht_percent_line[2] or "",
                    "Text38.0": wht_percent_line.has_key(3) and wht_percent_line[3] or "" ,
                    "Text21.1": wht_percent_line.has_key(4) and wht_percent_line[4] or "" ,
                    "Text27.1": wht_percent_line.has_key(5) and wht_percent_line[5] or "" ,
                    "Text38.1": wht_percent_line.has_key(6) and wht_percent_line[6] or "" ,
                    "Text21.2": wht_percent_line.has_key(7) and wht_percent_line[7] or "" ,
                    "Text27.2": wht_percent_line.has_key(8) and wht_percent_line[8] or "" ,
                    "Text38.2": wht_percent_line.has_key(9) and wht_percent_line[9] or "" ,
                    "Text21.3": wht_percent_line.has_key(10) and wht_percent_line[10] or "" ,
                    "Text27.3": wht_percent_line.has_key(11) and wht_percent_line[11] or "" ,
                    "Text38.3": wht_percent_line.has_key(12) and wht_percent_line[12] or "" ,
                    "Text21.4": wht_percent_line.has_key(13) and wht_percent_line[13] or "" ,
                    "Text27.4": wht_percent_line.has_key(14) and wht_percent_line[14] or "" ,
                    "Text38.4": wht_percent_line.has_key(15) and wht_percent_line[15] or "" ,
                    "Text21.5": wht_percent_line.has_key(16) and wht_percent_line[16] or "" ,
                    "Text27.5": wht_percent_line.has_key(17) and wht_percent_line[17] or "" ,
                    "Text38.5": wht_percent_line.has_key(18) and wht_percent_line[18] or "" ,

                    "Text22.0": wht_base_amount.has_key(1) and wht_base_amount[1] and lang.format("%.2f",wht_base_amount[1],grouping=True).replace("."," ") or "",
                    "Text28.0": wht_base_amount.has_key(2) and wht_base_amount[2] and lang.format("%.2f",wht_base_amount[2],grouping=True).replace("."," ") or "",
                    "Text39.0": wht_base_amount.has_key(3) and wht_base_amount[3] and lang.format("%.2f",wht_base_amount[3],grouping=True).replace("."," ") or "",
                    "Text22.1": wht_base_amount.has_key(4) and wht_base_amount[4] and lang.format("%.2f",wht_base_amount[4],grouping=True).replace("."," ") or "",
                    "Text28.1": wht_base_amount.has_key(5) and wht_base_amount[5] and lang.format("%.2f",wht_base_amount[5],grouping=True).replace("."," ") or "",
                    "Text39.1": wht_base_amount.has_key(6) and wht_base_amount[6] and lang.format("%.2f",wht_base_amount[6],grouping=True).replace("."," ") or "",
                    "Text22.2": wht_base_amount.has_key(7) and wht_base_amount[7] and lang.format("%.2f",wht_base_amount[7],grouping=True).replace("."," ") or "",
                    "Text28.2": wht_base_amount.has_key(8) and wht_base_amount[8] and lang.format("%.2f",wht_base_amount[8],grouping=True).replace("."," ") or "",
                    "Text39.2": wht_base_amount.has_key(9) and wht_base_amount[9]  and lang.format("%.2f",wht_base_amount[9],grouping=True).replace("."," ") or "",
                    "Text22.3": wht_base_amount.has_key(10) and wht_base_amount[10]  and lang.format("%.2f",wht_base_amount[10],grouping=True).replace("."," ") or "",
                    "Text28.3": wht_base_amount.has_key(11) and wht_base_amount[11] and lang.format("%.2f",wht_base_amount[11],grouping=True).replace("."," ") or "",
                    "Text39.3": wht_base_amount.has_key(12) and wht_base_amount[12] and lang.format("%.2f",wht_base_amount[12],grouping=True).replace("."," ") or "",
                    "Text22.4": wht_base_amount.has_key(13) and wht_base_amount[13] and lang.format("%.2f",wht_base_amount[13],grouping=True).replace("."," ") or "",
                    "Text28.4": wht_base_amount.has_key(14) and wht_base_amount[14] and lang.format("%.2f",wht_base_amount[14],grouping=True).replace("."," ") or "",
                    "Text39.4": wht_base_amount.has_key(15) and wht_base_amount[15] and lang.format("%.2f",wht_base_amount[15],grouping=True).replace("."," ") or "",
                    "Text22.5": wht_base_amount.has_key(16) and wht_base_amount[16] and lang.format("%.2f",wht_base_amount[16],grouping=True).replace("."," ") or "",
                    "Text28.5": wht_base_amount.has_key(17) and wht_base_amount[17] and lang.format("%.2f",wht_base_amount[17],grouping=True).replace("."," ") or "",
                    "Text39.5": wht_base_amount.has_key(18) and wht_base_amount[18] and lang.format("%.2f",wht_base_amount[18],grouping=True).replace("."," ") or "",

                    "Text23.0": wht_tax_line.has_key(1) and wht_tax_line[1] and lang.format("%.2f",wht_tax_line[1],grouping=True).replace("."," ") or "",
                    "Text34.0": wht_tax_line.has_key(2) and wht_tax_line[2] and lang.format("%.2f",wht_tax_line[2],grouping=True).replace("."," ") or "",
                    "Text40.0": wht_tax_line.has_key(3) and wht_tax_line[3] and lang.format("%.2f",wht_tax_line[3],grouping=True).replace("."," ") or "",
                    "Text23.1": wht_tax_line.has_key(4) and wht_tax_line[4] and lang.format("%.2f",wht_tax_line[4],grouping=True).replace("."," ") or "",
                    "Text34.1": wht_tax_line.has_key(5) and wht_tax_line[5] and lang.format("%.2f",wht_tax_line[5],grouping=True).replace("."," ") or "",
                    "Text40.1": wht_tax_line.has_key(6) and wht_tax_line[6] and lang.format("%.2f",wht_tax_line[6],grouping=True).replace("."," ") or "",
                    "Text23.2": wht_tax_line.has_key(7) and wht_tax_line[7] and lang.format("%.2f",wht_tax_line[7],grouping=True).replace("."," ") or "",
                    "Text34.2": wht_tax_line.has_key(8) and wht_tax_line[8] and lang.format("%.2f",wht_tax_line[8],grouping=True).replace("."," ") or "",
                    "Text40.2": wht_tax_line.has_key(9) and wht_tax_line[9] and lang.format("%.2f",wht_tax_line[9],grouping=True).replace("."," ") or "",
                    "Text23.3": wht_tax_line.has_key(10) and wht_tax_line[10] and lang.format("%.2f",wht_tax_line[10],grouping=True).replace("."," ") or "",
                    "Text34.3": wht_tax_line.has_key(11) and wht_tax_line[11] and lang.format("%.2f",wht_tax_line[11],grouping=True).replace("."," ") or "",
                    "Text40.3": wht_tax_line.has_key(12) and wht_tax_line[12] and lang.format("%.2f",wht_tax_line[12],grouping=True).replace("."," ") or "",
                    "Text23.4": wht_tax_line.has_key(13) and wht_tax_line[13] and lang.format("%.2f",wht_tax_line[13],grouping=True).replace("."," ") or "",
                    "Text34.4": wht_tax_line.has_key(14) and wht_tax_line[14] and lang.format("%.2f",wht_tax_line[14],grouping=True).replace("."," ") or "",
                    "Text40.4": wht_tax_line.has_key(15) and wht_tax_line[15] and lang.format("%.2f",wht_tax_line[15],grouping=True).replace("."," ") or "",
                    "Text23.5": wht_tax_line.has_key(16) and wht_tax_line[16] and lang.format("%.2f",wht_tax_line[16],grouping=True).replace("."," ") or "",
                    "Text34.5": wht_tax_line.has_key(17) and wht_tax_line[17] and lang.format("%.2f",wht_tax_line[17],grouping=True).replace("."," ") or "",
                    "Text40.5": wht_tax_line.has_key(18) and wht_tax_line[18] and lang.format("%.2f",wht_tax_line[18],grouping=True).replace("."," ") or "",

                    "Text24.0": sup_name.has_key(1) and "1" or "",
                    "Text24.1": sup_name.has_key(2) and "1" or "",
                    "Text24.2": sup_name.has_key(3) and "1" or "",
                    "Text24.3": sup_name.has_key(4) and "1" or "",
                    "Text24.4": sup_name.has_key(5) and "1" or "",
                    "Text24.5": sup_name.has_key(6) and "1" or "",
                }
            if k == count_line:              
                SITE_ROOT = os.path.abspath(os.path.dirname(__file__))
                PDF_FILE = "%s/pdf/wht_pnd53_attach.pdf" % (SITE_ROOT)
                pdf2=pdf_fill(PDF_FILE, vals)
                #pdf2 = pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_pnd53_attach.pdf",vals)
                if pdf:
                    pdf = pdf_merge(pdf, pdf2)
                else:
                    pdf = pdf2
            elif i == 7:       
                SITE_ROOT = os.path.abspath(os.path.dirname(__file__))
                PDF_FILE = "%s/pdf/wht_pnd53_attach.pdf" % (SITE_ROOT)
                pdf2=pdf_fill(PDF_FILE, vals)
                #pdf2 = pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_pnd53_attach.pdf",vals)               
                pages += 1
                i = 1
                j = 1
                ii = 0
                jj = 0
                if pdf:
                    pdf = pdf_merge(pdf, pdf2)
                else:
                    pdf = pdf2
                for irnge in range(6):
                    ii += 1 
                    no[ii] = ""
                    vat[ii] = ""
                    sup_name[ii] = ""
                    sup_address[ii]= ""
                    sup_address2[ii]= ""
                for jrnge in range(18):
                    jj += 1
                    wht_date[jj] =  False
                    wht_name_line[jj] = False
                    wht_percent_line[jj] = False
                    wht_base_amount[jj] = False
                    wht_tax_line[jj] = False

        return (pdf, "pdf")
    def create(self, cr, uid, ids, datas, context={}):
        print "WHT PND3 Attach Report"
        pool = pooler.get_pool(cr.dbname)
        lang = pool.get("res.lang").browse(cr, uid, 1)
        user = pool.get("res.users").browse(cr, uid, uid)
        pdf = False
        pdf2 = False
        vouch = pool.get("ineco.wht.pnd").browse(cr, uid, ids[0])
        company = vouch.company_id

        year = int(vouch.date_pnd[0:4]) + 543
        month = int(vouch.date_pnd[5:7]) - 1
        day = int(vouch.date_pnd[8:10])

        daynow = datetime.datetime.now().day
        monthnow = datetime.datetime.now().month
        yearnow = int(datetime.datetime.now().year) + 543

        i = 1
        j = 1
        k = 0
        no = {}
        vat = {}
        sup_name = {}
        sup_address = {}
        wht_date = {}
        wht_name_line = {}
        wht_percent_line = {}
        wht_base_amount = {}
        wht_tax_line = {}
        vals = {}
        amount = {}
        vat_amount = {}

        count_line = vouch.attach_count
        pages = 1
        for line in vouch.wht_ids:
            k += 1
            no[i] = k
            vat[i] = line.partner_id.pid and fmt_tin(line.partner_id.pid) or ""
            sup_name[i] = line.partner_id.name
            province = line.partner_id.state_id and line.partner_id.state_id.name or ""
            sup_address[i] = (line.partner_id.street or "") + " " + (
                line.partner_id.street2 or "") + " " + (
                    line.partner_id.city or "") + " " + (province or "")

            for wht_line in line.line_ids:
                wht_date[j] = line.date_doc and fmt_thaidate(
                    line.date_doc) or ""
                wht_name_line[j] = wht_line.note or ""
                wht_percent_line[j] = wht_line.percent
                wht_base_amount[j] = wht_line.base_amount
                wht_tax_line[j] = wht_line.tax
                if amount.has_key(pages) and amount[pages]:
                    amount[pages] = amount[pages] + wht_line.base_amount
                else:
                    amount[pages] = wht_line.base_amount
                if vat_amount.has_key(pages) and vat_amount[pages]:
                    vat_amount[pages] = vat_amount[pages] + wht_line.tax
                else:
                    vat_amount[pages] = wht_line.tax
                j += 1
            j = (3 * i) + 1
            i += 1
            vals = {
                "Text2.0":
                company.ineco_tax and fmt_tin(company.ineco_tax) or "",
                "Text4":
                company.ineco_branch or "",
                "Text18":
                pages,
                "Text19":
                vouch.attach_no,
                "Text21":
                "      " + (company.ineco_name or ""),
                "Text22":
                "        " + (company.ineco_position or ""),
                "Text23":
                day,
                "Text24":
                "    " + str(month + 1),
                "Text25":
                year,
                "Text9.7":
                lang.format("%.2f", amount[pages],
                            grouping=True).replace(".", " "),
                "Text10.7":
                lang.format("%.2f", vat_amount[pages],
                            grouping=True).replace(".", " "),
                #                    "Text9.7":  lang.format("%.2f",vouch.total_amount,grouping=True).replace("."," "),
                #                    "Text10.7": lang.format("%.2f", vouch.total_tax_send,grouping=True).replace("."," "),
                "Text20.0.0":
                no.has_key(1) and no[1] or "",
                "Text20.1.0":
                no.has_key(2) and no[2] or "",
                "Text20.2.0":
                no.has_key(3) and no[3] or "",
                "Text20.3.0":
                no.has_key(4) and no[4] or "",
                "Text20.4.0":
                no.has_key(5) and no[5] or "",
                "Text20.5.0":
                no.has_key(6) and no[6] or "",
                "Text2.1":
                vat.has_key(1) and vat[1] or "",
                "Text2.2":
                vat.has_key(2) and vat[2] or "",
                "Text2.3":
                vat.has_key(3) and vat[3] or "",
                "Text2.4":
                vat.has_key(4) and vat[4] or "",
                "Text2.5":
                vat.has_key(5) and vat[5] or "",
                "Text2.6":
                vat.has_key(6) and vat[6] or "",
                "Text6.0":
                sup_name.has_key(1) and sup_name[1] or "",
                "Text6.1":
                sup_name.has_key(2) and sup_name[2] or "",
                "Text6.2":
                sup_name.has_key(3) and sup_name[3] or "",
                "Text6.3":
                sup_name.has_key(4) and sup_name[4] or "",
                "Text6.4":
                sup_name.has_key(5) and sup_name[5] or "",
                "Text6.5":
                sup_name.has_key(6) and sup_name[6] or "",
                "Text8.0":
                sup_address.has_key(1) and sup_address[1] or "",
                "Text8.1":
                sup_address.has_key(2) and sup_address[2] or "",
                "Text8.2":
                sup_address.has_key(3) and sup_address[3] or "",
                "Text8.3":
                sup_address.has_key(4) and sup_address[4] or "",
                "Text8.4":
                sup_address.has_key(5) and sup_address[5] or "",
                "Text8.5":
                sup_address.has_key(6) and sup_address[6] or "",
                "Text1.0.0":
                wht_date.has_key(1) and wht_date[1] or "",
                "Text1.0.1.0":
                wht_date.has_key(2) and wht_date[2] or "",
                "Text1.0.1.1.0":
                wht_date.has_key(3) and wht_date[3] or "",
                "Text1.0.1.1.1.0":
                wht_date.has_key(4) and wht_date[4] or "",
                "Text1.0.1.1.1.1":
                wht_date.has_key(5) and wht_date[5] or "",
                "Text1.1.0":
                wht_date.has_key(6) and wht_date[6] or "",
                "Text1.1.1.0":
                wht_date.has_key(7) and wht_date[7] or "",
                "Text1.1.1.1":
                wht_date.has_key(8) and wht_date[8] or "",
                "Text1.2.0":
                wht_date.has_key(9) and wht_date[9] or "",
                "Text1.2.1.0":
                wht_date.has_key(10) and wht_date[10] or "",
                "Text1.2.1.1":
                wht_date.has_key(11) and wht_date[11] or "",
                "Text1.3.0":
                wht_date.has_key(12) and wht_date[12] or "",
                "Text1.3.1.0":
                wht_date.has_key(13) and wht_date[13] or "",
                "Text1.3.1.1":
                wht_date.has_key(14) and wht_date[14] or "",
                "Text1.4.0":
                wht_date.has_key(15) and wht_date[15] or "",
                "Text1.4.1.0":
                wht_date.has_key(16) and wht_date[16] or "",
                "Text1.4.1.1":
                wht_date.has_key(17) and wht_date[17] or "",
                "Text1.5":
                wht_date.has_key(18) and wht_date[18] or "",
                "Text12.0.0":
                wht_name_line.has_key(1) and wht_name_line[1] or "",
                "Text12.0.1.0":
                wht_name_line.has_key(2) and wht_name_line[2] or "",
                "Text12.0.1.1.0":
                wht_name_line.has_key(3) and wht_name_line[3] or "",
                "Text12.0.1.1.1.0":
                wht_name_line.has_key(4) and wht_name_line[4] or "",
                "Text12.0.1.1.1.1":
                wht_name_line.has_key(5) and wht_name_line[5] or "",
                "Text12.1.0":
                wht_name_line.has_key(6) and wht_name_line[6] or "",
                "Text12.1.1.0":
                wht_name_line.has_key(7) and wht_name_line[7] or "",
                "Text12.1.1.1":
                wht_name_line.has_key(8) and wht_name_line[8] or "",
                "Text12.2.0":
                wht_name_line.has_key(9) and wht_name_line[9] or "",
                "Text12.2.1.0":
                wht_name_line.has_key(10) and wht_name_line[10] or "",
                "Text12.2.1.1":
                wht_name_line.has_key(11) and wht_name_line[11] or "",
                "Text12.3.0":
                wht_name_line.has_key(12) and wht_name_line[12] or "",
                "Text12.3.1.0":
                wht_name_line.has_key(13) and wht_name_line[13] or "",
                "Text12.3.1.1":
                wht_name_line.has_key(14) and wht_name_line[14] or "",
                "Text12.4.0":
                wht_name_line.has_key(15) and wht_name_line[15] or "",
                "Text12.4.1.0":
                wht_name_line.has_key(16) and wht_name_line[16] or "",
                "Text12.4.1.1":
                wht_name_line.has_key(17) and wht_name_line[17] or "",
                "Text12.5":
                wht_name_line.has_key(18) and wht_name_line[18] or "",
                "Text5.0.0":
                wht_percent_line.has_key(1) and wht_percent_line[1] or "",
                "Text5.0.1.0":
                wht_percent_line.has_key(2) and wht_percent_line[2] or "",
                "Text5.0.1.1.0":
                wht_percent_line.has_key(3) and wht_percent_line[3] or "",
                "Text5.0.1.1.1.0":
                wht_percent_line.has_key(4) and wht_percent_line[4] or "",
                "Text5.0.1.1.1.1":
                wht_percent_line.has_key(5) and wht_percent_line[5] or "",
                "Text5.1.0":
                wht_percent_line.has_key(6) and wht_percent_line[6] or "",
                "Text5.1.1.0":
                wht_percent_line.has_key(7) and wht_percent_line[7] or "",
                "Text5.1.1.1":
                wht_percent_line.has_key(8) and wht_percent_line[8] or "",
                "Text5.2.0":
                wht_percent_line.has_key(9) and wht_percent_line[9] or "",
                "Text5.2.1.0":
                wht_percent_line.has_key(10) and wht_percent_line[10] or "",
                "Text5.2.1.1":
                wht_percent_line.has_key(11) and wht_percent_line[11] or "",
                "Text5.3.0":
                wht_percent_line.has_key(12) and wht_percent_line[12] or "",
                "Text5.3.1.0":
                wht_percent_line.has_key(13) and wht_percent_line[13] or "",
                "Text5.3.1.1":
                wht_percent_line.has_key(14) and wht_percent_line[14] or "",
                "Text5.4.0":
                wht_percent_line.has_key(15) and wht_percent_line[15] or "",
                "Text5.4.1.0":
                wht_percent_line.has_key(16) and wht_percent_line[16] or "",
                "Text5.4.1.1":
                wht_percent_line.has_key(17) and wht_percent_line[17] or "",
                "Text5.5":
                wht_percent_line.has_key(18) and wht_percent_line[18] or "",
                "Text9.0.0":
                wht_base_amount.has_key(1) and wht_base_amount[1]
                and lang.format("%.2f", wht_base_amount[1],
                                grouping=True).replace(".", " ") or "",
                "Text9.0.1.0":
                wht_base_amount.has_key(2) and wht_base_amount[2]
                and lang.format("%.2f", wht_base_amount[2],
                                grouping=True).replace(".", " ") or "",
                "Text9.0.1.1.0":
                wht_base_amount.has_key(3) and wht_base_amount[3]
                and lang.format("%.2f", wht_base_amount[3],
                                grouping=True).replace(".", " ") or "",
                "Text9.0.1.1.1.0":
                wht_base_amount.has_key(4) and wht_base_amount[4]
                and lang.format("%.2f", wht_base_amount[4],
                                grouping=True).replace(".", " ") or "",
                "Text9.0.1.1.1.1":
                wht_base_amount.has_key(5) and wht_base_amount[5]
                and lang.format("%.2f", wht_base_amount[5],
                                grouping=True).replace(".", " ") or "",
                "Text9.1.0":
                wht_base_amount.has_key(6) and wht_base_amount[6]
                and lang.format("%.2f", wht_base_amount[6],
                                grouping=True).replace(".", " ") or "",
                "Text9.1.1.0":
                wht_base_amount.has_key(7) and wht_base_amount[7]
                and lang.format("%.2f", wht_base_amount[7],
                                grouping=True).replace(".", " ") or "",
                "Text9.1.1.1":
                wht_base_amount.has_key(8) and wht_base_amount[8]
                and lang.format("%.2f", wht_base_amount[8],
                                grouping=True).replace(".", " ") or "",
                "Text9.2.0":
                wht_base_amount.has_key(9) and wht_base_amount[9]
                and lang.format("%.2f", wht_base_amount[9],
                                grouping=True).replace(".", " ") or "",
                "Text9.2.1.0":
                wht_base_amount.has_key(10) and wht_base_amount[10]
                and lang.format("%.2f", wht_base_amount[10],
                                grouping=True).replace(".", " ") or "",
                "Text9.2.1.1":
                wht_base_amount.has_key(11) and wht_base_amount[11]
                and lang.format("%.2f", wht_base_amount[11],
                                grouping=True).replace(".", " ") or "",
                "Text9.3.0":
                wht_base_amount.has_key(12) and wht_base_amount[12]
                and lang.format("%.2f", wht_base_amount[12],
                                grouping=True).replace(".", " ") or "",
                "Text9.3.1.0":
                wht_base_amount.has_key(13) and wht_base_amount[13]
                and lang.format("%.2f", wht_base_amount[13],
                                grouping=True).replace(".", " ") or "",
                "Text9.3.1.1":
                wht_base_amount.has_key(14) and wht_base_amount[14]
                and lang.format("%.2f", wht_base_amount[14],
                                grouping=True).replace(".", " ") or "",
                "Text9.4.0":
                wht_base_amount.has_key(15) and wht_base_amount[15]
                and lang.format("%.2f", wht_base_amount[15],
                                grouping=True).replace(".", " ") or "",
                "Text9.4.1.0":
                wht_base_amount.has_key(16) and wht_base_amount[16]
                and lang.format("%.2f", wht_base_amount[16],
                                grouping=True).replace(".", " ") or "",
                "Text9.4.1.1":
                wht_base_amount.has_key(17) and wht_base_amount[17]
                and lang.format("%.2f", wht_base_amount[17],
                                grouping=True).replace(".", " ") or "",
                "Text9.5":
                wht_base_amount.has_key(18) and wht_base_amount[18]
                and lang.format("%.2f", wht_base_amount[18],
                                grouping=True).replace(".", " ") or "",
                "Text10.0.0":
                wht_tax_line.has_key(1) and wht_tax_line[1] and lang.format(
                    "%.2f", wht_tax_line[1], grouping=True).replace(".", " ")
                or "",
                "Text10.0.1.0":
                wht_tax_line.has_key(2) and wht_tax_line[2] and lang.format(
                    "%.2f", wht_tax_line[2], grouping=True).replace(".", " ")
                or "",
                "Text10.0.1.1.0":
                wht_tax_line.has_key(3) and wht_tax_line[3] and lang.format(
                    "%.2f", wht_tax_line[3], grouping=True).replace(".", " ")
                or "",
                "Text10.0.1.1.1.0":
                wht_tax_line.has_key(4) and wht_tax_line[4] and lang.format(
                    "%.2f", wht_tax_line[4], grouping=True).replace(".", " ")
                or "",
                "Text10.0.1.1.1.1":
                wht_tax_line.has_key(5) and wht_tax_line[5] and lang.format(
                    "%.2f", wht_tax_line[5], grouping=True).replace(".", " ")
                or "",
                "Text10.1.0":
                wht_tax_line.has_key(6) and wht_tax_line[6] and lang.format(
                    "%.2f", wht_tax_line[6], grouping=True).replace(".", " ")
                or "",
                "Text10.1.1.0":
                wht_tax_line.has_key(7) and wht_tax_line[7] and lang.format(
                    "%.2f", wht_tax_line[7], grouping=True).replace(".", " ")
                or "",
                "Text10.1.1.1":
                wht_tax_line.has_key(8) and wht_tax_line[8] and lang.format(
                    "%.2f", wht_tax_line[8], grouping=True).replace(".", " ")
                or "",
                "Text10.2.0":
                wht_tax_line.has_key(9) and wht_tax_line[9] and lang.format(
                    "%.2f", wht_tax_line[9], grouping=True).replace(".", " ")
                or "",
                "Text10.2.1.0":
                wht_tax_line.has_key(10) and wht_tax_line[10] and lang.format(
                    "%.2f", wht_tax_line[10], grouping=True).replace(".", " ")
                or "",
                "Text10.2.1.1":
                wht_tax_line.has_key(11) and wht_tax_line[11] and lang.format(
                    "%.2f", wht_tax_line[11], grouping=True).replace(".", " ")
                or "",
                "Text10.3.0":
                wht_tax_line.has_key(12) and wht_tax_line[12] and lang.format(
                    "%.2f", wht_tax_line[12], grouping=True).replace(".", " ")
                or "",
                "Text10.3.1.0":
                wht_tax_line.has_key(13) and wht_tax_line[13] and lang.format(
                    "%.2f", wht_tax_line[13], grouping=True).replace(".", " ")
                or "",
                "Text10.3.1.1":
                wht_tax_line.has_key(14) and wht_tax_line[14] and lang.format(
                    "%.2f", wht_tax_line[14], grouping=True).replace(".", " ")
                or "",
                "Text10.4.0":
                wht_tax_line.has_key(15) and wht_tax_line[15] and lang.format(
                    "%.2f", wht_tax_line[15], grouping=True).replace(".", " ")
                or "",
                "Text10.4.1.0":
                wht_tax_line.has_key(16) and wht_tax_line[16] and lang.format(
                    "%.2f", wht_tax_line[16], grouping=True).replace(".", " ")
                or "",
                "Text10.4.1.1":
                wht_tax_line.has_key(17) and wht_tax_line[17] and lang.format(
                    "%.2f", wht_tax_line[17], grouping=True).replace(".", " ")
                or "",
                "Text10.5":
                wht_tax_line.has_key(18) and wht_tax_line[18] and lang.format(
                    "%.2f", wht_tax_line[18], grouping=True).replace(".", " ")
                or "",
            }
            if k == count_line:
                report_file = os.path.dirname(
                    os.path.abspath(__file__)) + "/pdf/wht_pnd3_attach.pdf"
                pdf2 = pdf_fill(report_file, vals)
                #pdf2 = pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_pnd3_attach.pdf",vals)
                if pdf:
                    pdf = pdf_merge(pdf, pdf2)
                else:
                    pdf = pdf2
            elif i == 7:
                report_file = os.path.dirname(
                    os.path.abspath(__file__)) + "/pdf/wht_pnd3_attach.pdf"
                pdf2 = pdf_fill(report_file, vals)
                #pdf2 = pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_pnd3_attach.pdf",vals)
                pages += 1
                i = 1
                j = 1
                ii = 0
                jj = 0
                if pdf:
                    pdf = pdf_merge(pdf, pdf2)
                else:
                    pdf = pdf2
                for irnge in range(6):
                    ii += 1
                    no[ii] = ""
                    vat[ii] = ""
                    sup_name[ii] = ""
                    sup_address[ii] = ""
                for jrnge in range(18):
                    jj += 1
                    wht_date[jj] = False
                    wht_name_line[jj] = False
                    wht_percent_line[jj] = False
                    wht_base_amount[jj] = False
                    wht_tax_line[jj] = False

        return (pdf, "pdf")
Exemple #4
0
    def create(self, cr, uid, ids, datas, context={}):
        #print "WHT PND3 Report"
        pool = pooler.get_pool(cr.dbname)
        lang = pool.get("res.lang").browse(cr, uid, 1)
        user = pool.get("res.users").browse(cr, uid, uid)
        pdf = False
        for id in ids:
            vouch = pool.get("account.period").browse(cr, uid, id)
            company = vouch.company_id

            yearnow = int(vouch.date_pp30[0:4]) + 543
            monthnow = int(vouch.date_pp30[5:7])
            daynow = int(vouch.date_pp30[8:10])

            #             daynow = datetime.datetime.now().day
            #             monthnow  = datetime.datetime.now().month
            #             yearnow = int(datetime.datetime.now().year)+543

            sale_untax = vouch.sale_amount_untaxed - vouch.sale_refund_amount_untaxed + (
                vouch.sale_receipt_amount_untaxed -
                vouch.sale_receipt_amount_tax)
            sale_tax = vouch.sale_amount_tax - vouch.sale_refund_amount_tax + vouch.sale_receipt_amount_tax
            purchase_untax = vouch.purchase_amount_untaxed - vouch.purchase_refund_amount_untaxed + (
                vouch.purchase_receipt_amount_untaxed -
                vouch.purchase_receipt_amount_tax)
            purchase_tax = vouch.purchase_amount_tax - vouch.purchase_refund_amount_tax + vouch.purchase_receipt_amount_tax

            vals = {
                "Text1":
                company.ineco_tax and fmt_tin(company.ineco_tax) or "",
                "Text57":
                company.ineco_branch or '',
                "name_place":
                company.ineco_company_name,
                "number":
                company.ineco_building or '',
                "room_no":
                company.ineco_room_no or '',
                "floor":
                company.ineco_class or '',
                "village":
                company.ineco_village or '',
                "add_no":
                company.ineco_no or '',
                "moo":
                company.ineco_moo or '',
                "soi":
                company.ineco_alley or '',
                "road":
                company.ineco_road or '',
                "district":
                company.ineco_district or '',
                "amphur":
                company.ineco_amphoe or '',
                "province":
                company.ineco_province or '',
                "Text58":
                company.ineco_zip or '',
                "tel":
                company.ineco_phone or '',
                "year":
                yearnow,
                "Text53":
                lang.format("%.2f", sale_untax,
                            grouping=True).replace(".", " "),
                "Text47":
                lang.format("%.2f", sale_untax,
                            grouping=True).replace(".", " "),
                "Text30":
                lang.format("%.2f", sale_tax, grouping=True).replace(".", " "),
                "Text51":
                lang.format("%.2f", purchase_untax,
                            grouping=True).replace(".", " "),
                "Text52":
                lang.format("%.2f", purchase_tax,
                            grouping=True).replace(".", " "),
                "signature4":
                company.ineco_name or '',
                "date":
                str(daynow) + "/" + str(monthnow) + "/" + str(yearnow),
            }
            if sale_tax >= purchase_tax:
                vat = sale_tax - purchase_tax
                vals.update({
                    "Text34":
                    lang.format("%.2f", vat, grouping=True).replace(".", " "),
                    "Text38":
                    lang.format("%.2f", vat, grouping=True).replace(".", " "),
                    "'Check Box11'":
                    "Yes",
                })
            else:
                vat = purchase_tax - sale_tax
                vals.update({
                    "Text35":
                    lang.format("%.2f", vat, grouping=True).replace(".", " "),
                    "Text39":
                    lang.format("%.2f", vat, grouping=True).replace(".", " "),
                    "'Check Box12'":
                    "Yes",
                })

            pdf2 = pdf_fill(
                "openerp/addons/ineco_thai_account/report/pdf/pp30.pdf", vals)
            if pdf:
                pdf = pdf_merge(pdf, pdf2)
            else:
                pdf = pdf2

        return (pdf, "pdf")
Exemple #5
0
 def create(self, cr, uid, ids, data, context={}):
     pool = pooler.get_pool(cr.dbname)
     tdy = pool.get("tdy.request").browse(cr, uid, ids[0])
     lang_id = pool.get("res.lang").search(cr, uid,
                                           [("code", "=", "en_US")])[0]
     lang = pool.get("res.lang").browse(cr, uid, lang_id)
     fields = fmt_fields(cr, uid, tdy, lang=lang)
     vals = {
         "field1":
         fmt_date(tdy.date),
         "field2":
         tdy.requester_id.lname + ", " + tdy.requester_id.fname,
         "field3":
         tdy.ssn or "",
         "field4":
         fields.get("position") or "",
         "field5":
         "USAMC-AFRIMS, BANGKOK, THAILAND",
         "field6":
         "USAMC-AFRIMS, APO AP 96546 (W2DRAA)",
         "field7":
         "02-696-2752",
         "field8":
         fields.get("auth_type") or "",
         "field9":
         tdy.purpose.find("\n") == -1 and len(tdy.purpose) <= 30
         and tdy.purpose or "See item 16. Remarks",
         "field10a":
         fields.get("num_days") or "",
         "field10b":
         fields.get("first_day") or "",
         "field11":
         fields.get("itin") or "",
         "field11v":
         "",  #"field11v": "X",
         "field13b_check":
         tdy.other_rate and "X" or "",
         "field13b":
         tdy.other_rate and "%.0f Baht/day" % tdy.other_rate or "",
         "field14a":
         fmt_amount(tdy.cost_per_diem_man or tdy.cost_per_diem, lang),
         "field14b":
         fmt_amount(tdy.cost_travel_man or tdy.cost_travel, lang),
         "field14c":
         fmt_amount(tdy.cost_other + tdy.cost_regis, lang),
         "field14d":
         fmt_amount(tdy.cost_total, lang),
         "field15":
         fmt_amount(tdy.advance_amount, lang),
         "field16":
         fields.get("remarks") or "",
         "field17":
         fields.get("request_official") or "",
         "field18":
         fields.get("approve_official") or "",
         "field19":
         fields.get("funding") or "",
         "field19b":
         fields.get("loa") or "",
         "field20":
         fields.get("authorize_official") or "",
         "field21":
         fmt_date(tdy.date),
         "field22": (tdy.po_no or "") + "   " + (tdy.doc_no or ""),
         "field16cont":
         "",
         "f12ar":
         "CR" in fields["modes"] and "X" or "",
         "f12aa":
         "CA" in fields["modes"] and "X" or "",
         "f12ab":
         "CB" in fields["modes"] and "X" or "",
         "f12as":
         "CS" in fields["modes"] and "X" or "",
         "f12ba":
         "GA" in fields["modes"] and "X" or "",
         "f12bv":
         "GV" in fields["modes"] and "X" or "",
         "f12bs":
         "GS" in fields["modes"] and "X" or "",
         "f12cc":
         "LC" in fields["modes"] and "X" or "",
         "f12ct":
         "LT" in fields["modes"] and "X" or "",
         "f12co":
         "LO" in fields["modes"] and "X" or "",
     }
     pdf = pdf_fill("addons/ac_afrims/report/pdf/form_1610.pdf", vals)
     return (pdf, "pdf")
Exemple #6
0
    def create(self,cr,uid,ids,datas,context={}):
        #print "WHT PND3 Report"      
        pool=pooler.get_pool(cr.dbname)
        lang=pool.get("res.lang").browse(cr,uid,1)      
        user=pool.get("res.users").browse(cr,uid,uid)
        pdf = False
        for id in ids:
            vouch = pool.get("account.period").browse(cr,uid,id)          
            company = vouch.company_id
            
            yearnow=int(vouch.date_pp30[0:4])+543
            monthnow=int(vouch.date_pp30[5:7])
            daynow=int(vouch.date_pp30[8:10])
                            
#             daynow = datetime.datetime.now().day
#             monthnow  = datetime.datetime.now().month
#             yearnow = int(datetime.datetime.now().year)+543
                        
                
            sale_untax = vouch.sale_amount_untaxed - vouch.sale_refund_amount_untaxed + (vouch.sale_receipt_amount_untaxed - vouch.sale_receipt_amount_tax)
            sale_tax = vouch.sale_amount_tax - vouch.sale_refund_amount_tax + vouch.sale_receipt_amount_tax
            purchase_untax = vouch.purchase_amount_untaxed - vouch.purchase_refund_amount_untaxed + (vouch.purchase_receipt_amount_untaxed - vouch.purchase_receipt_amount_tax)
            purchase_tax = vouch.purchase_amount_tax - vouch.purchase_refund_amount_tax + vouch.purchase_receipt_amount_tax
            
    
            vals={
                "Text1":company.vat and fmt_tin(company.vat) or "",
                "Text57":company.ineco_branch or '',
                "name_place":company.ineco_company_name,                
                "number":company.ineco_building or '',
                "room_no":company.ineco_room_no or '',
                "floor":company.ineco_class or '',
                "village":company.ineco_village or '',
                "add_no":company.ineco_no or '',
                "moo":company.ineco_moo or '',
                "soi":company.ineco_alley or '',
                "road":company.ineco_road or '',
                "district":company.ineco_district or '',
                "amphur":company.ineco_amphoe or '',
                "province":company.ineco_province or '',
                "Text58":company.ineco_zip or '',
                "tel":company.ineco_phone or '',
                "year":yearnow,
                "Text53":lang.format("%.2f",sale_untax,grouping=True).replace("."," "),
                "Text47":lang.format("%.2f",sale_untax,grouping=True).replace("."," "),
                "Text30":lang.format("%.2f",sale_tax,grouping=True).replace("."," "),
                "Text51":lang.format("%.2f",purchase_untax,grouping=True).replace("."," "),
                "Text52":lang.format("%.2f",purchase_tax,grouping=True).replace("."," "),       
                "signature4": company.ineco_name or '',
                "date":str(daynow)+"/"+ str(monthnow)+"/"+ str(yearnow),   
              
            }
            if sale_tax >= purchase_tax:
                vat = sale_tax - purchase_tax
                vals.update({
                             "Text34":lang.format("%.2f",vat,grouping=True).replace("."," "),
                             "Text38":lang.format("%.2f",vat,grouping=True).replace("."," "), 
                             "'Check Box11'": "Yes",
                             })
            else:
                vat = purchase_tax - sale_tax
                vals.update({
                             "Text35":lang.format("%.2f",vat,grouping=True).replace("."," "),
                             "Text39":lang.format("%.2f",vat,grouping=True).replace("."," "), 
                             "'Check Box12'": "Yes",
                             })                

            SITE_ROOT = os.path.abspath(os.path.dirname(__file__))
            PDF_FILE = "%s/pdf/pp30.pdf" % (SITE_ROOT)
            pdf2=pdf_fill(PDF_FILE, vals)

            #pdf2=pdf_fill("openerp/addons/ineco_thai_account/report/pdf/pp30.pdf",vals)
            if pdf:
                pdf = pdf_merge(pdf, pdf2)
            else:
                pdf = pdf2
                
        return (pdf, "pdf")
Exemple #7
0
Fichier : pr.py Projet : worwear/af
    def create(self, cr, uid, ids, data, context={}):
        limit = 4  #pr_lines limit in reports
        pool = pooler.get_pool(cr.dbname)
        vals = {}
        lang_id = pool.get("res.lang").search(cr, uid,
                                              [("code", "=", "en_US")])[0]
        lang = pool.get("res.lang").browse(cr, uid, lang_id)
        pr = pool.get("purchase.request").browse(cr, uid, ids[0])
        fields = fmt_fields(cr, uid, pr, lang=lang)
        cont_lines = len(pr.lines) >= limit
        cont_purpose = fields["purpose"].count("\n") > 3
        need_cont = cont_lines or cont_purpose
        num_pg = need_cont and 2 or 1
        vals = {
            "field1":
            "WT0J3Y",
            "field1b":
            pr.name,
            "field2":
            pr.doc_no or "",
            "field3":
            fields["date"],
            #"field4": "PURCHASING AND CONTRACTING OFFICER, USAMC-AFRIMS",
            "field4":
            "Purchasing & Contracting Officer\n US Embassy Thailand (GSO)\n APO AP 96546",
            #"field5": "CHIEF, DEPARTMENT OF LOGISTICS, USAMC-AFRIMS",
            "field5":
            "Department of Logistics Procurement \n USAMD-AFRIMS \n APO AP 96546",
            "field6":
            fields["from"],
            #"field7": "USAMC-AFRIMS APO AP 96546",
            "field7":
            "Department of Virology\n USAMD-AFRIMS, APO AP 96546",
            "field8":
            fields["deliver_to"],
            "field9":
            fields["no_later"],
            "field10":
            fields["field10"],
            #"field11": pr.purch_admin_id.dl or "",
            "field11":
            pr.purch_admin_id.dl + " #" + pr.purch_admin_id.phone_ext or "",
            "field12":
            "X",
            "field12_1":
            "AR 710-2",
            "field25":
            not cont_purpose and fields["purpose"]
            or "**See continuation sheet**",
            "field14":
            "",
            "field15":
            "",
            "field15h":
            pr.description or "",
            "field18ah":
            pr.lines[0].currency_id.name,
            "field18bh":
            pr.lines[0].currency_id.name,
            #"field15b": "Suggested supplier:\n"+fields["supplier"],#TODO:Fix this
            "field16":
            "",
            "field17":
            "",
            "field19":
            fields["funding"],
            "field18a":
            "",
            "field18b":
            "",
            "field27":
            fields["dept_chief"].upper(),
            "field29":
            fields["dept_chief_date"],
            "field30":
            fields["dept_chief_phone"],
            "field28":
            fields["dept_chief_sign"],
            #"field20": fields["budget_chief"],
            "field20":
            "Chadchadaporn P.\n Budget Analyst, FSN-9",
            "field22":
            fields["budget_chief_date"],
            "field21":
            fields["budget_chief_sign"],
            #"field31": fields["logis_chief"].upper(),
            "field31":
            fields["field31"],
            "field33":
            fields["logis_chief_date"],
            "field32":
            fields["logis_chief_sign"],
            "field34":
            fields["field34"],
            "pa":
            1,
            "po":
            num_pg,
        }
        for line in pr.lines[:limit]:
            newline = get_newline(
                line.product_id and line.product_id.name_get()[0][1]
                or line.name, 35)

            vals["field14"] += "%d" % line.sequence + newline
            vals["fiels15"] = ""
            vals["field16"] += "%.2f" % line.qty + newline
            vals["field17"] += "%s" % line.uom_id.name + newline
            #vals["field18ah"]+= pr.currency_id.name,
            vals["field18a"] += "%s" % lang.format(
                "%.2f", line.price_unit, grouping=True) + newline
            vals["field18b"] += "%s" % lang.format(
                "%.2f", line.subtotal, grouping=True) + newline
            #vals["field18a"]+="%s"%lang.format("%.2f",line.price_unit,grouping=True)+newline
            #vals["field18b"]+="%s"%lang.format("%f",line.subtotal)+newline
            if (line.product_id):
                vals["field15"] += "%s" % (
                    line.product_id.name_get()[0][1]) + "\n"
            else:
                vals["field15"] += "%s" % (line.name) + "\n"
        if len(pr.lines) < limit:
            #vals["field15"]+="**See continuation sheet**\n"
            vals["field15"] += "\nSuggested Supplier\n" + fields[
                'supplier'] + "\n\n"

        # because of some problem in PDF fields in IE...
        vals["field8n"] = vals["field8"]
        vals["field11n"] = vals["field11"]
        vals["field15n"] = vals["field15"]
        vals["field16n"] = vals["field16"]
        vals["field30n"] = vals["field30"]

        from pprint import pprint
        pprint(vals)

        pdf = pdf_fill("addons/ac_afrims/report/pdf/form_3953.pdf", vals)
        if not need_cont:
            return (pdf, "pdf")
        vals = {
            "line_item": "",
            "line_supplies": "",
            "line_quantity": "",
            "line_unit": "",
            "line_unit_price": "",
            "line_amount": "",
        }
        if cont_lines:
            # suggested section
            line_suggested = "Suggested Supplier\n" + fields[
                'supplier'] + "\n\n"
            vals["line_supplies"] += line_suggested
            line_start = "\n" * line_suggested.count('\n')
            vals["line_item"] += line_start
            vals["line_quantity"] += line_start
            vals["line_unit"] += line_start
            vals["line_unit_price"] += line_start
            vals["line_amount"] += line_start
            #line loop
            for line in pr.lines[limit:]:
                newline = get_newline(
                    line.product_id and line.product_id.name_get()[0][1]
                    or line.name, 65)

                vals["line_item"] += "%d" % line.sequence + newline
                vals["line_supplies"] += "%s\n" % (
                    line.product_id and line.product_id.name_get()[0][1]
                    or line.name)
                vals["line_quantity"] += "%.2f" % line.qty + newline
                vals["line_unit"] += "%s" % line.uom_id.name + newline
                vals["line_unit_price"] += "%s" % lang.format(
                    "%.2f", line.price_unit, grouping=True) + newline
                vals["line_amount"] += "%s" % lang.format(
                    "%.2f", line.subtotal, grouping=True) + newline

            if cont_purpose:
                vals["line_supplies"] + "\n"
        if cont_purpose:
            vals["line_supplies"] += "Purpose:\n" + fields["purpose"]
        pdf_cont = pdf_fill("addons/ac_afrims/report/pdf/form_336.pdf", vals)
        pdf_all = pdf_merge(pdf, pdf_cont)
        return (pdf_all, "pdf")
Exemple #8
0
Fichier : pr.py Projet : worwear/af
    def create(self, cr, uid, ids, data, context={}):
        pool = pooler.get_pool(cr.dbname)
        lang_id = pool.get("res.lang").search(cr, uid,
                                              [("code", "=", "en_US")])[0]
        lang = pool.get("res.lang").browse(cr, uid, lang_id)
        pr = pool.get("purchase.request").browse(cr, uid, ids[0])
        records = []

        line_per_page = 12
        start = 0
        total_page = int(math.ceil(len(pr.lines) / 12.0))

        for page in range(total_page):
            vals = {
                "issue":
                "X",
                "field1":
                pr.doc_no or "",
                "field3":
                "Department of Logistics, USAMC-AFRIMS, Supply Room Officer, Attn: Khun Supoj",
                "field4":
                "",
                "field8":
                "%s, %s" %
                (pr.department_id.long_name or "", pr.requester_id.full_name),
                "field13d":
                pr.date,
                "field9":
                pr.name,
                "field13by":
                pr.purch_admin_id.full_name,
            }

            vals['page_no'] = page + 1
            i = 0
            for line in pr.lines[start:start + line_per_page]:
                i += 1
                vals.update({
                    "fa%d" % i:
                    line.sequence,
                    "fb%d" % i:
                    line.product_id and line.product_id.default_code or "",
                    "fc%d" % i:
                    line.product_id and line.product_id.name
                    or line.name,  #XXX
                    "fd%d" % i:
                    line.uom_id.name,
                    "fe%d" % i:
                    "%.2f" % line.qty,
                    "fjb%d" % i:
                    top_projects(line),
                    "fjd%d" % i:
                    line.notes or '',  #pass, #weng edit
                })
            if int(page) == int(total_page) - 1:
                vals["fc%d" % (i + 1)] = "*** Nothing Follows ***"
            start += line_per_page
            records.append(vals)

        pdf_all = ''
        for r in records:
            if not pdf_all:
                pdf_all = pdf_fill("addons/ac_afrims/report/pdf/form_3161.pdf",
                                   r)
            else:
                pdf_all = pdf_merge(
                    pdf_all,
                    pdf_fill("addons/ac_afrims/report/pdf/form_3161.pdf", r))

        return (pdf_all, "pdf")
Exemple #9
0
    def create(self, cr, uid, ids, datas, context={}):
        #print "WHT PND3 Report"
        pool = pooler.get_pool(cr.dbname)
        lang = pool.get("res.lang").browse(cr, uid, 1)
        user = pool.get("res.users").browse(cr, uid, uid)
        pdf = False
        for id in ids:
            vouch = pool.get("ineco.wht.pnd").browse(cr, uid, id)
            company = vouch.company_id

            year = int(vouch.period_tax_id.date_start[0:4]) + 543
            month = int(vouch.date_pnd[5:7]) - 2
            if month == -1:
                month = 11
            #print month
            year_sign = int(vouch.date_pnd[0:4]) + 543
            #month=int(vouch.date_pnd[5:7]) - 1
            #month=int(vouch.date_pnd[5:7]) - 2
            month_sign = int(vouch.date_pnd[5:7])

            day = int(vouch.date_pnd[8:10])

            daynow = datetime.datetime.now().day
            monthnow = datetime.datetime.now().month
            yearnow = int(datetime.datetime.now().year) + 543

            typepnd = 0
            section3 = ""
            section65 = ""
            section69 = ""
            attachpnd = ""

            if vouch.type_normal == True:
                typepnd = 0
            else:
                typepnd = 1
            if vouch.section_3 == True:
                section3 = "Yes"
            if vouch.section_65 == True:
                section65 = "Yes"
            if vouch.section_69 == True:
                section69 = "Yes"
            if vouch.attach_pnd == True:
                attachpnd = "Yes"

            vals = {
                "Text2":
                company.ineco_tax and fmt_tin(company.ineco_tax) or "",
                "Text4":
                company.ineco_branch or '',
                "Text5":
                company.ineco_company_name,
                "Text6":
                company.ineco_building or '',
                "Text7":
                company.ineco_room_no or '',
                "Text8":
                company.ineco_class or '',
                "Text9":
                company.ineco_village or '',
                "Text10":
                company.ineco_no or '',
                "Text11":
                company.ineco_moo or '',
                "Text12":
                company.ineco_alley or '',
                "Text13":
                company.ineco_road or '',
                "Text14":
                company.ineco_district or '',
                "Text15":
                company.ineco_amphoe or '',
                "Text16":
                company.ineco_province or '',
                "Text17":
                company.ineco_zip or '',
                "Text18":
                company.ineco_phone or '',
                "Text19":
                vouch.attach_count,
                "Text22":
                year,
                "Text46":
                vouch.attach_no,
                "Text51.2":
                lang.format("%.2f", vouch.total_amount,
                            grouping=True).replace(".", " "),
                "Text51.3":
                lang.format("%.2f", vouch.total_tax,
                            grouping=True).replace(".", " "),
                "Text51.4":
                lang.format("%.2f", vouch.add_amount,
                            grouping=True).replace(".", " "),
                "Text51.5":
                lang.format("%.2f", vouch.total_tax_send,
                            grouping=True).replace(".", " "),
                "Text55":
                "      " + company.ineco_position,
                "Text54":
                "      " + company.ineco_name,
                "Text56":
                day,
                "Text57":
                "    " + str(month_sign),
                "Text58":
                year_sign,
                "'Check Box6'":
                section3,
                "'Check Box8'":
                section65,
                "'Check Box7'":
                section69,
                "'Check Box36'":
                attachpnd,
                "'Radio Button23'":
                month,
                "'Radio Button19'":
                typepnd,
            }
            report_file = os.path.dirname(
                os.path.abspath(__file__)) + "/pdf/wht_pnd53.pdf"
            pdf2 = pdf_fill(report_file, vals)
            #pdf2=pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_pnd53.pdf",vals)
            if pdf:
                pdf = pdf_merge(pdf, pdf2)
            else:
                pdf = pdf2

        return (pdf, "pdf")
Exemple #10
0
    def create(self, cr, uid, ids, datas, context={}):
        #print "WHT certificate report"
        pool = pooler.get_pool(cr.dbname)
        lang = pool.get("res.lang").browse(cr, uid, 1)
        user = pool.get("res.users").browse(cr, uid, uid)
        pdf = False
        for id in ids:
            vouch = pool.get("ineco.wht").browse(cr, uid, id)
            partner = vouch.company_id.partner_id
            supp = vouch.partner_id

            year = int(vouch.date_doc[0:4]) + 543
            month = int(vouch.date_doc[5:7])
            day = int(vouch.date_doc[8:10])

            totals = {}
            #totals[line.tax_code_id.code]=vouch.base_amount
            #print "totals",totals

            vals = {
                "name1": partner.name,
                "add1": fmt_addr(partner) or "",
                "tin1": partner.pid or "",
                "id1": partner.vat and fmt_tin(partner.vat) or "",
                "name2": supp.name,
                "add2": supp and fmt_addr(supp) or "",
                #"tin1_2": supp.pid or "",
                #"id1_2": supp.vat and fmt_tin(supp.vat) or "",
                "id1_2": fmt_tin(supp.pid) or "",
                "tin1_2": supp.vat and fmt_tin(supp.vat) or "",
                #"chk4": supp.vat and "Yes" or "",
                #"chk7": supp.pid and "Yes" or "",
                "chk4": vouch.wht_kind == 'pp3' and "Yes" or "",
                "chk7": vouch.wht_kind == 'pp7' and "Yes" or "",
                "date_pay": day,
                "month_pay": month,
                "year_pay": year,
            }
            #book_no
            vals.update({'book_no': '1'})
            #run no
            vals.update({'run_no': vouch.id})
            #ภงด
            #         vals.update({
            #             'chk1': "Yes",
            #             'chk2': "Yes",
            #             'chk3': "Yes",
            #             'chk5': "Yes",
            #             'chk6': "Yes",
            #             'chk7': "Yes",
            #         })
            if vouch.wht_kind == 'pp1':
                vals.update({'chk1': "Yes"})
            if vouch.wht_kind == 'pp2':
                vals.update({'chk2': "Yes"})
            if vouch.wht_kind == 'pp3':
                vals.update({'chk3': "Yes"})
            if vouch.wht_kind == 'pp4':
                vals.update({'chk4': "Yes"})
            if vouch.wht_kind == 'pp5':
                vals.update({'chk5': "Yes"})
            if vouch.wht_kind == 'pp6':
                vals.update({'chk6': "Yes"})
            if vouch.wht_kind == 'pp7':
                vals.update({'chk7': "Yes"})
            #ด้านล่าง

    #         vals.update({
    #             'chk8': "Yes",
    #             'chk9': "Yes",
    #             'chk10': "Yes",
    #             'chk11': "Yes",
    #         })
            if vouch.wht_payment == 'pm1':
                vals.update({'chk8': "Yes"})
            if vouch.wht_payment == 'pm2':
                vals.update({'chk9': "Yes"})
            if vouch.wht_payment == 'pm3':
                vals.update({'chk10': "Yes"})
            if vouch.wht_payment == 'pm4':
                vals.update({'chk11': "Yes"})

            #Item No
            vals.update({'item': vouch.seq or ""})

            #Spec unknow
            #vals.update({'spec1':'1'}) #Other 1
            #vals.update({'spec3':'2'}) #Other 2
            #vals.update({'spec4':'3'}) #Other 3

            total_base = vouch.base_amount
            total_tax = vouch.tax

            for line in vouch.line_ids:
                year = int(line.date_doc[0:4]) + 543
                month = int(line.date_doc[5:7])
                day = int(line.date_doc[8:10])
                if line.wht_type_id.seq == 100:
                    vals.update({
                        "date1":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.0":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.0":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 200:
                    vals.update({
                        "date2":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.1":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.1":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 300:
                    vals.update({
                        "date3":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.2":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.2":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 400:
                    vals.update({
                        "date4":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.3":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.3":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 411:
                    vals.update({
                        "date5":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.4":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.4":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 412:
                    vals.update({
                        "date6":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.5":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.5":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 413:
                    vals.update({
                        "date7":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.6":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.6":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 414:
                    vals.update({
                        #rate1
                        "rate1":
                        "",
                        "date8":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.7":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.7":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 421:
                    vals.update({
                        "date9":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.8":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.8":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 422:
                    vals.update({
                        "date10":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.9":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.9":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 423:
                    vals.update({
                        "date11":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.10":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.10":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 425:
                    vals.update({
                        "spec1":
                        line.name,
                        "date12":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.11":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.11":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 500:
                    vals.update({
                        "date13":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.12":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.12":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })
                if line.wht_type_id.seq == 600:
                    vals.update({
                        "spec3":
                        line.note or vouch.note or line.wht_type_id.printed
                        or 'ค่าบริการ',
                        "date14":
                        "%d-%d-%d" % (day, month, year),
                        "pay1.13":
                        lang.format("%.2f", line.base_amount,
                                    grouping=True).replace(".", " "),
                        "tax1.13":
                        lang.format("%.2f", line.tax,
                                    grouping=True).replace(".", " "),
                    })

            vals.update({
                "pay1.14":
                lang.format("%.2f", total_base,
                            grouping=True).replace(".", " "),
                "tax1.14":
                lang.format("%.2f", total_tax,
                            grouping=True).replace(".", " "),
                "total":
                num2word_th(total_tax, "th").decode('utf-8'),
            })

            report_file = os.path.dirname(
                os.path.abspath(__file__)) + "/pdf/wht_certif.pdf"
            pdf2 = pdf_fill(report_file, vals)
            #pdf2=pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_certif.pdf",vals)
            if pdf:
                pdf = pdf_merge(pdf, pdf2)
            else:
                pdf = pdf2
        return (pdf, "pdf")
Exemple #11
0
    def create(self,cr,uid,ids,datas,context={}):
        pool=pooler.get_pool(cr.dbname)

        res=pool.get("res.lang").search(cr,uid,[("code","=","th_TH")])
        if not res:
            raise Exception("Thai language not installed")
        lang_id=res[0]
        lang=pool.get("res.lang").browse(cr,uid,lang_id)

        period_id=datas["form"]["period_id"]
        period=pool.get("account.period").browse(cr,uid,period_id)
        fy=period.fiscalyear_id
        user=pool.get("res.users").browse(cr,uid,uid)

        year=int(fy.date_stop[:4])+543
        month=int(period.date_stop[5:7])

        partner=user.company_id.partner_id
        addr=partner.address[0]

        vals={
            "name": partner.name,
            "year": year,
            #"section3": "X",
            "branch_code":"00000",
            "cb_pnd_attach":"Yes",
            "cb_tredecim":"Yes",
            "cb_ordinary_filling":"Yes",
            "road": addr.street,
            "district": addr.city,
            "province": addr.state_id.name,
            "tel": addr.phone,
        }

        ids=pool.get("account.tax.code").search(cr,uid,[("code","like","PND53_")])
        for tc in pool.get("account.tax.code").browse(cr,uid,ids,{"period_id":period_id}):
            vals[tc.code.replace("PND53_","tax")]=tc.sum_period

        vals.update({
            "tax3": 0.0,
            "tax4": vals["tax2"],
        })
        print vals
        vals.update({
            "%d"%month: "Yes",
            "zipcode":addr.zip,
            "tin":partner.tin and fmt_tin(partner.tin) or "",
            "tax1":lang.format("%.2f",vals["tax1"],grouping=True).replace("."," "),
            "tax2":lang.format("%.2f",vals["tax2"],grouping=True).replace("."," "),
            "tax3":lang.format("%.2f",vals["tax3"],grouping=True).replace("."," "),
            "tax4":lang.format("%.2f",vals["tax4"],grouping=True).replace("."," "),
        })
            
        pdf=pdf_fill("addons/ac_account_thai/report/pdf/wht_pnd53.pdf",vals)

        # fill attachments

        tax_code_id=pool.get("account.tax.code").search(cr,uid,[("code","=","PND53_2")])
        base_code_id=pool.get("account.tax.code").search(cr,uid,[("code","=","PND53_1")])

        # find all lines to show in attachments
        ids=pool.get("account.move.line").search(cr,uid,[("tax_code_id","child_of","PND53_2"),("period_id","=",period_id)],order="date")

        # group lines by suppliers
        supp_lines = {}
        for ml in pool.get("account.move.line").browse(cr,uid,ids):
            supp_lines.setdefault(ml.partner_id,[]).append(ml)

        # create list of rows to show in attachments
        rows=[]
        for supp,lines in supp_lines.items():
            for i in range(0,len(lines),3):
                rows.append((lines[i].date,supp,lines[i:i+3]))

        # sort rows by date
        rows=sorted(rows)

        # display rows on pages
        ROWS_PER_PAGE=7
        num_pages=(len(rows)+ROWS_PER_PAGE-1)/ROWS_PER_PAGE
        row_no=0
        for j in range(0,len(rows),ROWS_PER_PAGE):
            vals={
                "tin": partner.tin and fmt_tin(partner.tin) or "",
                "branch_code":"00000",
                "page_no": j/ROWS_PER_PAGE+1,
                "page_total": num_pages,
            }
            page_rows=rows[j:j+ROWS_PER_PAGE]

            i=0
            base_page=0.0
            tax_page=0.0
            for row in page_rows:
                i+=1
                supp=row[1]
                lines=row[2]
                row_no+=1
                vals.update({
                    "no%d"%i: str(row_no),
                    "line%d_tin"%i: supp.tin and fmt_tin(supp.tin) or "",
                    "line%d_name"%i: supp.name,
                    "line%d_branch_code"%i:"00000",
                    "line%d_addr1"%i: fmt_addr1(addr),
                    "line%d_addr2"%i: fmt_addr2(addr),
                })
                ii=0
                for ml_tax in lines:
                    ii+=1
                    res=pool.get("account.move.line").search(cr,uid,[("tax_code_id","child_of",base_code_id),("move_id","=",ml_tax.move_id.id)])
                    ml_base=res and pool.get("account.move.line").browse(cr,uid,res[0]) or None
                    vals.update({
                        "line%d_date%d"%(i,ii): fmt_thaidate(ml_tax.date),
                        "line%d_type%d"%(i,ii): ml_tax.name,
                        "line%d_base%d"%(i,ii): ml_base and lang.format("%.2f",ml_base.tax_amount,grouping=True).replace("."," ") or "",
                        "line%d_rate%d"%(i,ii): ml_base and "%.0f%%"%(ml_tax.tax_amount*100.0/ml_base.tax_amount) or "",
                        "line%d_tax%d"%(i,ii): lang.format("%.2f",ml_tax.tax_amount,grouping=True).replace("."," "),
                        "line%d_cond%d"%(i,ii): "1",
                    })
                    base_page+=ml_base and ml_base.tax_amount or 0.0
                    tax_page+=ml_tax.tax_amount
            vals.update({
                "Text42_21": lang.format("%.2f",base_page,grouping=True).replace("."," "),
                "Text43_21": lang.format("%.2f",tax_page,grouping=True).replace("."," "),
            })
            pdf2=pdf_fill("addons/ac_account_thai/report/pdf/wht_pnd53_attach.pdf",vals)
            pdf=pdf_merge(pdf,pdf2)
        return (pdf,"pdf")
Exemple #12
0
    def create(self,cr,uid,ids,datas,context={}):
        #print "WHT PND3 Report"      
        pool=pooler.get_pool(cr.dbname)
        lang=pool.get("res.lang").browse(cr,uid,1)      
        user=pool.get("res.users").browse(cr,uid,uid)
        pdf = False
        for id in ids:
            vouch = pool.get("ineco.wht.pnd").browse(cr,uid,id)          
            company = vouch.company_id
            
            year=int(vouch.date_pnd[0:4])+543
            #month=int(vouch.date_pnd[5:7]) - 1
            #month=int(vouch.date_pnd[5:7]) - 2
            month=int(vouch.period_tax_id.date_start[5:7]) - 1
            month_sign = int(vouch.date_pnd[5:7])
            if month == -1: 
                month = 11
            if month == 11:
                month_radio = 11
                year = year - 1 
            elif month == 0:
                month_radio = 1
            elif month == 1:
                month_radio = 2
            elif month == 2:
                month_radio = 3
            else:
                month_radio = month

            day=int(vouch.date_pnd[8:10])
                            
            daynow = datetime.datetime.now().day
            monthnow  = datetime.datetime.now().month 
            yearnow = int(datetime.datetime.now().year)+543
                   
            typepnd = 0
            section3 = ""
            section48 = ""
            section50 = ""
            attachpnd = ""
            
            if vouch.type_normal == True:
                typepnd = 0
            else:
                typepnd = 1
            if  vouch.section_3 == True:
                section3 = "Yes"
            if  vouch.section_48 == True:
                section48 = "Yes"
            if  vouch.section_50 == True:
                section50 = "Yes"        
            if  vouch.attach_pnd == True:
                attachpnd = "Yes"             
    
            vals={
                "Text2":company.vat and fmt_tin(company.vat) or "",
                "Text4":company.ineco_branch or '',
                "Text5":company.ineco_company_name,
                "Text6":company.ineco_building or '',
                "Text7":company.ineco_room_no or '',
                "Text8":company.ineco_class or '',
                "Text9":company.ineco_village or '',
                "Text10":company.ineco_no or '',
                "Text11":company.ineco_moo or '',
                "Text12":company.ineco_alley or '',
                "Text13":company.ineco_road or '',
                "Text14":company.ineco_district or '',
                "Text15":company.ineco_amphoe or '',
                "Text16":company.ineco_province or '',
                "Text17":company.ineco_zip or '',
                "Text18":company.ineco_phone or '',
                "Text19":vouch.attach_count,
                "Text22":year,
                "Text46":vouch.attach_no,
                "Text51.2":lang.format("%.2f",vouch.total_amount,grouping=True).replace("."," "),
                "Text51.3":lang.format("%.2f",vouch.total_tax,grouping=True).replace("."," "),
                "Text51.4":lang.format("%.2f",vouch.add_amount,grouping=True).replace("."," "),
                "Text51.5":lang.format("%.2f",vouch.total_tax_send,grouping=True).replace("."," "),
                "Text55":"      "+ company.ineco_position,
                "Text54":"      "+ company.ineco_name,
                "Text56":day,  
                "Text57":"    "+ str(month_sign),  
                "Text58":yearnow,   
                "'Check Box6'": section3,
                "'Check Box7'": section48,
                "'Check Box8'": section50,
                "'Check Box36'": attachpnd,
                "'Radio Button23'": month_radio ,
                "'Radio Button19'":typepnd ,
            }
            #may = 0, #june = 4
    
            SITE_ROOT = os.path.abspath(os.path.dirname(__file__))
            PDF_FILE = "%s/pdf/wht_pnd3.pdf" % (SITE_ROOT)
            pdf2=pdf_fill(PDF_FILE, vals)
            #pdf2=pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_pnd3.pdf",vals)
            if pdf:
                pdf = pdf_merge(pdf, pdf2)
            else:
                pdf = pdf2
                
        return (pdf, "pdf")
Exemple #13
0
    def create(self,cr,uid,ids,datas,context={}):
        pool=pooler.get_pool(cr.dbname)
        res=pool.get("res.lang").search(cr,uid,[("code","=","th_TH")])
        if not res:
            raise Exception("Thai language not installed")
        lang_id=res[0]
        lang=pool.get("res.lang").browse(cr,uid,lang_id)

        period_id=datas["form"]["period_id"]
        period=pool.get("account.period").browse(cr,uid,period_id)
        fy=period.fiscalyear_id
        user=pool.get("res.users").browse(cr,uid,uid)

        year=int(fy.date_stop[:4])+543
        month=int(period.date_stop[5:7])

        partner=user.company_id.partner_id
        vals={
            "place_name": partner.name,
            "year": year,
            "branch_code":"00000",
            "cb_pnd_attach":"Yes",
            "cb_tredecim":"Yes",
            "cb_ordinary_filling":"Yes",
        }

        addr=partner.address[0]
        vals.update({
            "road": addr.street,
            "district": addr.city,
            "province": addr.state_id.name or "",
            "tel": addr.phone,
        })

        ids=pool.get("account.tax.code").search(cr,uid,[("code","like","PP30_")])
        for tc in pool.get("account.tax.code").browse(cr,uid,ids,{"period_id":period_id}):
            vals[tc.code.replace("PP30_","tax")]=tc.sum_period

        vals.update({
            "tax1": vals["tax4"],
            "tax2": 0.0,
            "tax3": 0.0,
        })
        vals.update({
            "tax8": vals["tax5"]>vals["tax7"] and vals["tax5"]-vals["tax7"] or 0.0,
            "tax9": vals["tax7"]>vals["tax5"] and vals["tax7"]-vals["tax5"] or 0.0,
            "tax10": 0.0,
        })
        vals.update({
            
            "tax11": vals["tax8"],
            "tax12": vals["tax9"],
        })
        set_satang(vals)

        vals.update({
            "head_office": "Yes",
            "ordinary_filing": "Yes",
            "zipcode":addr.zip,
            "%d"%month: "Yes",
            "tin":partner.tin and fmt_tin(partner.tin) or "",
            "tax1":str(vals["tax1"])+" "+"%.2d"%(vals["st1"]),
            "tax2":str(vals["tax2"])+" "+"%.2d"%(vals["st2"]),
            "tax3":str(vals["tax3"])+" "+"%.2d"%(vals["st3"]),
            "tax4":str(vals["tax4"])+" "+"%.2d"%(vals["st4"]),
            "tax5":str(vals["tax5"])+" "+"%.2d"%(vals["st5"]),
            "tax6":str(vals["tax6"])+" "+"%.2d"%(vals["st6"]),
            "tax7":str(vals["tax7"])+" "+"%.2d"%(vals["st7"]),
            "tax8":str(vals["tax8"])+" "+"%.2d"%(vals["st8"]),
            "tax9":str(vals["tax9"])+" "+"%.2d"%(vals["st9"]),
            "tax10":str(vals["tax10"])+" "+"%.2d"%(vals["st10"]),
            "tax11":str(vals["tax11"])+" "+"%.2d"%(vals["st11"]),
            "tax12":str(vals["tax12"])+" "+"%.2d"%(vals["st12"]),
            "pay_more": vals["tax12"] and "Yes" or "No",
        })

        pdf=pdf_fill("addons/ac_account_thai/report/pdf/vat_pp30.pdf",vals)

        # attachments for output vat
        ids=pool.get("account.move.line").search(cr,uid,[("tax_code_id.code","=","PP30_5"),("period_id","=",period_id)])
        item_no=0
        PAGE_SIZE=20
        for p in range(0,len(ids),PAGE_SIZE):
            ids2=ids[p:p+PAGE_SIZE]
            if not ids2:
                break
            vals={
                "year": year,
                "month": month,
                "name": partner.name,
                "tin": partner.tin and partner.tin or "",
                "page_no": p/PAGE_SIZE+1,
                "page_total": (len(ids)+PAGE_SIZE-1)/PAGE_SIZE,
                "date": time.strftime("%d-%m-%Y"),
                "repeatIn": repeatIn,
            }
            lines=[]
            total_base=0.0
            total_tax=0.0
            for ml in pool.get("account.move.line").browse(cr,uid,ids2):
                cust=ml.partner_id
                addr=cust.address[0]
                res=pool.get("account.move.line").search(cr,uid,[("tax_code_id.code","=","PP30_4"),("move_id","=",ml.move_id.id)])
                ml2_id=res[0]
                ml2=pool.get("account.move.line").browse(cr,uid,ml2_id)
                item_no+=1
                lines.append({
                    "item_no": item_no,
                    "invoice": ml.invoice and ml.invoice.number or "N/A",
                    "date": ml.date,
                    "customer": cust.name,
                    "base": lang.format("%.2f",ml2.tax_amount,grouping=True),
                    "tax": lang.format("%.2f",ml.tax_amount,grouping=True),
                })
                total_base+=ml2.tax_amount
                total_tax+=ml.tax_amount
            vals.update({
                "lines": lines,
                "total_base": lang.format("%.2f",total_base,grouping=True),
                "total_tax": lang.format("%.2f",total_tax,grouping=True),
            })
            pdf2=rml2pdf("addons/ac_account_thai/report/rml/output_vat.rml",vals)
            pdf=pdf_merge(pdf,pdf2)

        # attachments for input vat
        ids=pool.get("account.move.line").search(cr,uid,[("tax_code_id.code","=","PP30_7"),("period_id","=",period_id)])
        item_no=0
        PAGE_SIZE=20
        for p in range(0,len(ids),PAGE_SIZE):
            ids2=ids[p:p+PAGE_SIZE]
            if not ids2:
                break
            vals={
                "year": year,
                "month": month,
                "name": partner.name,
                "tin": partner.tin,
                "page_no": p/PAGE_SIZE+1,
                "page_total": (len(ids)+PAGE_SIZE-1)/PAGE_SIZE,
                "date": time.strftime("%Y-%m-%d"),
                "repeatIn": repeatIn,
            }
            lines=[]
            total_base=0.0
            total_tax=0.0
            for ml in pool.get("account.move.line").browse(cr,uid,ids2):
                supp=ml.partner_id
                addr=supp.address[0]
                res=pool.get("account.move.line").search(cr,uid,[("tax_code_id.code","=","PP30_6"),("move_id","=",ml.move_id.id)])
                ml2_id=res[0]
                ml2=pool.get("account.move.line").browse(cr,uid,ml2_id)
                item_no+=1
                lines.append({
                    "item_no": item_no,
                    "invoice": ml.invoice and ml.invoice.number or "N/A",
                    "date": ml.date,
                    "supplier": supp.name,
                    "base": lang.format("%.2f",ml2.tax_amount,grouping=True),
                    "tax": lang.format("%.2f",ml.tax_amount,grouping=True),
                })
                total_base+=ml2.tax_amount
                total_tax+=ml.tax_amount
            vals.update({
                "lines": lines,
                "total_base": lang.format("%.2f",total_base,grouping=True),
                "total_tax": lang.format("%.2f",total_tax,grouping=True),
            })
            pdf2=rml2pdf("addons/ac_account_thai/report/rml/input_vat.rml",vals)
            pdf=pdf_merge(pdf,pdf2)

        return (pdf,"pdf")
 def create(self, cr, uid, ids, datas, context={}):
     #print "WHT certificate report"
     pool=pooler.get_pool(cr.dbname)
     lang=pool.get("res.lang").browse(cr,uid,1)
     user=pool.get("res.users").browse(cr,uid,uid)
     pdf = False
     for id in ids:
         vouch = pool.get("ineco.wht").browse(cr,uid,id)
         partner = vouch.company_id.partner_id
         supp = vouch.partner_id
 
         year=int(vouch.date_doc[0:4])+543
         month=int(vouch.date_doc[5:7])
         day=int(vouch.date_doc[8:10])
 
         totals={}
         #totals[line.tax_code_id.code]=vouch.base_amount
         #print "totals",totals
 
         vals={
             "name1": partner.name,
             "add1": fmt_addr(partner) or "",
             "tin1": partner.pid or "",
             "id1": partner.vat and fmt_tin(partner.vat) or "",
             "name2": supp.name,
             "add2": supp and fmt_addr(supp) or "",
             #"tin1_2": supp.pid or "",
             #"id1_2": supp.vat and fmt_tin(supp.vat) or "",
             "id1_2": fmt_tin(supp.pid) or "",
             "tin1_2": supp.vat and fmt_tin(supp.vat) or "",
             #"chk4": supp.vat and "Yes" or "",
             #"chk7": supp.pid and "Yes" or "",
             "chk4": vouch.wht_kind == 'pp3' and "Yes" or "",
             "chk7": vouch.wht_kind == 'pp7' and "Yes" or "",
             "date_pay": day,
             "month_pay": month,
             "year_pay": year,
         }
         #book_no
         vals.update({'book_no':'1'})
         #run no
         vals.update({'run_no':vouch.id})
         #ภงด
 #         vals.update({
 #             'chk1': "Yes",
 #             'chk2': "Yes",
 #             'chk3': "Yes",
 #             'chk5': "Yes",
 #             'chk6': "Yes",
 #             'chk7': "Yes",
 #         })
         if vouch.wht_kind == 'pp1':
             vals.update({'chk1': "Yes"})
         if vouch.wht_kind == 'pp2':
             vals.update({'chk2': "Yes"})
         if vouch.wht_kind == 'pp3':
             vals.update({'chk3': "Yes"})
         if vouch.wht_kind == 'pp4':
             vals.update({'chk4': "Yes"})
         if vouch.wht_kind == 'pp5':
             vals.update({'chk5': "Yes"})
         if vouch.wht_kind == 'pp6':
             vals.update({'chk6': "Yes"})
         if vouch.wht_kind == 'pp7':
             vals.update({'chk7': "Yes"})
         #ด้านล่าง
 #         vals.update({
 #             'chk8': "Yes",
 #             'chk9': "Yes",
 #             'chk10': "Yes",
 #             'chk11': "Yes",
 #         })
         if vouch.wht_payment == 'pm1':
             vals.update({'chk8': "Yes"})
         if vouch.wht_payment == 'pm2':
             vals.update({'chk9': "Yes"})
         if vouch.wht_payment == 'pm3':
             vals.update({'chk10': "Yes"})
         if vouch.wht_payment == 'pm4':
             vals.update({'chk11': "Yes"})
         
         #Item No
         vals.update({'item':vouch.seq or ""})
         
         #Spec unknow
         #vals.update({'spec1':'1'}) #Other 1
         #vals.update({'spec3':'2'}) #Other 2
         #vals.update({'spec4':'3'}) #Other 3
         
         total_base=vouch.base_amount
         total_tax=vouch.tax
 
         for line in vouch.line_ids:
             year = int(line.date_doc[0:4])+543
             month = int(line.date_doc[5:7])
             day = int(line.date_doc[8:10])
             if line.wht_type_id.seq == 100:
                 vals.update({
                     "date1": "%d-%d-%d"%(day,month,year),
                     "pay1.0": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.0": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 200:
                 vals.update({
                     "date2": "%d-%d-%d"%(day,month,year),
                     "pay1.1": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.1": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 300:
                 vals.update({
                     "date3": "%d-%d-%d"%(day,month,year),
                     "pay1.2": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.2": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 400:
                 vals.update({
                     "date4": "%d-%d-%d"%(day,month,year),
                     "pay1.3": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.3": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 411:
                 vals.update({
                     "date5": "%d-%d-%d"%(day,month,year),
                     "pay1.4": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.4": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 412:
                 vals.update({
                     "date6": "%d-%d-%d"%(day,month,year),
                     "pay1.5": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.5": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 413:
                 vals.update({
                     "date7": "%d-%d-%d"%(day,month,year),
                     "pay1.6": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.6": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 414:
                 vals.update({
                     #rate1
                     "rate1": "",
                     "date8": "%d-%d-%d"%(day,month,year),
                     "pay1.7": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.7": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 421:
                 vals.update({
                     "date9": "%d-%d-%d"%(day,month,year),
                     "pay1.8": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.8": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 422:
                 vals.update({
                     "date10": "%d-%d-%d"%(day,month,year),
                     "pay1.9": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.9": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 423:
                 vals.update({
                     "date11": "%d-%d-%d"%(day,month,year),
                     "pay1.10": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.10": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 425:
                 vals.update({
                     "spec1": line.name,
                     "date12": "%d-%d-%d"%(day,month,year),
                     "pay1.11": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.11": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 500:
                 vals.update({
                     "date13": "%d-%d-%d"%(day,month,year),
                     "pay1.12": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.12": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
             if line.wht_type_id.seq == 600:
                 vals.update({
                     "spec3": line.note or vouch.note or line.wht_type_id.printed or 'ค่าบริการ',
                     "date14": "%d-%d-%d"%(day,month,year),
                     "pay1.13": lang.format("%.2f",line.base_amount,grouping=True).replace("."," "),
                     "tax1.13": lang.format("%.2f",line.tax,grouping=True).replace("."," "),
                 })
 
         vals.update({
             "pay1.14": lang.format("%.2f",total_base,grouping=True).replace("."," "),
             "tax1.14": lang.format("%.2f",total_tax,grouping=True).replace("."," "),
             "total": num2word_th(total_tax,"th").decode('utf-8'),
         })
 
         report_file = os.path.dirname(os.path.abspath(__file__))+"/pdf/wht_certif.pdf"
         pdf2=pdf_fill(report_file,vals)
         #pdf2=pdf_fill("openerp/addons/ineco_thai_account/report/pdf/wht_certif.pdf",vals)
         if pdf:
             pdf = pdf_merge(pdf, pdf2)
         else:
             pdf = pdf2
     return (pdf, "pdf")
Exemple #15
0
    def create(self,cr,uid,ids,datas,context={}):
        print "WHT certificate report"
        pool=pooler.get_pool(cr.dbname)

        res=pool.get("res.lang").search(cr,uid,[("code","=","th_TH")])
        if not res:
            raise Exception("Thai language not installed")
        lang_id=res[0]
        lang=pool.get("res.lang").browse(cr,uid,lang_id)

        user=pool.get("res.users").browse(cr,uid,uid)
        partner=user.company_id.partner_id
        vouch=pool.get("account.voucher").browse(cr,uid,ids[0])
        supp=vouch.partner_id

        year=int(vouch.date[0:4])+543
        month=int(vouch.date[5:7])
        day=int(vouch.date[8:10])

        totals={}
        if vouch.move_id:
            for line in vouch.move_id.line_id:
                if line.tax_code_id:
                    totals[line.tax_code_id.code]=totals.get(line.tax_code_id,0.0)+line.tax_amount
        #print "totals",totals

        vals={
            "name1": partner.name,
            "add1": partner.address and fmt_addr(partner.address[0]) or "",
            "tin1": partner.tin and fmt_tin(partner.tin) or "",
            "id1": partner.pin or "",
            "name2": supp.name,
            "add2": supp.address and fmt_addr(supp.address[0]) or "",
            "tin1_2": supp.tin and fmt_tin(supp.tin) or "",
            "id1_2": supp.pin or "",
            "chk4": supp.pin and "Yes" or "",
            "chk7": supp.tin and "Yes" or "",
            "date_pay": day,
            "month_pay": month,
            "year_pay": year,
        }

        total_base=0.0
        total_tax=0.0

        tax=totals.get("50_PND3_5_TAX",0.0) or totals.get("50_PND53_5_TAX")
        if tax:
            base=totals.get("50_PND3_5_BASE",0.0) or totals.get("50_PND53_5_BASE",0.0)
            vals.update({
                "date13": "%d-%d-%d"%(day,month,year),
                "pay1.12": lang.format("%.2f",base,grouping=True).replace("."," "),
                "tax1.12": lang.format("%.2f",tax,grouping=True).replace("."," "),
            })
            total_base+=base
            total_tax+=tax

        tax=totals.get("50_PND3_6_TAX",0.0) or totals.get("50_PND53_6_TAX")
        if tax:
            base=totals.get("50_PND3_6_BASE",0.0) or totals.get("50_PND53_6_BASE",0.0)
            vals.update({
                "date14": "%d-%d-%d"%(day,month,year),
                "pay1.13": lang.format("%.2f",base,grouping=True).replace("."," "),
                "tax1.13": lang.format("%.2f",tax,grouping=True).replace("."," "),
            })
            total_base+=base
            total_tax+=tax

        vals.update({
            "pay1.14": lang.format("%.2f",total_base,grouping=True).replace("."," "),
            "tax1.14": lang.format("%.2f",total_tax,grouping=True).replace("."," "),
            "total": num2word_th(int(total_tax),"th").decode('utf-8'),
        })

        pdf=pdf_fill("addons/ac_account_thai/report/pdf/wht_certif.pdf",vals)
        return (pdf,"pdf")