diff --git a/CHANGELOG b/CHANGELOG index 37cbe54852..1beb5dc025 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add configuration option to store label in filestore * Manage supplier shipment returns Version 5.8.0 - 2020-11-02 diff --git a/doc/conf.py b/doc/conf.py new file mode 100644 index 0000000000..8513b72dd2 --- /dev/null +++ b/doc/conf.py @@ -0,0 +1,61 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +modules_url = 'https://docs.tryton.org/projects/modules-{module}/en/{series}/' +trytond_url = 'https://docs.tryton.org/projects/server/en/{series}/' + + +def get_info(): + import configparser + import os + import subprocess + import sys + + module_dir = os.path.dirname(os.path.dirname(__file__)) + + config = configparser.ConfigParser() + config.read_file(open(os.path.join(module_dir, 'tryton.cfg'))) + info = dict(config.items('tryton')) + + result = subprocess.run( + [sys.executable, 'setup.py', '--name'], + stdout=subprocess.PIPE, check=True, cwd=module_dir) + info['name'] = result.stdout.decode('utf-8').strip() + + result = subprocess.run( + [sys.executable, 'setup.py', '--version'], + stdout=subprocess.PIPE, check=True, cwd=module_dir) + version = result.stdout.decode('utf-8').strip() + if 'dev' in version: + info['series'] = 'latest' + else: + info['series'] = '.'.join(version.split('.', 2)[:2]) + + for key in {'depends', 'extras_depend'}: + info[key] = info.get(key, '').strip().splitlines() + info['modules'] = set(info['depends'] + info['extras_depend']) + info['modules'] -= {'ir', 'res'} + + return info + + +info = get_info() + +master_doc = 'index' +project = info['name'] +release = version = info['series'] +default_role = 'ref' +highlight_language = 'none' +extensions = [ + 'sphinx.ext.intersphinx', + ] +intersphinx_mapping = { + 'trytond': (trytond_url.format(series=version), None), + } +intersphinx_mapping.update({ + m: (modules_url.format( + module=m.replace('_', '-'), series=version), None) + for m in info['modules'] + }) + +del get_info, info, modules_url, trytond_url diff --git a/doc/configuration.rst b/doc/configuration.rst new file mode 100644 index 0000000000..97fd2d25ff --- /dev/null +++ b/doc/configuration.rst @@ -0,0 +1,29 @@ +************* +Configuration +************* + +The *Stock Package Shipping Module* uses some settings from the +``[stock_package_shipping]`` section of the :doc:`configuration file +`. + +.. _config-stock_package_shipping.filestore: + +``filestore`` +============= + +This configuration value indicates whether the shipping label should be stored +in the :py:mod:`trytond:trytond.filestore` (``True``) or the database +(``False``). + +The default value is: ``False`` + +.. _config-stock_package_shipping.store_prefix: + +``store_prefix`` +================ + +This is the prefix to use with the :py:mod:`trytond:trytond.filestore`. +This value is only used when the `filestore +` setting is in use. + +The default value is: ``None`` diff --git a/doc/index.rst b/doc/index.rst index 87569742e8..c8ec097f91 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -52,3 +52,8 @@ button triggers a wizard that is overridden in shipping service specific modules. The starting state of the wizard is a ``StateTransition``. Its linked method is overridden in shipping service modules in order to communicate with the service. + +.. toctree:: + :maxdepth: 2 + + configuration diff --git a/setup.py b/setup.py index b3a7045eac..9d32d6b9d1 100755 --- a/setup.py +++ b/setup.py @@ -10,9 +10,12 @@ from setuptools import setup, find_packages def read(fname): - return io.open( + content = io.open( os.path.join(os.path.dirname(__file__), fname), 'r', encoding='utf-8').read() + content = re.sub( + r'(?m)^\.\. toctree::\r?\n((^$|^\s.*$)\r?\n)*', '', content) + return content def get_require_version(name): diff --git a/stock.py b/stock.py index 2eb0276741..81512ec47b 100644 --- a/stock.py +++ b/stock.py @@ -1,6 +1,7 @@ # This file is part of Tryton. The COPYRIGHT file at the top level of # this repository contains the full copyright notices and license terms. +from trytond.config import config from trytond.i18n import gettext from trytond.model import Workflow, ModelView, fields from trytond.model.exceptions import AccessError @@ -11,6 +12,13 @@ from trytond.wizard import Wizard, StateTransition from .exceptions import PackWarning +if config.getboolean('stock_package_shipping', 'filestore', default=False): + file_id = 'shipping_label_id' + store_prefix = config.get( + 'stock_package_shipping', 'store_prefix', default=None) +else: + file_id = store_prefix = None + class PackageType(metaclass=PoolMeta): __name__ = 'stock.package.type' @@ -87,7 +95,10 @@ class Package(metaclass=PoolMeta): states={ 'readonly': Eval('_parent_shipment', {}).get('carrier', False), }) - shipping_label = fields.Binary('Shipping Label', readonly=True) + shipping_label = fields.Binary( + "Shipping Label", readonly=True, + file_id=file_id, store_prefix=store_prefix) + shipping_label_id = fields.Char("Shipping Label ID", readonly=True) @classmethod def search_rec_name(cls, name, clause):