Beispiel #1
0
 def add_creditor_info(self, payment):
     payment_content = ""
     # creditor information
     payment_content += make_line("        <Cdtr>")
     # name of the creditor/supplier
     payment_content += make_line("          <Nm>" +
                                  cgi.escape(payment.receiver) + "</Nm>")
     # address of creditor/supplier (should contain at least country and first address line
     payment_content += make_line("          <PstlAdr>")
     # street name
     payment_content += make_line("            <StrtNm>{0}</StrtNm>".format(
         cgi.escape(get_street_name(payment.receiver_address_line1))))
     # building number
     payment_content += make_line("            <BldgNb>{0}</BldgNb>".format(
         cgi.escape(get_building_number(payment.receiver_address_line1))))
     # postal code
     payment_content += make_line("            <PstCd>{0}</PstCd>".format(
         cgi.escape(get_pincode(payment.receiver_address_line2))))
     # town name
     payment_content += make_line("            <TwnNm>{0}</TwnNm>".format(
         cgi.escape(get_city(payment.receiver_address_line2))))
     country = frappe.get_doc("Country", payment.receiver_country)
     payment_content += make_line("            <Ctry>" +
                                  country.code.upper() + "</Ctry>")
     payment_content += make_line("          </PstlAdr>")
     payment_content += make_line("        </Cdtr>")
     return payment_content
def generate_payment_file_from_payroll(payroll_entry):
    payroll_record = frappe.get_doc("Payroll Entry", payroll_entry)
    payments = []
    # note: find by matching time range as there is a known issue that the link does not work (v10)
    salary_slips = frappe.get_all("Salary Slip",
                                  filters={
                                      'start_date': payroll_record.start_date,
                                      'end_date': payroll_record.end_date,
                                      'docstatus': 1
                                  },
                                  fields=[
                                      'name', 'posting_date', 'rounded_total',
                                      'employee_name', 'employee',
                                      'bank_account_no'
                                  ])
    company = frappe.get_doc('Company', payroll_record.company)
    country_code = frappe.get_value("Country", company.country, 'code').upper()
    for salary_slip in salary_slips:
        # collect address information
        employee = frappe.get_doc("Employee", salary_slip['employee'])
        if employee.permanent_address:
            address = employee.permanent_address
        elif employee.current_address:
            address = employee.current_address
        else:
            frappe.throw(
                _("No address for employee {0} found.").format(
                    salary_slip['employee_name']))
        lines = address.split("\n")
        street = get_street_name(lines[0])
        building = get_building_number(lines[0])
        pincode = get_pincode(lines[1])
        city = get_city(lines[1])

        payments.append({
            'payment_id':
            cgi.escape("PMTINF-{0}".format(salary_slip['name'])),
            'execution_date':
            salary_slip['posting_date'],
            'instruction_id':
            cgi.escape("INSTRID-{0}".format(salary_slip['name'])),
            'endtoend_id':
            cgi.escape("{0}".format(salary_slip['name'])),
            'transaction_type':
            "SEPA",
            'amount':
            salary_slip['rounded_total'],
            'currency':
            company.default_currency,
            'receiver_name':
            cgi.escape(salary_slip['employee_name']),
            'receiver_street':
            cgi.escape(street),
            'receiver_building':
            cgi.escape(building),
            'receiver_city':
            cgi.escape(city),
            'receiver_pincode':
            cgi.escape(pincode),
            'receiver_country':
            country_code,
            'receiver_iban':
            salary_slip['bank_account_no'].replace(" ", "")
        })
    try:
        paid_from = frappe.get_value('Account', payroll_record.payment_account,
                                     'iban').replace(" ", "")
    except:
        frappe.throw("Account IBAN not found: {0}".format(
            payroll_record.payment_account))

    pain001_data = {
        'msg_id':
        "MSG-" + payroll_record.name,
        'company':
        cgi.escape(payroll_record.company),
        'payments':
        payments,
        'paid_from_iban':
        paid_from,
        'paid_from_bic':
        frappe.get_value('Account', payroll_record.payment_account, 'bic')
    }
    return generate_pain001(pain001_data)
def add_creditor_info(payment_record):
    payment_content = ""
    # creditor information
    payment_content += make_line("        <Cdtr>")
    # name of the creditor/supplier
    name = payment_record.party
    if payment_record.party_type == "Employee":
        name = frappe.get_value("Employee", payment_record.party,
                                "employee_name")
    payment_content += make_line("          <Nm>" + name + "</Nm>")
    # address of creditor/supplier (should contain at least country and first address line
    # get supplier address
    if payment_record.party_type == "Supplier" or payment_record.party_type == "Customer":
        supplier_address = get_billing_address(payment_record.party,
                                               payment_record.party_type)
        if supplier_address == None:
            return None
        street = get_street_name(supplier_address.address_line1)
        building = get_building_number(supplier_address.address_line1)
        plz = supplier_address.pincode
        city = supplier_address.city
        # country (has to be a two-digit code)
        try:
            country_code = frappe.get_value('Country',
                                            supplier_address.country,
                                            'code').upper()
        except:
            country_code = "CH"
    elif payment_record.party_type == "Employee":
        employee = frappe.get_doc("Employee", payment_record.party)
        if employee.permanent_address:
            address = employee.permanent_address
        elif employee.current_address:
            address = employee.current_address
        else:
            # no address found
            return None
        try:
            lines = address.split("\n")
            street = get_street_name(lines[0])
            building = get_building_number(lines[0])
            plz = get_pincode(lines[1])
            city = get_city(lines[1])
            country_code = "CH"
        except:
            # invalid address
            return None
    else:
        # unknown supplier type
        return None
    payment_content += make_line("          <PstlAdr>")
    # street name
    payment_content += make_line("            <StrtNm>" + street + "</StrtNm>")
    # building number
    payment_content += make_line("            <BldgNb>" + building +
                                 "</BldgNb>")
    # postal code
    payment_content += make_line("            <PstCd>{0}</PstCd>".format(plz))
    # town name
    payment_content += make_line("            <TwnNm>" + city + "</TwnNm>")
    payment_content += make_line("            <Ctry>" + country_code +
                                 "</Ctry>")
    payment_content += make_line("          </PstlAdr>")
    payment_content += make_line("        </Cdtr>")
    return payment_content