Esempio n. 1
0
def enqueue_print_slips(kwargs):
    console("Start Printing")
    payroll_entry = kwargs
    ss_data = frappe.get_all("Salary Slip",
                             filters={"payroll_entry": payroll_entry})
    ss_list = []
    for i in ss_data:
        ss_list.append(i.name)
    doctype = dict({"Salary Slip": ss_list})
    print_format = ""
    default_print_format = frappe.db.get_value(
        'Property Setter',
        dict(property='default_print_format', doc_type="Salary Slip"), "value")
    if default_print_format:
        print_format = default_print_format
    else:
        print_format = "Standard"

    pdf = download_multi_pdf(doctype,
                             payroll_entry,
                             format=print_format,
                             no_letterhead=0)
    if pdf:
        ret = frappe.get_doc({
            "doctype": "File",
            "attached_to_doctype": "Payroll Entry",
            "attached_to_name": payroll_entry,
            "folder": "Home/Attachments",
            "file_name": payroll_entry + ".pdf",
            "file_url": "/files/" + payroll_entry + ".pdf",
            "content": pdf
        })
        ret.save(ignore_permissions=1)
        console("Printing Finished", "The PDF file is ready in attatchments")
        return ret
Esempio n. 2
0
def download_multi_pdf(doctype, name, format=None, no_letterhead=0):
    output = PdfFileWriter()
    if isinstance(doctype, dict):
        for doctype_name in doctype:
            for doc_name in doctype[doctype_name]:
                try:
                    console(doc_name)
                    output = frappe.get_print(
                        doctype_name, doc_name, format, as_pdf=True, output=output, no_letterhead=no_letterhead)
                except Exception:
                    frappe.log_error("Permission Error on doc {} of doctype {}".format(
                        doc_name, doctype_name))
        frappe.local.response.filename = "{}.pdf".format(name)

    return read_multi_pdf(output)
Esempio n. 3
0
    def get_buying_amount(self, row, item_code):
        console("in buying amount", item_code)
        # IMP NOTE
        # stock_ledger_entries should already be filtered by item_code and warehouse and
        # sorted by posting_date desc, posting_time desc
        if item_code in self.non_stock_items and (row.project
                                                  or row.cost_center):
            #Issue 6089-Get last purchasing rate for non-stock item
            item_rate = self.get_last_purchase_rate(item_code, row)
            console("non stock items item_rate", item_rate)

            return flt(row.qty) * item_rate

        else:
            my_sle = self.sle.get((item_code, row.warehouse))
            if (row.update_stock or row.dn_detail) and my_sle:
                parenttype, parent = row.parenttype, row.parent
                if row.dn_detail:
                    parenttype, parent = "Delivery Note", row.delivery_note

                for i, sle in enumerate(my_sle):
                    # find the stock valution rate from stock ledger entry
                    if sle.voucher_type == parenttype and parent == sle.voucher_no and \
                     sle.voucher_detail_no == row.item_row:
                        previous_stock_value = len(my_sle) > i+1 and \
                         flt(my_sle[i+1].stock_value) or 0.0

                        if previous_stock_value:
                            return (previous_stock_value -
                                    flt(sle.stock_value)) * flt(row.qty) / abs(
                                        flt(sle.qty))
                        else:
                            return flt(row.qty) * self.get_average_buying_rate(
                                row, item_code)
                    else:
                        console("unknown criteria hit", sle.voucher_type,
                                parenttype, parent, sle.voucher_no,
                                sle.voucher_detail_no, row.item_row)
            else:
                console("NO update stock or dn detail and no my_sel")
                return flt(row.qty) * self.get_average_buying_rate(
                    row, item_code)

        console("0 returned as no matching code")
        return 0.0
def make_withholding_tax_gl_entries_for_purchase(doc, method):
    withholding_payable_account, default_currency, auto_create_for_purchase_withholding = frappe.get_value("Company", doc.company, ["default_withholding_payable_account","default_currency","auto_create_for_purchase_withholding"])
    if not auto_create_for_purchase_withholding:
        return
    float_precision = cint(frappe.db.get_default("float_precision")) or 3
    withholding_payable_account, default_currency = frappe.get_value("Company", doc.company, ["default_withholding_payable_account","default_currency"])
    if not withholding_payable_account:
        frappe.throw(_("Please Setup Withholding Payable Account in Company " + str(doc.company)))
    for item in doc.items:
        if not item.withholding_tax_rate > 0:
            continue
        withholding_payable_account_type = frappe.get_value("Account", withholding_payable_account, "account_type") or ""
        if withholding_payable_account_type != "Payable":
            frappe.msgprint( _("Withholding Payable Account type not 'Payable'"))
        if doc.party_account_currency == default_currency:
            exchange_rate = 1
        else:
            exchange_rate = doc.conversion_rate
        creditor_amount = flt(item.base_net_rate * item.qty * item.withholding_tax_rate / 100 / exchange_rate, float_precision)
        wtax_base_amount = creditor_amount * exchange_rate

        jl_rows = []
        debit_row = dict(
            account = doc.credit_to,
            party_type = "Supplier",
            party = doc.supplier,
            debit_in_account_currency = creditor_amount,
            exchange_rate = exchange_rate,
            cost_center =  item.cost_center,
            reference_type = "Purchase Invoice",
            reference_name = doc.name
        )
        jl_rows.append(debit_row)
        credit_row = dict(
            account = withholding_payable_account,
            party_type = "Supplier" if withholding_payable_account_type == "Payable" else "",
            party = doc.supplier if withholding_payable_account_type == "Payable" else "", 
            credit_in_account_currency = wtax_base_amount,
            cost_center =  item.cost_center,
            account_curremcy = default_currency,
        )
        jl_rows.append(credit_row)
        user_remark = "Withholding Tax Payable Against Item " + item.item_code + " in " + doc.doctype + " " + doc.name + " of amount " + str(flt(item.net_amount,2)) + " " + doc.currency + " with exchange rate of " + str(doc.conversion_rate)
        jv_doc = frappe.get_doc(dict(
            doctype = "Journal Entry",
            voucher_type = "Contra Entry",
            posting_date = doc.posting_date,
            accounts = jl_rows,
            company = doc.company,
            multi_currency = 0 if doc.party_account_currency == default_currency else 1,
            user_remark = user_remark
        ))
        console(jl_rows)
        jv_doc.flags.ignore_permissions = True
        frappe.flags.ignore_account_permission = True
        jv_doc.save()
        if frappe.get_value("Company",doc.company,"auto_submit_for_purchase_withholding") or False:
            jv_doc.submit()
        item.withholding_tax_entry = jv_doc.name
        jv_url = frappe.utils.get_url_to_form(jv_doc.doctype, jv_doc.name)
        si_msgprint = "Journal Entry Created for Withholding Tax <a href='{0}'>{1}</a>".format(jv_url,jv_doc.name)
        frappe.msgprint(_(si_msgprint))