Add/improve some CORE member xref links
This commit is contained in:
		
							parent
							
								
									fcaa486e7f
								
							
						
					
					
						commit
						8e45b3fbf4
					
				
					 6 changed files with 72 additions and 13 deletions
				
			
		|  | @ -1,3 +0,0 @@ | ||||||
| ## -*- coding: utf-8; -*- |  | ||||||
| <%inherit file="/core-pos/master/view.mako" /> |  | ||||||
| ${parent.body()} |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| ################################################################################ | ################################################################################ | ||||||
| # | # | ||||||
| #  Rattail -- Retail Software Framework | #  Rattail -- Retail Software Framework | ||||||
| #  Copyright © 2010-2022 Lance Edgar | #  Copyright © 2010-2023 Lance Edgar | ||||||
| # | # | ||||||
| #  This file is part of Rattail. | #  This file is part of Rattail. | ||||||
| # | # | ||||||
|  | @ -48,6 +48,7 @@ class CustomerView(CoreOfficeMasterView): | ||||||
|     Base class for customer views. |     Base class for customer views. | ||||||
|     """ |     """ | ||||||
|     model_class = corepos.CustData |     model_class = corepos.CustData | ||||||
|  |     model_key = ('card_number', 'person_number') | ||||||
|     model_title = "CORE-POS Customer (Legacy)" |     model_title = "CORE-POS Customer (Legacy)" | ||||||
|     model_title_plural = "CORE-POS Customers (Legacy)" |     model_title_plural = "CORE-POS Customers (Legacy)" | ||||||
|     url_prefix = '/core-pos/customers' |     url_prefix = '/core-pos/customers' | ||||||
|  |  | ||||||
|  | @ -92,6 +92,7 @@ class CoreMasterView(MasterView): | ||||||
|         Adds the URL for viewing the record/object within CORE Office, or else |         Adds the URL for viewing the record/object within CORE Office, or else | ||||||
|         the reason for lack of such a URL. |         the reason for lack of such a URL. | ||||||
|         """ |         """ | ||||||
|  |         kwargs = super().template_kwargs_view(**kwargs) | ||||||
|         obj = kwargs['instance'] |         obj = kwargs['instance'] | ||||||
| 
 | 
 | ||||||
|         # CORE Office URL |         # CORE Office URL | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| ################################################################################ | ################################################################################ | ||||||
| # | # | ||||||
| #  Rattail -- Retail Software Framework | #  Rattail -- Retail Software Framework | ||||||
| #  Copyright © 2010-2022 Lance Edgar | #  Copyright © 2010-2023 Lance Edgar | ||||||
| # | # | ||||||
| #  This file is part of Rattail. | #  This file is part of Rattail. | ||||||
| # | # | ||||||
|  | @ -26,7 +26,7 @@ CORE-POS member views | ||||||
| 
 | 
 | ||||||
| from corepos.db.office_op import model as corepos | from corepos.db.office_op import model as corepos | ||||||
| 
 | 
 | ||||||
| from rattail_corepos.config import core_office_customer_account_url | from rattail_corepos.config import core_office_url, core_office_customer_account_url | ||||||
| 
 | 
 | ||||||
| from webhelpers2.html import HTML, tags | from webhelpers2.html import HTML, tags | ||||||
| 
 | 
 | ||||||
|  | @ -159,7 +159,9 @@ class MemberView(CoreOfficeMasterView): | ||||||
|         items = [] |         items = [] | ||||||
|         for customer in customers: |         for customer in customers: | ||||||
|             text = str(customer) |             text = str(customer) | ||||||
|             url = self.request.route_url('corepos.customers.view', id=customer.id) |             url = self.request.route_url('corepos.customers.view', | ||||||
|  |                                          card_number=customer.card_number, | ||||||
|  |                                          person_number=customer.person_number) | ||||||
|             link = tags.link_to(text, url) |             link = tags.link_to(text, url) | ||||||
|             items.append(HTML.tag('li', c=[link])) |             items.append(HTML.tag('li', c=[link])) | ||||||
|         return HTML.tag('ul', c=items) |         return HTML.tag('ul', c=items) | ||||||
|  | @ -174,10 +176,14 @@ class MemberView(CoreOfficeMasterView): | ||||||
|                                      card_number=suspension.card_number) |                                      card_number=suspension.card_number) | ||||||
|         return tags.link_to(text, url) |         return tags.link_to(text, url) | ||||||
| 
 | 
 | ||||||
|     def core_office_object_url(self, office_url, member): |     def get_xref_buttons(self, member): | ||||||
|         return core_office_customer_account_url(self.rattail_config, |         url = core_office_url(self.rattail_config) | ||||||
|                                                 member.card_number, |         if url: | ||||||
|                                                 office_url=office_url) |             url = core_office_customer_account_url(self.rattail_config, | ||||||
|  |                                                    member.card_number, | ||||||
|  |                                                    office_url=url) | ||||||
|  |             return [self.make_xref_button(url=url, | ||||||
|  |                                           text="View in CORE Office")] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def defaults(config, **kwargs): | def defaults(config, **kwargs): | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| ################################################################################ | ################################################################################ | ||||||
| # | # | ||||||
| #  Rattail -- Retail Software Framework | #  Rattail -- Retail Software Framework | ||||||
| #  Copyright © 2010-2022 Lance Edgar | #  Copyright © 2010-2023 Lance Edgar | ||||||
| # | # | ||||||
| #  This file is part of Rattail. | #  This file is part of Rattail. | ||||||
| # | # | ||||||
|  | @ -24,6 +24,10 @@ | ||||||
| Customer Views | Customer Views | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
|  | from rattail_corepos.config import core_office_url, core_office_customer_account_url | ||||||
|  | 
 | ||||||
