blob: a5471366ca20c2a0f1c98b33c195f89e086e6c91 [file] [log] [blame]
Raffael Meyerff878c02019-02-07 03:28:27 +01001import os
2import frappe
3
Raffael Meyer1f72b442019-01-27 23:32:41 +01004
5def setup(company=None, patch=True):
Raffael Meyerff878c02019-02-07 03:28:27 +01006 if not patch:
7 update_address_template()
Raffael Meyer1f72b442019-01-27 23:32:41 +01008
9
10def update_address_template():
Raffael Meyerff878c02019-02-07 03:28:27 +010011 """
12 Read address template from file. Update existing Address Template or create a
13 new one.
14 """
15 dir_name = os.path.dirname(__file__)
16 template_path = os.path.join(dir_name, 'address_template.html')
Raffael Meyer1f72b442019-01-27 23:32:41 +010017
Raffael Meyerff878c02019-02-07 03:28:27 +010018 with open(template_path, 'r') as template_file:
19 template_html = template_file.read()
20
21 address_template = frappe.db.get_value('Address Template', 'Germany')
22
23 if address_template:
24 frappe.db.set_value('Address Template', 'Germany', 'template', template_html)
25 else:
26 # make new html template for Germany
27 frappe.get_doc(dict(
28 doctype='Address Template',
29 country='Germany',
30 template=template_html
31 )).insert()