feat(regional): a central place for regional address templates (#19862)

* feat: a central place for regional address templates

* set up address templates during install

* why don't the tests run?

* fix: remove unused variables, fix cwd

* fix: .get() dicts contents

* fix: choose the right default

* fix: fieldname is template, not html

* fix: import unittest

* fix: remove unnecessary code

* fix: ensure country exists

* fix: ensure country exists

* feat: test updating an existing template

* fix(regional): DuplicateEntryError in test_update_address_template

* refactor and set 'is_default'

* fix codacy

* fix: patch gst_fixes

* fix: patch update_address_template_for_india

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
This commit is contained in:
Raffael Meyer
2020-04-08 05:26:57 +02:00
committed by GitHub
parent 0672b6b2e8
commit 9aae0c27c2
13 changed files with 131 additions and 70 deletions

View File

@@ -5,12 +5,9 @@ from __future__ import unicode_literals
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
def setup(company=None, patch=True):
make_custom_fields()
add_print_formats()
update_address_template()
def make_custom_fields():
custom_fields = {
@@ -21,22 +18,7 @@ def make_custom_fields():
}
create_custom_fields(custom_fields)
def add_print_formats():
frappe.reload_doc("regional", "print_format", "irs_1099_form")
frappe.db.sql(""" update `tabPrint Format` set disabled = 0 where
name in('IRS 1099 Form') """)
def update_address_template():
html = """{{ address_line1 }}<br>
{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}
{{ city }}, {% if state %}{{ state }}{% endif -%}{% if pincode %} {{ pincode }}<br>{% endif -%}
{% if country != "United States" %}{{ country|upper }}{% endif -%}
"""
address_template = frappe.db.get_value('Address Template', 'United States')
if address_template:
frappe.db.set_value('Address Template', 'United States', 'template', html)
else:
frappe.get_doc(dict(doctype='Address Template', country='United States', template=html)).insert()