|  | from webhelpers2.html import tags | ||||||
|  | 
 | ||||||
| from tailbone.views import ViewSupplement | from tailbone.views import ViewSupplement | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -35,6 +39,7 @@ class CustomerViewSupplement(ViewSupplement): | ||||||
| 
 | 
 | ||||||
|     labels = { |     labels = { | ||||||
|         'corepos_account_id': "CORE-POS Account ID", |         'corepos_account_id': "CORE-POS Account ID", | ||||||
|  |         'corepos_card_number': "CORE-POS Card Number", | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     def get_grid_query(self, query): |     def get_grid_query(self, query): | ||||||
|  | @ -44,15 +49,31 @@ class CustomerViewSupplement(ViewSupplement): | ||||||
|     def configure_grid(self, g): |     def configure_grid(self, g): | ||||||
|         model = self.model |         model = self.model | ||||||
|         g.set_filter('corepos_account_id', model.CoreCustomer.corepos_account_id) |         g.set_filter('corepos_account_id', model.CoreCustomer.corepos_account_id) | ||||||
|  |         g.set_filter('corepos_card_number', model.CoreCustomer.corepos_card_number) | ||||||
| 
 | 
 | ||||||
|     def configure_form(self, f): |     def configure_form(self, f): | ||||||
|         if not self.master.creating: |         if not self.master.creating: | ||||||
|             f.append('corepos_account_id') |             f.append('corepos_account_id') | ||||||
|  |             f.append('corepos_card_number') | ||||||
| 
 | 
 | ||||||
|     def get_version_child_classes(self): |     def get_version_child_classes(self): | ||||||
|         model = self.model |         model = self.model | ||||||
|         return [model.CoreCustomer] |         return [model.CoreCustomer] | ||||||
| 
 | 
 | ||||||
|  |     def get_xref_buttons(self, customer): | ||||||
|  |         url = core_office_url(self.rattail_config) | ||||||
|  |         if url: | ||||||
|  |             url = core_office_customer_account_url(self.rattail_config, | ||||||
|  |                                                    customer.number, | ||||||
|  |                                                    office_url=url) | ||||||
|  |             return [{'url': url, 'text': "View in CORE Office"}] | ||||||
|  | 
 | ||||||
|  |     def get_xref_links(self, customer): | ||||||
|  |         if customer.corepos_card_number: | ||||||
|  |             url = self.request.route_url('corepos.members.view', | ||||||
|  |                                          card_number=customer.corepos_card_number) | ||||||
|  |             return [tags.link_to("View CORE-POS Member", url)] | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def includeme(config): | def includeme(config): | ||||||
|     CustomerViewSupplement.defaults(config) |     CustomerViewSupplement.defaults(config) | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| ################################################################################ | ################################################################################ | ||||||
| # | # | ||||||
| #  Rattail -- Retail Software Framework | #  Rattail -- Retail Software Framework | ||||||
| #  Copyright © 2010-2022 Lance Edgar | #  Copyright © 2010-2023 Lance Edgar | ||||||
| # | # | ||||||
| #  This file is part of Rattail. | #  This file is part of Rattail. | ||||||
| # | # | ||||||
|  | @ -24,9 +24,26 @@ | ||||||
| Member Views | Member Views | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
|  | from rattail_corepos.config import core_office_url, core_office_customer_account_url | ||||||
|  | 
 | ||||||
|  | from webhelpers2.html import tags | ||||||
|  | 
 | ||||||
| from tailbone.views import ViewSupplement | from tailbone.views import ViewSupplement | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class MembershipTypeViewSupplement(ViewSupplement): | ||||||
|  |     """ | ||||||
|  |     MembershipType view supplement for CORE integration | ||||||
|  |     """ | ||||||
|  |     route_prefix = 'membership_types' | ||||||
|  | 
 | ||||||
|  |     def get_xref_buttons(self, memtype): | ||||||
|  |         url = core_office_url(self.rattail_config) | ||||||
|  |         if url: | ||||||
|  |             url = f'{url}/mem/MemberTypeEditor.php' | ||||||
|  |             return [{'url': url, 'text': "View in CORE Office"}] | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class MemberViewSupplement(ViewSupplement): | class MemberViewSupplement(ViewSupplement): | ||||||
|     """ |     """ | ||||||
|     Member view supplement for CORE integration |     Member view supplement for CORE integration | ||||||
|  | @ -52,6 +69,22 @@ class MemberViewSupplement(ViewSupplement): | ||||||
|         model = self.model |         model = self.model | ||||||
|         return [model.CoreMember] |         return [model.CoreMember] | ||||||
| 
 | 
 | ||||||
|  |     def get_xref_buttons(self, member): | ||||||
|  |         if member.customer and member.customer.corepos_card_number: | ||||||
|  |             url = core_office_url(self.rattail_config) | ||||||
|  |             if url: | ||||||
|  |                 url = core_office_customer_account_url(self.rattail_config, | ||||||
|  |                                                        member.customer.corepos_card_number, | ||||||
|  |                                                        office_url=url) | ||||||
|  |                 return [{'url': url, 'text': "View in CORE Office"}] | ||||||
|  | 
 | ||||||
|  |     def get_xref_links(self, member): | ||||||
|  |         if member.customer and member.customer.corepos_card_number: | ||||||
|  |             url = self.request.route_url('corepos.members.view', | ||||||
|  |                                          card_number=member.customer.corepos_card_number) | ||||||
|  |             return [tags.link_to("View CORE-POS Member", url)] | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| def includeme(config): | def includeme(config): | ||||||
|  |     MembershipTypeViewSupplement.defaults(config) | ||||||
|     MemberViewSupplement.defaults(config) |     MemberViewSupplement.defaults(config) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar