From 69585ad15d6dcf5d94ff3cc56168e37631b9a192 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 2 Aug 2020 21:28:53 -0500 Subject: [PATCH] Fix handling of `corepos_account_id` field when editing customers --- tailbone_corepos/views/customers.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tailbone_corepos/views/customers.py b/tailbone_corepos/views/customers.py index 1def7cf..9dc0ce1 100644 --- a/tailbone_corepos/views/customers.py +++ b/tailbone_corepos/views/customers.py @@ -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() + [