Add xref buttons for all Harvest views

This commit is contained in:
Lance Edgar 2023-03-25 13:21:02 -05:00
parent 4c64dbc536
commit fc70b3c8ae
5 changed files with 76 additions and 4 deletions

View file

@ -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.
# #
@ -25,6 +25,7 @@ Harvest Client views
""" """
from rattail_harvest.db.model import HarvestClient from rattail_harvest.db.model import HarvestClient
from rattail_harvest.harvest.config import get_harvest_url
from webhelpers2.html import HTML, tags from webhelpers2.html import HTML, tags
@ -84,6 +85,19 @@ class HarvestClientView(HarvestMasterView):
items.append(HTML.tag('li', c=[tags.link_to(text, url)])) items.append(HTML.tag('li', c=[tags.link_to(text, url)]))
return HTML.tag('ul', c=items) return HTML.tag('ul', c=items)
def get_xref_buttons(self, client):
buttons = super(HarvestClientView, self).get_xref_buttons(client)
model = self.model
# harvest proper
url = get_harvest_url(self.rattail_config)
if url:
url = '{}/clients'.format(url)
buttons.append(self.make_xref_button(url=url,
text="View in Harvest"))
return buttons
def defaults(config, **kwargs): def defaults(config, **kwargs):
base = globals() base = globals()

View file

@ -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.
# #
@ -25,6 +25,7 @@ Harvest Project views
""" """
from rattail_harvest.db.model import HarvestProject from rattail_harvest.db.model import HarvestProject
from rattail_harvest.harvest.config import get_harvest_url
from .master import HarvestMasterView from .master import HarvestMasterView
@ -106,6 +107,19 @@ class HarvestProjectView(HarvestMasterView):
f.set_readonly('created_at') f.set_readonly('created_at')
f.set_readonly('updated_at') f.set_readonly('updated_at')
def get_xref_buttons(self, project):
buttons = super(HarvestProjectView, self).get_xref_buttons(project)
model = self.model
# harvest
url = get_harvest_url(self.rattail_config)
if url:
url = '{}/projects/{}'.format(url, project.id)
buttons.append(self.make_xref_button(url=url,
text="View in Harvest"))
return buttons
def get_row_data(self, project): def get_row_data(self, project):
model = self.model model = self.model
return self.Session.query(model.HarvestTimeEntry)\ return self.Session.query(model.HarvestTimeEntry)\

View file

@ -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.
# #
@ -25,6 +25,7 @@ Harvest Task views
""" """
from rattail_harvest.db.model import HarvestTask from rattail_harvest.db.model import HarvestTask
from rattail_harvest.harvest.config import get_harvest_url
from .master import HarvestMasterView from .master import HarvestMasterView
@ -60,6 +61,19 @@ class HarvestTaskView(HarvestMasterView):
# time_entries # time_entries
f.remove_field('time_entries') f.remove_field('time_entries')
def get_xref_buttons(self, task):
buttons = super(HarvestTaskView, self).get_xref_buttons(task)
model = self.model
# harvest
url = get_harvest_url(self.rattail_config)
if url:
url = '{}/tasks'.format(url)
buttons.append(self.make_xref_button(url=url,
text="View in Harvest"))
return buttons
def defaults(config, **kwargs): def defaults(config, **kwargs):
base = globals() base = globals()

View file

@ -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.
# #
@ -25,6 +25,7 @@ Harvest Time Entry views
""" """
from rattail_harvest.db.model import HarvestTimeEntry from rattail_harvest.db.model import HarvestTimeEntry
from rattail_harvest.harvest.config import get_harvest_url
from .master import HarvestMasterView from .master import HarvestMasterView
@ -88,6 +89,22 @@ class HarvestTimeEntryView(HarvestMasterView):
f.set_type('billable_rate', 'currency') f.set_type('billable_rate', 'currency')
f.set_type('cost_rate', 'currency') f.set_type('cost_rate', 'currency')
def get_xref_buttons(self, entry):
buttons = super(HarvestTimeEntryView, self).get_xref_buttons(entry)
model = self.model
# harvest
url = get_harvest_url(self.rattail_config)
if url:
url = '{}/time/day/{}/{}'.format(
url,
entry.spent_date.strftime('%Y/%m/%d'),
entry.user_id)
buttons.append(self.make_xref_button(url=url,
text="View in Harvest"))
return buttons
def defaults(config, **kwargs): def defaults(config, **kwargs):
base = globals() base = globals()

View file

@ -25,6 +25,7 @@ Harvest User views
""" """
from rattail_harvest.db.model import HarvestUser from rattail_harvest.db.model import HarvestUser
from rattail_harvest.harvest.config import get_harvest_url
import colander import colander
@ -119,6 +120,18 @@ class HarvestUserView(HarvestMasterView):
if not person: if not person:
raise colander.Invalid(node, "Person not found (you must *select* a record)") raise colander.Invalid(node, "Person not found (you must *select* a record)")
def get_xref_buttons(self, user):
buttons = super(HarvestUserView, self).get_xref_buttons(user)
model = self.model
# harvest proper
url = get_harvest_url(self.rattail_config)
if url:
url = '{}/team'.format(url)
buttons.append(self.make_xref_button(url=url, text="View in Harvest"))
return buttons
def defaults(config, **kwargs): def defaults(config, **kwargs):
base = globals() base = globals()