Fix handling of corepos_account_id field when editing customers

This commit is contained in:
Lance Edgar 2020-08-02 21:28:53 -05:00
parent acf6764cbb
commit 69585ad15d

View file

@ -53,6 +53,26 @@ class CustomerView(base.CustomersView):
model = self.rattail_config.get_model()
g.set_filter('corepos_account_id', model.CoreCustomer.corepos_account_id)
def configure_form(self, f):
super(CustomerView, self).configure_form(f)
f.set_required('corepos_account_id', False)
def objectify(self, form, data=None):
if data is None:
data = form.validated
customer = form.model_instance
# this field lives in an extension table, but the column does not allow
# null, which means we don't want to pass an empty value along unless
# there is already an extension record in place for this customer
if 'corepos_account_id' in data and data['corepos_account_id'] is None:
if self.creating:
data.pop('corepos_account_id')
elif self.editing and not customer._corepos:
data.pop('corepos_account_id')
return super(CustomerView, self).objectify(form, data)
def get_version_child_classes(self):
model = self.rattail_config.get_model()
return super(CustomerView, self).get_version_child_classes() + [