Files
@ 26e7d55e67fc
Branch filter:
Location: rattail-project/rattail/rattail/db/model/labels.py
26e7d55e67fc
4.1 KiB
text/x-python
Update changelog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | # -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Data Models for Label Printing
"""
from __future__ import unicode_literals, absolute_import
import six
import sqlalchemy as sa
from sqlalchemy.orm import object_session
from .core import Base, uuid_column
from rattail.util import load_object
@six.python_2_unicode_compatible
class LabelProfile(Base):
"""
Represents a collection of settings for product label printing.
"""
__tablename__ = 'label_profile'
__versioned__ = {}
uuid = uuid_column()
ordinal = sa.Column(sa.Integer())
code = sa.Column(sa.String(length=30), nullable=True, doc="""
Supposedly unique "code" for the label profile. May be useful for
identification of a common label type across nodes, for instance.
""")
description = sa.Column(sa.String(length=50))
printer_spec = sa.Column(sa.String(length=255))
formatter_spec = sa.Column(sa.String(length=255))
format = sa.Column(sa.Text())
visible = sa.Column(sa.Boolean())
sync_me = sa.Column(sa.Boolean(), nullable=True, doc="""
Flag indicating whether this label profile should be synced across "all"
other Rattail systems across the organization.
""")
_printer = None
_formatter = None
def __str__(self):
return str(self.description or '')
# TODO: Copy elsewhere, deprecate and remove this logic (not strictly an
# API call from within data model, but should go with the others, below).
def get_formatter(self, config):
if not self._formatter and self.formatter_spec:
try:
formatter = load_object(self.formatter_spec)
except AttributeError:
pass
else:
self._formatter = formatter(config)
self._formatter.format = self.format
return self._formatter
# TODO: Copy elsewhere, deprecate and remove this logic (API call from
# within data model).
def get_printer(self, config):
if not self._printer and self.printer_spec:
try:
printer = load_object(self.printer_spec)
except AttributeError:
pass
else:
self._printer = printer(config)
for name in printer.required_settings:
setattr(printer, name, self.get_printer_setting(name))
self._printer.formatter = self.get_formatter(config)
return self._printer
# TODO: Copy elsewhere, deprecate and remove this logic (API call from
# within data model).
def get_printer_setting(self, name):
from rattail.db.api import get_setting
if self.uuid is None:
return None
session = object_session(self)
name = 'labels.{0}.printer.{1}'.format(self.uuid, name)
return get_setting(session, name)
# TODO: Copy elsewhere, deprecate and remove this logic (API call from
# within data model).
def save_printer_setting(self, name, value):
from rattail.db.api import save_setting
session = object_session(self)
if self.uuid is None:
session.flush()
name = 'labels.{0}.printer.{1}'.format(self.uuid, name)
save_setting(session, name, value)
|