Raffael Meyer | ff878c0 | 2019-02-07 03:28:27 +0100 | [diff] [blame] | 1 | import os |
| 2 | import frappe |
| 3 | |
Raffael Meyer | 1f72b44 | 2019-01-27 23:32:41 +0100 | [diff] [blame] | 4 | |
| 5 | def setup(company=None, patch=True): |
Raffael Meyer | ff878c0 | 2019-02-07 03:28:27 +0100 | [diff] [blame] | 6 | if not patch: |
| 7 | update_address_template() |
Raffael Meyer | 1f72b44 | 2019-01-27 23:32:41 +0100 | [diff] [blame] | 8 | |
| 9 | |
| 10 | def update_address_template(): |
Raffael Meyer | ff878c0 | 2019-02-07 03:28:27 +0100 | [diff] [blame] | 11 | """ |
| 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 Meyer | 1f72b44 | 2019-01-27 23:32:41 +0100 | [diff] [blame] | 17 | |
Raffael Meyer | ff878c0 | 2019-02-07 03:28:27 +0100 | [diff] [blame] | 18 | 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() |