Refactored model imports, etc.
This is in preparation for using database models only from `rattail` (i.e. no `edbob`). Mostly the model and enum imports were affected.
This commit is contained in:
parent
d838203ec7
commit
1a557f3947
|
@ -36,7 +36,7 @@ from webhelpers.html.builder import format_attrs
|
|||
|
||||
from pyramid.renderers import render
|
||||
|
||||
from edbob.core import Object
|
||||
from rattail.core import Object
|
||||
|
||||
|
||||
__all__ = ['Grid']
|
||||
|
|
|
@ -35,7 +35,7 @@ from pyramid.renderers import render
|
|||
from pyramid_simpleform import Form
|
||||
from pyramid_simpleform.renderers import FormRenderer
|
||||
|
||||
from edbob.core import Object
|
||||
from rattail.core import Object
|
||||
from edbob.util import prettify
|
||||
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
<td class="brand">${cost.product.brand or ''}</td>
|
||||
<td class="desc">${cost.product.description}</td>
|
||||
<td class="size">${cost.product.size or ''}</td>
|
||||
<td class="case-qty">${cost.case_size} ${rattail.UNIT_OF_MEASURE.get(cost.product.unit_of_measure, '')}</td>
|
||||
<td class="case-qty">${cost.case_size} ${rattail.enum.UNIT_OF_MEASURE.get(cost.product.unit_of_measure, '')}</td>
|
||||
<td class="code">${cost.code or ''}</td>
|
||||
<td class="preferred">${'X' if cost.preference == 1 else ''}</td>
|
||||
% for i in range(14):
|
||||
|
|
|
@ -37,7 +37,7 @@ from ...grids.search import BooleanSearchFilter
|
|||
from edbob.pyramid.progress import SessionProgress
|
||||
from .. import SearchableAlchemyGridView, CrudView, View
|
||||
|
||||
import rattail
|
||||
from rattail import enum
|
||||
from rattail import batches
|
||||
from ...db import Session
|
||||
from rattail.db.model import Batch
|
||||
|
@ -119,7 +119,7 @@ class BatchCrud(CrudView):
|
|||
|
||||
def fieldset(self, model):
|
||||
fs = self.make_fieldset(model)
|
||||
fs.action_type.set(renderer=EnumFieldRenderer(rattail.BATCH_ACTION))
|
||||
fs.action_type.set(renderer=EnumFieldRenderer(enum.BATCH_ACTION))
|
||||
fs.executed.set(renderer=PrettyDateTimeFieldRenderer(from_='utc'))
|
||||
fs.configure(
|
||||
include=[
|
||||
|
|
|
@ -30,41 +30,37 @@ from sqlalchemy import and_
|
|||
|
||||
from edbob.enum import EMAIL_PREFERENCE
|
||||
|
||||
from . import SearchableAlchemyGridView
|
||||
from . import SearchableAlchemyGridView, CrudView
|
||||
from ..forms import EnumFieldRenderer
|
||||
|
||||
import rattail
|
||||
from ..db import Session
|
||||
from rattail.db.model import (
|
||||
Customer, CustomerPerson, CustomerGroupAssignment,
|
||||
CustomerEmailAddress, CustomerPhoneNumber)
|
||||
from . import CrudView
|
||||
from rattail.db import model
|
||||
|
||||
|
||||
class CustomersGrid(SearchableAlchemyGridView):
|
||||
|
||||
mapped_class = Customer
|
||||
mapped_class = model.Customer
|
||||
config_prefix = 'customers'
|
||||
sort = 'name'
|
||||
|
||||
def join_map(self):
|
||||
return {
|
||||
'email':
|
||||
lambda q: q.outerjoin(CustomerEmailAddress, and_(
|
||||
CustomerEmailAddress.parent_uuid == Customer.uuid,
|
||||
CustomerEmailAddress.preference == 1)),
|
||||
lambda q: q.outerjoin(model.CustomerEmailAddress, and_(
|
||||
model.CustomerEmailAddress.parent_uuid == model.Customer.uuid,
|
||||
model.CustomerEmailAddress.preference == 1)),
|
||||
'phone':
|
||||
lambda q: q.outerjoin(CustomerPhoneNumber, and_(
|
||||
CustomerPhoneNumber.parent_uuid == Customer.uuid,
|
||||
CustomerPhoneNumber.preference == 1)),
|
||||
lambda q: q.outerjoin(model.CustomerPhoneNumber, and_(
|
||||
model.CustomerPhoneNumber.parent_uuid == model.Customer.uuid,
|
||||
model.CustomerPhoneNumber.preference == 1)),
|
||||
}
|
||||
|
||||
def filter_map(self):
|
||||
return self.make_filter_map(
|
||||
exact=['id'],
|
||||
ilike=['name'],
|
||||
email=self.filter_ilike(CustomerEmailAddress.address),
|
||||
phone=self.filter_ilike(CustomerPhoneNumber.number))
|
||||
email=self.filter_ilike(model.CustomerEmailAddress.address),
|
||||
phone=self.filter_ilike(model.CustomerPhoneNumber.number))
|
||||
|
||||
def filter_config(self):
|
||||
return self.make_filter_config(
|
||||
|
@ -77,8 +73,8 @@ class CustomersGrid(SearchableAlchemyGridView):
|
|||
def sort_map(self):
|
||||
return self.make_sort_map(
|
||||
'id', 'name',
|
||||
email=self.sorter(CustomerEmailAddress.address),
|
||||
phone=self.sorter(CustomerPhoneNumber.number))
|
||||
email=self.sorter(model.CustomerEmailAddress.address),
|
||||
phone=self.sorter(model.CustomerPhoneNumber.number))
|
||||
|
||||
def grid(self):
|
||||
g = self.make_grid()
|
||||
|
@ -106,20 +102,20 @@ class CustomersGrid(SearchableAlchemyGridView):
|
|||
|
||||
class CustomerCrud(CrudView):
|
||||
|
||||
mapped_class = Customer
|
||||
mapped_class = model.Customer
|
||||
home_route = 'customers'
|
||||
|
||||
def get_model(self, key):
|
||||
model = super(CustomerCrud, self).get_model(key)
|
||||
if model:
|
||||
return model
|
||||
model = Session.query(Customer).filter_by(id=key).first()
|
||||
model = Session.query(model.Customer).filter_by(id=key).first()
|
||||
if model:
|
||||
return model
|
||||
model = Session.query(CustomerPerson).get(key)
|
||||
model = Session.query(model.CustomerPerson).get(key)
|
||||
if model:
|
||||
return model.customer
|
||||
model = Session.query(CustomerGroupAssignment).get(key)
|
||||
model = Session.query(model.CustomerGroupAssignment).get(key)
|
||||
if model:
|
||||
return model.customer
|
||||
return None
|
||||
|
|
|
@ -26,16 +26,19 @@
|
|||
Report Views
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from .core import View
|
||||
from mako.template import Template
|
||||
from pyramid.response import Response
|
||||
|
||||
from ..db import Session
|
||||
from rattail.db.model import Vendor, Department, Product, ProductCost
|
||||
|
||||
import re
|
||||
import rattail
|
||||
from edbob.time import local_time
|
||||
|
||||
import rattail
|
||||
from rattail import enum
|
||||
from rattail.db import model
|
||||
from rattail.files import resource_path
|
||||
|
||||
|
||||
|
@ -64,13 +67,13 @@ class OrderingWorksheet(View):
|
|||
|
||||
def __call__(self):
|
||||
if self.request.params.get('vendor'):
|
||||
vendor = Session.query(Vendor).get(self.request.params['vendor'])
|
||||
vendor = Session.query(model.Vendor).get(self.request.params['vendor'])
|
||||
if vendor:
|
||||
departments = []
|
||||
uuids = self.request.params.get('departments')
|
||||
if uuids:
|
||||
for uuid in uuids.split(','):
|
||||
dept = Session.query(Department).get(uuid)
|
||||
dept = Session.query(model.Department).get(uuid)
|
||||
if dept:
|
||||
departments.append(dept)
|
||||
preferred_only = self.request.params.get('preferred_only') == '1'
|
||||
|
@ -87,12 +90,12 @@ class OrderingWorksheet(View):
|
|||
Rendering engine for the ordering worksheet report.
|
||||
"""
|
||||
|
||||
q = Session.query(ProductCost)
|
||||
q = q.join(Product)
|
||||
q = q.filter(ProductCost.vendor == vendor)
|
||||
q = q.filter(Product.department_uuid.in_([x.uuid for x in departments]))
|
||||
q = Session.query(model.ProductCost)
|
||||
q = q.join(model.Product)
|
||||
q = q.filter(model.ProductCost.vendor == vendor)
|
||||
q = q.filter(model.Product.department_uuid.in_([x.uuid for x in departments]))
|
||||
if preferred_only:
|
||||
q = q.filter(ProductCost.preference == 1)
|
||||
q = q.filter(model.ProductCost.preference == 1)
|
||||
|
||||
costs = {}
|
||||
for cost in q:
|
||||
|
@ -138,7 +141,7 @@ class InventoryWorksheet(View):
|
|||
This is the "Inventory Worksheet" report.
|
||||
"""
|
||||
|
||||
departments = Session.query(Department)
|
||||
departments = Session.query(model.Department)
|
||||
|
||||
if self.request.params.get('department'):
|
||||
department = departments.get(self.request.params['department'])
|
||||
|
@ -150,7 +153,7 @@ class InventoryWorksheet(View):
|
|||
response.text = body
|
||||
return response
|
||||
|
||||
departments = departments.order_by(rattail.Department.name)
|
||||
departments = departments.order_by(model.Department.name)
|
||||
departments = departments.all()
|
||||
return{'departments': departments}
|
||||
|
||||
|
@ -160,12 +163,12 @@ class InventoryWorksheet(View):
|
|||
"""
|
||||
|
||||
def get_products(subdepartment):
|
||||
q = Session.query(rattail.Product)
|
||||
q = q.outerjoin(rattail.Brand)
|
||||
q = q.filter(rattail.Product.subdepartment == subdepartment)
|
||||
q = Session.query(model.Product)
|
||||
q = q.outerjoin(model.Brand)
|
||||
q = q.filter(model.Product.subdepartment == subdepartment)
|
||||
if self.request.params.get('weighted-only'):
|
||||
q = q.filter(rattail.Product.unit_of_measure == rattail.UNIT_OF_MEASURE_POUND)
|
||||
q = q.order_by(rattail.Brand.name, rattail.Product.description)
|
||||
q = q.filter(model.Product.unit_of_measure == enum.UNIT_OF_MEASURE_POUND)
|
||||
q = q.order_by(model.Brand.name, model.Product.description)
|
||||
return q.all()
|
||||
|
||||
now = local_time()
|
||||
|
|
Loading…
Reference in a new issue