Tyler Matteson | 53a6492 | 2019-01-17 14:04:01 -0500 | [diff] [blame] | 1 | # Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | # License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | from __future__ import unicode_literals |
| 5 | import frappe |
| 6 | from frappe.custom.doctype.custom_field.custom_field import create_custom_fields |
| 7 | |
| 8 | |
| 9 | def setup(company=None, patch=True): |
| 10 | make_custom_fields() |
| 11 | add_print_formats() |
| 12 | update_address_template() |
| 13 | |
| 14 | |
| 15 | def make_custom_fields(): |
| 16 | custom_fields = { |
| 17 | 'Supplier': [ |
| 18 | dict(fieldname='irs_1099', fieldtype='Check', insert_after='tax_id', |
| 19 | label='Is IRS 1099 reporting required for supplier?') |
| 20 | ] |
| 21 | } |
| 22 | create_custom_fields(custom_fields) |
| 23 | |
| 24 | |
| 25 | def add_print_formats(): |
| 26 | frappe.reload_doc("regional", "print_format", "irs_1099_form") |
| 27 | frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where |
| 28 | name in('IRS 1099 Form') """) |
| 29 | |
| 30 | |
| 31 | def update_address_template(): |
| 32 | html = """{{ address_line1 }}<br> |
| 33 | {% if address_line2 %}{{ address_line2 }}<br>{% endif -%} |
| 34 | {{ city }}, {% if state %}{{ state }}{% endif -%}{% if pincode %} {{ pincode }}<br>{% endif -%} |
| 35 | {% if country != "United States" %}{{ country|upper }}{% endif -%} |
| 36 | """ |
| 37 | |
| 38 | address_template = frappe.db.get_value('Address Template', 'United States') |
| 39 | if address_template: |
| 40 | frappe.db.set_value('Address Template', 'United States', 'template', html) |
| 41 | else: |
| 42 | frappe.get_doc(dict(doctype='Address Template', country='United States', template=html)).insert() |