本文整理汇总了Python中psi.app.service.Info.get_db方法的典型用法代码示例。如果您正苦于以下问题:Python Info.get_db方法的具体用法?Python Info.get_db怎么用?Python Info.get_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类psi.app.service.Info
的用法示例。
在下文中一共展示了Info.get_db方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_or_update_inventory_transaction
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def create_or_update_inventory_transaction(self):
from psi.app.models.inventory_transaction import InventoryTransactionLine, InventoryTransaction
from psi.app.models.enum_values import EnumValues
if self.type.code == const.DIRECT_SHIPPING_TYPE_KEY:
it_type = EnumValues.get(const.SALES_OUT_INV_TRANS_TYPE_KEY)
else:
it_type = EnumValues.get(const.FRANCHISE_SALES_OUT_INV_TRANS_TYPE_KEY)
it = self.inventory_transaction
if it is None:
it = InventoryTransaction()
it.type = it_type
self.inventory_transaction = it
it.date = self.date
it.organization = self.organization
for line in self.lines:
itl = line.inventory_transaction_line
if itl is None:
itl = InventoryTransactionLine()
itl.quantity = -line.quantity
itl.product = line.product
itl.price = line.price
itl.in_transit_quantity = 0
itl.inventory_transaction = it
line.inventory_transaction_line = itl
self.update_saleable_qty_in_purchase_inv_lines(line)
Info.get_db().session.add(it)
示例2: init_all
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def init_all(app, migrate=True):
init_logging(app)
# === Important notice to the maintainer ===
# This line was use to database = init_db(app)
# But we found session can not be cleaned among different
# Unit tests, so we add this to avoid issue
# sqlalchemy-object-already-attached-to-session
# http://stackoverflow.com/questions/24291933/sqlalchemy-object-already-attached-to-session
# A similar issue was captured on
# https://github.com/jarus/flask-testing/issues/32
# Please don't try to modify the follow four lines.
# Please don't try to modify the follow four lines.
# Please don't try to modify the follow four lines.
if Info.get_db() is None:
database = init_db(app)
else:
database = Info.get_db()
database.init_app(app)
security = init_flask_security(app, database)
init_migrate(app, database)
if migrate:
with app.app_context():
upgrade(directory=MIGRATION_DIR)
init_https(app)
init_admin_views(app, database)
babel = init_babel(app)
api = init_flask_restful(app)
init_reports(app, api)
init_jinja2_functions(app)
# init_debug_toolbar(app)
init_image_service(app)
socket_io = init_socket_io(app)
define_route_context(app, database, babel)
# define a context processor for merging flask-admin's template context
# into the flask-security views.
@security.context_processor
def security_context_processor():
from flask import url_for
return dict(
get_url=url_for
)
@app.teardown_appcontext
def shutdown_session(exception=None):
database = Info.get_db()
database.session.remove()
return socket_io
示例3: sales_amount_report
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def sales_amount_report(r_type, r_period):
limit = get_limit(r_period)
sql = sqls.SALES_AMOUNT_REPORT_SQL.format('WEEK', 'WW', limit) \
if r_period == 'week' \
else sqls.SALES_AMOUNT_REPORT_SQL.format('MONTH', 'Mon', limit)
results = Info.get_db().engine.execute(sql).fetchall()
labels, totals = [], []
for r in results:
labels.append("{0}, {1}".format(int(r[0]), gettext(r[2])))
totals.append(float(r[3]))
avg = str(format_util.format_decimal(sum(totals) / float(len(totals)))) if len(totals) > 0 else 0
labels.reverse()
totals.reverse()
ct = gettext(r_type.capitalize())
cp = gettext(r_period.capitalize())
label_tot = gettext('Total Sales {0} Per {1}').format(ct, cp)
label_avg = gettext('Average Sales {0}(Past {1} {2}(s)): {3}').format(ct, 24, cp, avg)
return dict(
data={
"labels": labels,
"details": {
"average_amount": {
"label": label_avg,
"data": [avg] * len(totals),
"style": "average"
},
"total": {
"label": label_tot,
"data": totals,
"style": "major"
}
}
},
status='success'
)
示例4: test_logic
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def test_logic():
fixture.login_as_admin(self.test_client)
user, password = object_faker.user(role_names=[
'franchise_sales_order_create',
'franchise_sales_order_view',
'franchise_sales_order_edit',
'product_view'
])
franchise_so_type = EnumValues.get(FRANCHISE_SO_TYPE_KEY)
sales_order = object_faker.sales_order(creator=user,
number_of_line=1,
type=franchise_so_type)
db_util.save_objects_commit(sales_order, user)
so_id = sales_order.id
shipped_status = EnumValues.get(SO_SHIPPED_STATUS_KEY)
fixture.login_user(self.test_client, user.email, password)
rv = self.test_client.put('/api/sales_order/' + str(so_id),
follow_redirects=True,
data=dict(status_id=shipped_status.id))
self.assertIn(b'message', rv.data)
self.assertIn(b'Status update successfully', rv.data)
self.assertEqual(rv.status_code, 200)
so_from_db = Info.get_db().session.query(SalesOrder).get(so_id)
self.assertIsNotNone(so_from_db)
self.assertEquals(SO_SHIPPED_STATUS_KEY, so_from_db.status.code)
示例5: put
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def put(self, sales_order_id):
try:
args = parser.parse_args()
status_id = args['status_id']
session = Info.get_db().session
sales_order = session.query(SalesOrder).get(sales_order_id)
status = session.query(EnumValues).get(status_id)
if status is not None and status.type.code == SO_STATUS_KEY:
if sales_order.status.code == SO_CREATED_STATUS_KEY:
if status.code == SO_SHIPPED_STATUS_KEY or status.code == SO_DELIVERED_STATUS_KEY:
sales_order.status_id = status_id
shipping = SalesOrderService.create_or_update_shipping(sales_order)
session.add(sales_order)
session.add(shipping)
SalesOrderService.update_related_po_status(sales_order, PO_SHIPPED_STATUS_KEY)
elif status.code == SO_INVALID_STATUS_KEY:
sales_order.status_id = status_id
session.add(sales_order)
po = SalesOrderService.update_related_po_status(sales_order, PO_REJECTED_STATUS_KEY)
recvs = po.po_receivings
for recv in recvs:
session.delete(recv)
session.commit()
return dict(message=gettext('Status update successfully'), status='success'), 200
else:
return dict(message=gettext('Status update not allowed'), status='error'), 201
else:
return dict(message=gettext('Invalid sales order status parameter'), status='error'), 201
except Exception as e:
return dict(message=gettext('Failed to change sales order status<br>{0}').format(e.message), status='error'), 201
示例6: get_total
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def get_total(report_type, period_type, period_number, year):
if report_type == 'amount_compare_with_last_period':
sql = sqls.GET_AMOUNT_BY_YEAR_SQL.format(period_type, period_number, year)
elif report_type == 'profit_compare_with_last_period':
sql = sqls.GET_PROFIT_BY_YEAR_SQL.format(period_type, period_number, year)
results = Info.get_db().engine.execute(sql).fetchall()
return results[0][0]
示例7: save_objects_commit
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def save_objects_commit(*objects):
"""
Save objects and commit to database
:param objects: Objects to save
"""
db = Info.get_db()
save_objects(objects)
db.session.commit()
示例8: update_related_po_status
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def update_related_po_status(sales_order, status_code):
purchase_order = SalesOrderService.get_related_po(sales_order)
session = Info.get_db().session
if purchase_order is not None:
status = EnumValues.get(status_code)
purchase_order.status = status
session.add(purchase_order)
return purchase_order
示例9: filter_by_organization
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def filter_by_organization(object_type, user=current_user):
"""
Filter object by user's organization
:param object_type: Object type to filter
:param user: User('s Organization) to use for the filter
:return: List of object filter by the user's organisation
"""
db = Info.get_db()
return db.session.query(object_type).filter_by(organization_id=user.organization_id).all()
示例10: save_objects
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def save_objects(objects):
"""
Save objects without commit them to database
:param objects: objects to save
"""
db = Info.get_db()
for obj in objects:
if obj is not None:
db.session.add(obj)
示例11: cleanup_database
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def cleanup_database(app_context):
with app_context:
db = Info.get_db()
db.session.remove()
db.engine.execute('DROP TABLE alembic_version')
db.engine.execute('DROP VIEW sales_order_detail')
db.session.commit()
db.reflect()
db.drop_all()
示例12: get_related_po
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def get_related_po(sales_order):
rt = EnumValues.get(const.FRANCHISE_PO_TO_SO_RT_KEY)
session = Info.get_db().session
related_value, purchase_order = None, None
if sales_order.type.code == const.FRANCHISE_SO_TYPE_KEY:
related_value = session.query(RelatedValues).filter_by(to_object_id=sales_order.id, relation_type_id=rt.id).first()
if related_value is not None:
purchase_order = session.query(PurchaseOrder).get(related_value.from_object_id)
return purchase_order
示例13: populate_obj
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def populate_obj(self, obj, name):
from flask import request
from psi.app.service import Info
from psi.app.utils import db_util
from psi.app.utils import file_util
images_to_del = request.form.get('images-to-delete')
if len(images_to_del) > 0:
to_del_ids = images_to_del.split(',')
for to_del_id in to_del_ids:
db_util.delete_by_id(self.object_type, to_del_id, commit=False)
files = request.files.getlist('images_placeholder')
images = getattr(obj, name)
for f in files:
if len(f.filename) > 0:
image_owner = self.object_type()
image = file_util.save_image(image_owner, f)
Info.get_db().session.add(image)
Info.get_db().session.add(image_owner)
images.append(image_owner)
setattr(obj, name, images)
示例14: delete_by_id
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def delete_by_id(obj_type, id_to_del, commit=True):
"""
Delete model object by value
:type obj_type: db.Model
:type id_to_del: int
"""
db = Info.get_db()
obj = db.session.query(obj_type).get(id_to_del)
db.session.delete(obj)
if commit:
db.session.commit()
示例15: get_by_name
# 需要导入模块: from psi.app.service import Info [as 别名]
# 或者: from psi.app.service.Info import get_db [as 别名]
def get_by_name(object_type, val, user=current_user):
"""
Get the first model object via query condition of name field
:param object_type: Object type
:param val: value of the name
:param user: user context, default to current login user.
:return: The object if found, otherwise None
"""
db = Info.get_db()
if hasattr(object_type, 'organization_id'):
return db.session.query(object_type).filter_by(name=val, organization_id=user.organization_id).first()
return db.session.query(object_type).filter_by(name=val).first()