I'm trying to add a SMS permission checkbox to the portal in Odoo. I have this view working:
<odoo>
<template id="sms_permission_portal" inherit_id="portal.portal_my_details_fields" name="Add SMS Permission to Portal">
<xpath expr="//div[8]" position="after">
<div class="mb-3 sms_permission col-xl-6">
<label class="col-form-label" for="sms_permission">SMS Permission</label>
<div class="col-1">
<div class="form-check">
<input type="checkbox" id="sms_permission" name="sms_permission" class="s_website_form_input form-check-input sms_permission" t-att-checked="'checked' if partner.sms_permission else None" t-att-value="partner.sms_permission" data-fill-with="und>
</div>
</div>
<div class="s_website_form_field_description small form-text text-muted">I would like to receive SMS text messages.</div>
</div>
</xpath>
</template>
</odoo>
I modified the controller to allow my field:
from odoo.addons.portal.controllers.portal import CustomerPortal
class CustomerPortal(CustomerPortal):
def _get_optional_fields(self):
""" This method is there so that we can override the optional fields """
return ["zipcode", "state_id", "sms_permission", "vat", "company_name"]
I whitelisted the variable to allow use in web forms:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<function model="ir.model.fields" name="formbuilder_whitelist">
<value>res.partner</value>
<value eval="[
'sms_permission',
]"/>
</function>
</data>
</odoo>
Everything seems to work fine. Except when I uncheck the box it doesn't save. Checks get saved but unchecks do not.
I understand that's because if the checkbox is unchecked then the browser doesn't send the variable to Odoo. So Odoo/python doesn't have any way to know that it got modified.
Anyone have a solution for this?