Add more views for product origins
This commit is contained in:
parent
dca270f682
commit
456415b0fa
|
@ -94,6 +94,11 @@ def make_corepos_menu(request):
|
|||
'url': url('corepos.scale_items'),
|
||||
'perm': 'corepos.scale_items.list',
|
||||
},
|
||||
{
|
||||
'title': "Origins",
|
||||
'url': url('corepos.origins'),
|
||||
'perm': 'corepos.origins.list',
|
||||
},
|
||||
{'type': 'sep'},
|
||||
{
|
||||
'title': "Super Departments",
|
||||
|
@ -142,11 +147,6 @@ def make_corepos_menu(request):
|
|||
'url': url('corepos.purchase_orders'),
|
||||
'perm': 'corepos.purchase_orders.list',
|
||||
},
|
||||
{
|
||||
'title': "Origins",
|
||||
'url': url('corepos.origins'),
|
||||
'perm': 'corepos.origins.list',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
## -*- coding: utf-8; -*-
|
||||
<%inherit file="/master/index.mako" />
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
${parent.context_menu_items()}
|
||||
% if request.has_perm('corepos.origins'):
|
||||
<li>${h.link_to("View CORE-POS Origins", url('corepos.origins'))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
||||
${parent.body()}
|
18
tailbone_corepos/templates/core-pos/origins/index.mako
Normal file
18
tailbone_corepos/templates/core-pos/origins/index.mako
Normal file
|
@ -0,0 +1,18 @@
|
|||
## -*- coding: utf-8; -*-
|
||||
<%inherit file="/master/index.mako" />
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
${parent.context_menu_items()}
|
||||
% if request.has_perm('corepos.origin_regions'):
|
||||
<li>${h.link_to("View CORE-POS Origin Regions", url('corepos.origin_regions'))}</li>
|
||||
% endif
|
||||
% if request.has_perm('corepos.origin_stateprov'):
|
||||
<li>${h.link_to("View CORE-POS Origin States/Provinces", url('corepos.origin_stateprov'))}</li>
|
||||
% endif
|
||||
% if request.has_perm('corepos.origin_countries'):
|
||||
<li>${h.link_to("View CORE-POS Origin Countries", url('corepos.origin_countries'))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
||||
${parent.body()}
|
|
@ -0,0 +1,12 @@
|
|||
## -*- coding: utf-8; -*-
|
||||
<%inherit file="/master/index.mako" />
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
${parent.context_menu_items()}
|
||||
% if request.has_perm('corepos.origins'):
|
||||
<li>${h.link_to("View CORE-POS Origins", url('corepos.origins'))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
||||
${parent.body()}
|
|
@ -0,0 +1,12 @@
|
|||
## -*- coding: utf-8; -*-
|
||||
<%inherit file="/master/index.mako" />
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
${parent.context_menu_items()}
|
||||
% if request.has_perm('corepos.origins'):
|
||||
<li>${h.link_to("View CORE-POS Origins", url('corepos.origins'))}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
|
||||
${parent.body()}
|
|
@ -2,7 +2,7 @@
|
|||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2020 Lance Edgar
|
||||
# Copyright © 2010-2021 Lance Edgar
|
||||
#
|
||||
# This file is part of Rattail.
|
||||
#
|
||||
|
@ -26,9 +26,68 @@ CORE-POS origin views
|
|||
|
||||
from corepos.db.office_op import model as corepos
|
||||
|
||||
from deform import widget as dfwidget
|
||||
from webhelpers2.html import tags
|
||||
|
||||
from .master import CoreOfficeMasterView
|
||||
|
||||
|
||||
class OriginCountryView(CoreOfficeMasterView):
|
||||
"""
|
||||
Master view for Origin Countries
|
||||
"""
|
||||
model_class = corepos.OriginCountry
|
||||
model_title = "CORE-POS Origin Country"
|
||||
model_title_plural = "CORE-POS Origin Countries"
|
||||
url_prefix = '/core-pos/origins/countries'
|
||||
route_prefix = 'corepos.origin_countries'
|
||||
|
||||
def configure_form(self, f):
|
||||
super(OriginCountryView, self).configure_form(f)
|
||||
|
||||
if self.creating:
|
||||
f.remove('id')
|
||||
else:
|
||||
f.set_readonly('id')
|
||||
|
||||
|
||||
class OriginStateProvinceView(CoreOfficeMasterView):
|
||||
"""
|
||||
Master view for Origin State/Province
|
||||
"""
|
||||
model_class = corepos.OriginStateProv
|
||||
model_title = "CORE-POS Origin State/Province"
|
||||
model_title_plural = "CORE-POS Origin States/Provinces"
|
||||
url_prefix = '/core-pos/origins/stateprov'
|
||||
route_prefix = 'corepos.origin_stateprov'
|
||||
|
||||
def configure_form(self, f):
|
||||
super(OriginStateProvinceView, self).configure_form(f)
|
||||
|
||||
if self.creating:
|
||||
f.remove('id')
|
||||
else:
|
||||
f.set_readonly('id')
|
||||
|
||||
|
||||
class OriginRegionView(CoreOfficeMasterView):
|
||||
"""
|
||||
Master view for Origin Custom Regions
|
||||
"""
|
||||
model_class = corepos.OriginCustomRegion
|
||||
model_title = "CORE-POS Origin Region"
|
||||
url_prefix = '/core-pos/origins/regions'
|
||||
route_prefix = 'corepos.origin_regions'
|
||||
|
||||
def configure_form(self, f):
|
||||
super(OriginRegionView, self).configure_form(f)
|
||||
|
||||
if self.creating:
|
||||
f.remove('id')
|
||||
else:
|
||||
f.set_readonly('id')
|
||||
|
||||
|
||||
class OriginView(CoreOfficeMasterView):
|
||||
"""
|
||||
Base class for origin views.
|
||||
|
@ -65,6 +124,88 @@ class OriginView(CoreOfficeMasterView):
|
|||
'custom_region',
|
||||
]
|
||||
|
||||
def configure_grid(self, g):
|
||||
super(OriginView, self).configure_grid(g)
|
||||
|
||||
g.set_sort_defaults('id')
|
||||
g.set_link('name')
|
||||
g.set_link('short_name')
|
||||
|
||||
def configure_form(self, f):
|
||||
super(OriginView, self).configure_form(f)
|
||||
|
||||
# id
|
||||
if self.creating:
|
||||
f.remove('id')
|
||||
else:
|
||||
f.set_readonly('id')
|
||||
|
||||
# country
|
||||
if self.creating or self.editing:
|
||||
f.replace('country', 'country_id')
|
||||
f.set_label('country_id', "Country")
|
||||
countries = self.Session.query(corepos.OriginCountry)\
|
||||
.order_by(corepos.OriginCountry.name)\
|
||||
.all()
|
||||
values = [(c.id, str(c)) for c in countries]
|
||||
f.set_widget('country_id', dfwidget.SelectWidget(values=values))
|
||||
else:
|
||||
f.set_renderer('country', self.render_country)
|
||||
|
||||
# state_prov
|
||||
if self.creating or self.editing:
|
||||
f.replace('state_prov', 'state_prov_id')
|
||||
f.set_label('state_prov_id', "State/Province")
|
||||
stateprovs = self.Session.query(corepos.OriginStateProv)\
|
||||
.order_by(corepos.OriginStateProv.name)\
|
||||
.all()
|
||||
values = [(sp.id, str(sp)) for sp in stateprovs]
|
||||
f.set_widget('state_prov_id', dfwidget.SelectWidget(values=values))
|
||||
else:
|
||||
f.set_renderer('state_prov', self.render_stateprov)
|
||||
|
||||
# custom_region
|
||||
if self.creating or self.editing:
|
||||
f.replace('custom_region', 'custom_id')
|
||||
f.set_label('custom_id', "Custom Region")
|
||||
regions = self.Session.query(corepos.OriginCustomRegion)\
|
||||
.order_by(corepos.OriginCustomRegion.name)\
|
||||
.all()
|
||||
values = [(r.id, str(r)) for r in regions]
|
||||
f.set_widget('custom_id', dfwidget.SelectWidget(values=values))
|
||||
else:
|
||||
f.set_renderer('custom_region', self.render_region)
|
||||
|
||||
def render_country(self, origin, field):
|
||||
country = origin.country
|
||||
if country:
|
||||
text = str(country)
|
||||
if self.request.has_perm('corepos.origin_countries.view'):
|
||||
url = self.request.route_url('corepos.origin_countries.view', id=country.id)
|
||||
return tags.link_to(text, url)
|
||||
return text
|
||||
|
||||
def render_stateprov(self, origin, field):
|
||||
state_prov = origin.state_prov
|
||||
if state_prov:
|
||||
text = str(state_prov)
|
||||
if self.request.has_perm('corepos.origin_stateprov.view'):
|
||||
url = self.request.route_url('corepos.origin_stateprov.view', id=state_prov.id)
|
||||
return tags.link_to(text, url)
|
||||
return text
|
||||
|
||||
def render_region(self, origin, field):
|
||||
region = origin.custom_region
|
||||
if region:
|
||||
text = str(region)
|
||||
if self.request.has_perm('corepos.origin_regions.view'):
|
||||
url = self.request.route_url('corepos.origin_regions.view', id=region.id)
|
||||
return tags.link_to(text, url)
|
||||
return text
|
||||
|
||||
|
||||
def includeme(config):
|
||||
OriginCountryView.defaults(config)
|
||||
OriginStateProvinceView.defaults(config)
|
||||
OriginRegionView.defaults(config)
|
||||
OriginView.defaults(config)
|
||||
|
|
Loading…
Reference in a new issue