changeset 3c66e7357512 in modules/stock_package_shipping:default
details: 
https://hg.tryton.org/modules/stock_package_shipping?cmd=changeset;node=3c66e7357512
description:
        Add configuration option to store label in filestore

        issue10063
        review343691002
diffstat:

 CHANGELOG             |   1 +
 doc/conf.py           |  61 +++++++++++++++++++++++++++++++++++++++++++++++++++
 doc/configuration.rst |  29 ++++++++++++++++++++++++
 doc/index.rst         |   5 ++++
 setup.py              |   5 +++-
 stock.py              |  13 ++++++++++-
 6 files changed, 112 insertions(+), 2 deletions(-)

diffs (172 lines):

diff -r d848be07117b -r 3c66e7357512 CHANGELOG
--- a/CHANGELOG Sun Dec 20 19:57:17 2020 +0100
+++ b/CHANGELOG Thu Feb 25 21:21:56 2021 +0100
@@ -1,3 +1,4 @@
+* Add configuration option to store label in filestore
 * Manage supplier shipment returns
 
 Version 5.8.0 - 2020-11-02
diff -r d848be07117b -r 3c66e7357512 doc/conf.py
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/conf.py       Thu Feb 25 21:21:56 2021 +0100
@@ -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 -r d848be07117b -r 3c66e7357512 doc/configuration.rst
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/configuration.rst     Thu Feb 25 21:21:56 2021 +0100
@@ -0,0 +1,29 @@
+*************
+Configuration
+*************
+
+The *Stock Package Shipping Module* uses some settings from the
+``[stock_package_shipping]`` section of the :doc:`configuration file
+<trytond:topics/configuration>`.
+
+.. _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
+<config-stock_package_shipping.filestore>` setting is in use.
+
+The default value is: ``None``
diff -r d848be07117b -r 3c66e7357512 doc/index.rst
--- a/doc/index.rst     Sun Dec 20 19:57:17 2020 +0100
+++ b/doc/index.rst     Thu Feb 25 21:21:56 2021 +0100
@@ -52,3 +52,8 @@
 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 -r d848be07117b -r 3c66e7357512 setup.py
--- a/setup.py  Sun Dec 20 19:57:17 2020 +0100
+++ b/setup.py  Thu Feb 25 21:21:56 2021 +0100
@@ -10,9 +10,12 @@
 
 
 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 -r d848be07117b -r 3c66e7357512 stock.py
--- a/stock.py  Sun Dec 20 19:57:17 2020 +0100
+++ b/stock.py  Thu Feb 25 21:21:56 2021 +0100
@@ -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 .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 @@
         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):

Reply via email to