{# Uncommment to view API response #} {# {{ api_response|tojson|safe }} #} {%- set acord = document -%} {%- do change_tag(acord.SignonRq, "Rq", "Rs") -%} {%- do change_tag(acord.InsuranceSvcRq, "Rq", "Rs") -%} {%- do change_tag(acord.InsuranceSvcRs.HomePolicyQuoteInqRq, "Rq", "Rs") -%} {%- set policy_response = acord.InsuranceSvcRs.HomePolicyQuoteInqRs -%} {%- set home_line_business = acord.InsuranceSvcRs.HomePolicyQuoteInqRs.HomeLineBusiness -%} {%- set dwell = home_line_business.Dwell -%} {%- do delete_tag(acord.SignonRs.SignonPswd, "CustPswd") -%} {%- if not api_response -%} {%- do add_sub_tag(policy_response, "MsgStatus") -%} {%- set response_messages = policy_response.MsgStatus -%} {%- do add_sub_tag(response_messages, "MsgStatusCd", tag_value="Rejected") -%} {%- for hard_stop in var_data.hard_stops -%} {%- set element = new_element("MsgStatusDesc") -%} {%- do add_sub_tag(response_messages, "MsgStatusDesc", tag_value=hard_stop) -%} {%- endfor -%} {%- elif not api_response.success -%} {%- do raise_hard_stop(api_response|tojson) -%} {%- else -%} {%- do add_sub_tag(policy_response, "MsgStatus") -%} {%- set response_messages = policy_response.MsgStatus -%} {%- do add_sub_tag(response_messages, "MsgStatusCd", tag_value = "Success") -%} {%- macro format_money(amount) -%} {{ "${:,.0f}".format(amount|float) if amount|int >= 0 else "-${:,.0f}".format(amount|float|abs) }} {%- endmacro -%} {%- macro add_change_msg(change_code, change_msg) -%} {%- set element = new_element("ChangeStatus", tag_ref=("L01")) -%} {%- do add_sub_tag(element, "ActionCd", tag_value=change_code) -%} {%- do add_sub_tag(element, "ChangeDesc", tag_value=change_msg) -%} {%- do add_new_element(response_messages, element) -%} {%- endmacro -%} {%- macro add_new_cov(cov_key, cov_desc) -%} {%- set element = new_element("Coverage") -%} {%- do add_sub_tag(element, "CoverageCd", tag_value=cov_key) -%} {%- do add_sub_tag(element, "CoverageDesc", tag_value=cov_desc) -%} {%- do add_new_element(dwell, element) -%} {%- endmacro -%} {%- macro set_cov_limit_integer(value, cov_cd=None, cov_desc=None) -%} {%- set covs = dwell.xpath("Coverage[CoverageCd='" ~ cov_cd ~ "']") if cov_cd else dwell.xpath("Coverage[CoverageDesc='" ~ cov_desc ~ "']") -%} {%- if covs -%} {%- set cov = covs[0] -%} {%- if not cov.Limit -%} {%- do add_sub_tag(cov, 'Limit') -%} {%- endif -%} {%- if not cov.Limit.FormatInteger -%} {%- do add_sub_tag(cov.Limit, 'FormatInteger', tag_value=value) -%} {%- else -%} {%- do change_value(cov.Limit, 'FormatInteger', tag_value=value) -%} {%- endif -%} {%- endif -%} {%- endmacro -%} {%- macro set_cov_amt(value, cov_cd=None, cov_desc=None) -%} {%- set covs = dwell.xpath("Coverage[CoverageCd='" ~ cov_cd ~ "']") if cov_cd else dwell.xpath("Coverage[CoverageDesc='" ~ cov_desc ~ "']") -%} {%- if covs -%} {%- set cov = covs[0] -%} {%- if not cov.CurrentTermAmt -%} {%- do add_sub_tag(cov, 'CurrentTermAmt') -%} {%- endif -%} {%- if not cov.CurrentTermAmt.Amt -%} {%- do add_sub_tag(cov.CurrentTermAmt, 'Amt', tag_value=value) -%} {%- else -%} {%- do change_value(cov.CurrentTermAmt, 'Amt', tag_value=value) -%} {%- endif -%} {%- endif -%} {%- endmacro -%} {%- set prop = api_response.data.properties[0] -%} {%- set location_address = policy_response.Location.Addr -%} {%- do change_value(location_address, "Addr1", prop.address_line1) -%} {%- do change_value(location_address, "Addr2", prop.address_line2) -%} {%- do change_value(location_address, "City", prop.address_city) -%} {%- do change_value(location_address, "StateProvCd", prop.address_state) -%} {%- do change_value(location_address, "PostalCode", prop.address_zip) -%} {%- set ITEM_ACORD_MAP = { "Dwelling": "DWELL", "Other Structures": "OS", "Personal Property": "PP", "Personal Property Off Premises": "POP", "Loss of Use": "LOU", "Personal Liability": "PL", "Medical Payments to Others": "MEDPM", "Claim-Free Renewal Discount": "", "Full Water Damage Coverage": "WD", "Tier Factor": "", "Age of Home Factor": "", "Security Features Discount": "", "New Purchase Discount": "NHDIS", "Recent Home Inspection Discount": "", "Age of Insured": "", "Apply Maximum Discount Adjustment": "", "Advanced Shopper Discount": "", "Roof Systems Payment Schedule Endorsement": "", "Wind and Hail Deductible": "WHDED", "All Other Perils Deductible": "PropDed", "Policy Fee": "POLFE", "New Roof Discount": "ROFND" } -%} {%- for change in var_data.changes -%} {%- do add_change_msg(change.ActionCd, change.ChangeDesc) -%} {%- endfor -%} {%- set requested_coverages = {} -%} {%- for coverage in dwell.xpath("Coverage") -%} {%- do requested_coverages.update({(coverage.CoverageCd | string): coverage}) -%} {%- endfor -%} {%- for item in api_response.data["items"] if (item.pro_rata_amount != 0 or item.pro_rata_fee != 0 or item.limit) and item.type in ["coverage", "adjustment", "fee"] -%} {%- set code = ITEM_ACORD_MAP.get(item.name) -%} {%- if code and code in requested_coverages -%} {%- do requested_coverages.pop(code) -%} {%- else -%} {# New item #} {%- do add_new_cov(code, item.name) -%} {%- do add_change_msg('A', '{} is added to this quote.'.format(item.name if not code else "{} - {}".format(code, item.name))) -%} {%- endif -%} {%- if item.limit -%} {%- do set_cov_limit_integer(item.limit|int, cov_cd=code, cov_desc=item.name) -%} {%- endif -%} {%- set current_term_amt = item.pro_rata_amount if item.type != 'fee' else item.pro_rata_fee -%} {%- if current_term_amt -%} {%- do set_cov_amt(current_term_amt, cov_cd=code, cov_desc=item.name) -%} {%- endif -%} {%- endfor %} {%- for code, coverage_el in requested_coverages.items() -%} {# Remove unsupported coverages #} {%- set covs = dwell.xpath("Coverage[CoverageCd='" ~ code ~ "']") -%} {%- if covs -%} {%- do remove_element(covs[0]) -%} {%- do add_change_msg('D', '{}: this coverage is not currently offered.'.format(code)) -%} {%- endif -%} {%- endfor -%} {%- if response_messages.xpath("ChangeStatus") -%} {%- do add_sub_tag(response_messages, "MsgStatusCd", tag_value = "SuccessWithChanges") -%} {%- endif -%} {%- set element = new_element("FileAttachmentInfo") -%} {%- do add_sub_tag(element, "AttachmentDesc", tag_value="URL") -%} {%- do add_sub_tag(element, "WebsiteURL", tag_value="http://localhost:8080/agent/stateless_quotes/continue?id=" + api_response.data.stateless_quote_id + "&redirectTo=/agent/policies/wizard/policy_contacts") -%} {%- do add_new_element(policy_response, element) -%} {%- set element = new_element("FileAttachmentInfo") -%} {%- do add_sub_tag(element, "AttachmentDesc", tag_value="PDF") -%} {%- do add_sub_tag(element, "WebsiteURL", tag_value="http://localhost:8080/agent/stateless_quotes/continue?id=" + api_response.data.stateless_quote_id + "&redirectTo=/gateway%3Ffile%3Dagent.views%26method%3DbuildBriteQuoteDeliverable%26type%3Dquote") -%} {%- do add_new_element(policy_response, element) -%} {%- if not policy_response.PersPolicy.QuoteInfo -%} {%- do add_sub_tag(policy_response.PersPolicy, "QuoteInfo") -%} {%- endif -%} {%- do add_sub_tag(policy_response, "PolicySummaryInfo") -%} {%- do add_sub_tag(policy_response.PolicySummaryInfo, "FullTermAmt") -%} {%- do add_sub_tag(policy_response.PolicySummaryInfo.FullTermAmt, "Amt", tag_value=api_response.data.total.annual_premium) -%} {%- do add_sub_tag(policy_response.PolicySummaryInfo, "WrittenAmt") -%} {%- do add_sub_tag(policy_response.PolicySummaryInfo.WrittenAmt, "Amt", tag_value=api_response.data.total.pro_rata_premium) -%} {%- do add_sub_tag(policy_response.PolicySummaryInfo, "com.britecore_StatelessQuoteId", tag_value=api_response.data.stateless_quote_id) -%} {%- do add_sub_tag(policy_response.PolicySummaryInfo, "PolicyStatusCd", tag_value="QuotedNotBound") -%} {%- endif -%} {{ to_xml(acord)|safe -}}