Add basic/minimal merge support for customers

This commit is contained in:
Lance Edgar 2022-07-24 12:05:05 -05:00
parent e656f769b1
commit 25f39f4173

View file

@ -93,6 +93,18 @@ class CustomerView(MasterView):
'members', 'members',
] ]
mergeable = True
merge_coalesce_fields = [
'email_addresses',
'phone_numbers',
]
merge_fields = merge_coalesce_fields + [
'uuid',
'name',
]
def get_expose_active_in_pos(self): def get_expose_active_in_pos(self):
if not hasattr(self, '_expose_active_in_pos'): if not hasattr(self, '_expose_active_in_pos'):
self._expose_active_in_pos = self.rattail_config.getbool( self._expose_active_in_pos = self.rattail_config.getbool(
@ -444,6 +456,37 @@ class CustomerView(MasterView):
return self.redirect(self.request.get_referrer()) return self.redirect(self.request.get_referrer())
def get_merge_data(self, customer):
return {
'uuid': customer.uuid,
'name': customer.name,
'email_addresses': [e.address for e in customer.emails],
'phone_numbers': [p.number for p in customer.phones],
}
def merge_objects(self, removing, keeping):
coalesce = self.get_merge_coalesce_fields()
if coalesce:
if 'email_addresses' in coalesce:
keeping_emails = [e.address for e in keeping.emails]
for email in removing.emails:
if email.address not in keeping_emails:
keeping.add_email(address=email.address,
type=email.type,
invalid=email.invalid)
keeping_emails.append(email.address)
if 'phone_numbers' in coalesce:
keeping_phones = [e.number for e in keeping.phones]
for phone in removing.phones:
if phone.number not in keeping_phones:
keeping.add_phone(number=phone.number,
type=phone.type)
keeping_phones.append(phone.number)
self.Session.delete(removing)
def configure_get_simple_settings(self): def configure_get_simple_settings(self):
return [ return [