Stock Shipment Out Scanning with carrier and labels
task-030266
This commit is contained in:
parent
7c789b238d
commit
85deb7209e
11
__init__.py
11
__init__.py
|
@ -2,13 +2,16 @@
|
|||
#The COPYRIGHT file at the top level of this repository contains
|
||||
#the full copyright notices and license terms.
|
||||
from trytond.pool import Pool
|
||||
from .shipment import *
|
||||
from . import shipment
|
||||
|
||||
def register():
|
||||
Pool.register(
|
||||
ShipmentOutPicking,
|
||||
ShipmentOutPickingResult,
|
||||
shipment.ShipmentOutPicking,
|
||||
shipment.ShipmentOutPickingResult,
|
||||
shipment.ShipmentOutScanningStart,
|
||||
shipment.ShipmentOutScanningResult,
|
||||
module='stock_picking_carrier', type_='model')
|
||||
Pool.register(
|
||||
ShipmentOutPacked,
|
||||
shipment.ShipmentOutPacked,
|
||||
shipment.ShipmentOutScanning,
|
||||
module='stock_picking_carrier', type_='wizard')
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
#
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
msgctxt "error:stock.shipment.out.packed:"
|
||||
msgid "Not return API \"%(carrier)s\" a label"
|
||||
msgstr "No s'ha retornat una etiqueta de la API \"%(carrier)s\""
|
||||
msgstr "No se ha devuelto la etiqueta API \"%(carrier)s\""
|
||||
|
||||
msgctxt "error:stock.shipment.out.scanning:"
|
||||
msgid "Not return API \"%(carrier)s\" a label"
|
||||
msgstr "No se ha devuelto la etiqueta API \"%(carrier)s\""
|
||||
|
||||
msgctxt "field:stock.shipment.out.picking,carrier:"
|
||||
msgid "Carrier"
|
||||
|
@ -16,8 +20,24 @@ msgstr "Etiqueta"
|
|||
|
||||
msgctxt "field:stock.shipment.out.picking.result,label_name:"
|
||||
msgid "Label Name"
|
||||
msgstr "Nom etiqueta"
|
||||
msgstr "Nombre etiqueta"
|
||||
|
||||
msgctxt "field:stock.shipment.out.scanning.result,label:"
|
||||
msgid "Label"
|
||||
msgstr "Etiqueta"
|
||||
|
||||
msgctxt "field:stock.shipment.out.scanning.result,label_name:"
|
||||
msgid "Label Name"
|
||||
msgstr "Nombre etiqueta"
|
||||
|
||||
msgctxt "field:stock.shipment.out.scanning.start,carrier:"
|
||||
msgid "Carrier"
|
||||
msgstr "Transportista"
|
||||
|
||||
msgctxt "help:stock.shipment.out.picking,carrier:"
|
||||
msgid "Send shipment to API carrier"
|
||||
msgstr "Envia l'albarà a la API del transportista"
|
||||
msgstr "Envia el albarán a la API del transportista"
|
||||
|
||||
msgctxt "help:stock.shipment.out.scanning.start,carrier:"
|
||||
msgid "Send shipment to API carrier"
|
||||
msgstr "Envia el albarán a la API del transportista"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#
|
||||
#
|
||||
msgid ""
|
||||
msgstr "Content-Type: text/plain; charset=utf-8\n"
|
||||
|
||||
|
@ -6,6 +6,10 @@ msgctxt "error:stock.shipment.out.packed:"
|
|||
msgid "Not return API \"%(carrier)s\" a label"
|
||||
msgstr "No se ha devuelto la etiqueta API \"%(carrier)s\""
|
||||
|
||||
msgctxt "error:stock.shipment.out.scanning:"
|
||||
msgid "Not return API \"%(carrier)s\" a label"
|
||||
msgstr "No se ha devuelto la etiqueta API \"%(carrier)s\""
|
||||
|
||||
msgctxt "field:stock.shipment.out.picking,carrier:"
|
||||
msgid "Carrier"
|
||||
msgstr "Transportista"
|
||||
|
@ -18,6 +22,22 @@ msgctxt "field:stock.shipment.out.picking.result,label_name:"
|
|||
msgid "Label Name"
|
||||
msgstr "Nombre etiqueta"
|
||||
|
||||
msgctxt "field:stock.shipment.out.scanning.result,label:"
|
||||
msgid "Label"
|
||||
msgstr "Etiqueta"
|
||||
|
||||
msgctxt "field:stock.shipment.out.scanning.result,label_name:"
|
||||
msgid "Label Name"
|
||||
msgstr "Nombre etiqueta"
|
||||
|
||||
msgctxt "field:stock.shipment.out.scanning.start,carrier:"
|
||||
msgid "Carrier"
|
||||
msgstr "Transportista"
|
||||
|
||||
msgctxt "help:stock.shipment.out.picking,carrier:"
|
||||
msgid "Send shipment to API carrier"
|
||||
msgstr "Envia el albarán a la API del transportista"
|
||||
|
||||
msgctxt "help:stock.shipment.out.scanning.start,carrier:"
|
||||
msgid "Send shipment to API carrier"
|
||||
msgstr "Envia el albarán a la API del transportista"
|
||||
|
|
90
setup.py
90
setup.py
|
@ -1,78 +1,60 @@
|
|||
#!/usr/bin/env python
|
||||
# This file is part stock_picking_carrier module for Tryton.
|
||||
# The COPYRIGHT file at the top level of this repository contains
|
||||
# the full copyright notices and license terms.
|
||||
|
||||
# encoding: utf-8
|
||||
#This file is part stock_picking_carrier module for Tryton.
|
||||
#The COPYRIGHT file at the top level of this repository contains
|
||||
#the full copyright notices and license terms.
|
||||
from setuptools import setup
|
||||
import re
|
||||
import os
|
||||
import io
|
||||
try:
|
||||
from configparser import ConfigParser
|
||||
except ImportError:
|
||||
from ConfigParser import ConfigParser
|
||||
import ConfigParser
|
||||
|
||||
MODULE = 'stock_picking_carrier'
|
||||
PREFIX = 'trytonzz'
|
||||
MODULE2PREFIX = {}
|
||||
|
||||
|
||||
def read(fname):
|
||||
return io.open(
|
||||
os.path.join(os.path.dirname(__file__), fname),
|
||||
'r', encoding='utf-8').read()
|
||||
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
||||
|
||||
def get_require_version(name):
|
||||
if minor_version % 2:
|
||||
require = '%s >= %s.%s.dev0, < %s.%s'
|
||||
else:
|
||||
require = '%s >= %s.%s, < %s.%s'
|
||||
require %= (name, major_version, minor_version,
|
||||
major_version, minor_version + 1)
|
||||
return require
|
||||
|
||||
config = ConfigParser()
|
||||
config = ConfigParser.ConfigParser()
|
||||
config.readfp(open('tryton.cfg'))
|
||||
info = dict(config.items('tryton'))
|
||||
for key in ('depends', 'extras_depend', 'xml'):
|
||||
if key in info:
|
||||
info[key] = info[key].strip().splitlines()
|
||||
version = info.get('version', '0.0.1')
|
||||
major_version, minor_version, _ = version.split('.', 2)
|
||||
major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2)
|
||||
major_version = int(major_version)
|
||||
minor_version = int(minor_version)
|
||||
name = 'trytonzz_stock_picking_carrier'
|
||||
download_url = 'https://bitbucket.org/zikzakmedia/trytond-stock_picking_carrier'
|
||||
|
||||
requires = []
|
||||
for dep in info.get('depends', []):
|
||||
if not re.match(r'(ir|res)(\W|$)', dep):
|
||||
if not re.match(r'(ir|res|webdav)(\W|$)', dep):
|
||||
prefix = MODULE2PREFIX.get(dep, 'trytond')
|
||||
requires.append(get_require_version('%s_%s' % (prefix, dep)))
|
||||
requires.append(get_require_version('trytond'))
|
||||
requires.append('%s_%s >= %s.%s, < %s.%s' %
|
||||
(prefix, dep, major_version, minor_version,
|
||||
major_version, minor_version + 1))
|
||||
requires.append('trytond >= %s.%s, < %s.%s' %
|
||||
(major_version, minor_version, major_version, minor_version + 1))
|
||||
|
||||
tests_require = []
|
||||
dependency_links = []
|
||||
if minor_version % 2:
|
||||
# Add development index for testing with proteus
|
||||
dependency_links.append('https://trydevpi.tryton.org/')
|
||||
tests_require = ['proteus >= %s.%s, < %s.%s' %
|
||||
(major_version, minor_version, major_version, minor_version + 1)]
|
||||
|
||||
setup(name=name,
|
||||
version=version,
|
||||
description='Tryton Stock Picking Carrier Module',
|
||||
setup(name='%s_%s' % (PREFIX, MODULE),
|
||||
version=info.get('version', '0.0.1'),
|
||||
description='Tryton module to send shipment to carrier API',
|
||||
long_description=read('README'),
|
||||
author='Zikzakmedia SL',
|
||||
author_email='zikzak@zikzakmedia.com',
|
||||
url='https://bitbucket.org/zikzakmedia/',
|
||||
download_url=download_url,
|
||||
keywords='',
|
||||
package_dir={'trytond.modules.stock_picking_carrier': '.'},
|
||||
url='http://www.zikzakmedia.com/',
|
||||
download_url='https://bitbucket.org/zikzakmedia/trytond-%s' % MODULE,
|
||||
package_dir={'trytond.modules.%s' % MODULE: '.'},
|
||||
packages=[
|
||||
'trytond.modules.stock_picking_carrier',
|
||||
'trytond.modules.stock_picking_carrier.tests',
|
||||
'trytond.modules.%s' % MODULE,
|
||||
'trytond.modules.%s.tests' % MODULE,
|
||||
],
|
||||
package_data={
|
||||
'trytond.modules.stock_picking_carrier': (info.get('xml', [])
|
||||
+ ['tryton.cfg', 'view/*.xml', 'locale/*.po', '*.odt',
|
||||
'icons/*.svg', 'tests/*.rst']),
|
||||
'trytond.modules.%s' % MODULE: (info.get('xml', [])
|
||||
+ ['tryton.cfg', 'view/*.xml', 'locale/*.po']),
|
||||
},
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
|
@ -89,31 +71,21 @@ setup(name=name,
|
|||
'Natural Language :: English',
|
||||
'Natural Language :: French',
|
||||
'Natural Language :: German',
|
||||
'Natural Language :: Hungarian',
|
||||
'Natural Language :: Italian',
|
||||
'Natural Language :: Portuguese (Brazilian)',
|
||||
'Natural Language :: Russian',
|
||||
'Natural Language :: Slovenian',
|
||||
'Natural Language :: Spanish',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python :: 2.6',
|
||||
'Programming Language :: Python :: 2.7',
|
||||
'Programming Language :: Python :: 3.3',
|
||||
'Programming Language :: Python :: 3.4',
|
||||
'Programming Language :: Python :: 3.5',
|
||||
'Programming Language :: Python :: Implementation :: CPython',
|
||||
'Programming Language :: Python :: Implementation :: PyPy',
|
||||
'Topic :: Office/Business',
|
||||
],
|
||||
license='GPL-3',
|
||||
install_requires=requires,
|
||||
dependency_links=dependency_links,
|
||||
zip_safe=False,
|
||||
entry_points="""
|
||||
[trytond.modules]
|
||||
stock_picking_carrier = trytond.modules.stock_picking_carrier
|
||||
""",
|
||||
%s = trytond.modules.%s
|
||||
""" % (MODULE, MODULE),
|
||||
test_suite='tests',
|
||||
test_loader='trytond.test_loader:Loader',
|
||||
tests_require=tests_require,
|
||||
use_2to3=True,
|
||||
)
|
||||
|
|
69
shipment.py
69
shipment.py
|
@ -7,7 +7,8 @@ from trytond.model import fields
|
|||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['ShipmentOutPicking', 'ShipmentOutPickingResult', 'ShipmentOutPacked']
|
||||
__all__ = ['ShipmentOutPicking', 'ShipmentOutPickingResult', 'ShipmentOutPacked',
|
||||
'ShipmentOutScanningStart', 'ShipmentOutScanningResult', 'ShipmentOutScanning']
|
||||
|
||||
|
||||
class ShipmentOutPicking:
|
||||
|
@ -40,8 +41,7 @@ class ShipmentOutPacked:
|
|||
})
|
||||
|
||||
def transition_packed(self):
|
||||
pool = Pool()
|
||||
Shipment = pool.get('stock.shipment.out')
|
||||
Shipment = Pool().get('stock.shipment.out')
|
||||
|
||||
super(ShipmentOutPacked, self).transition_packed()
|
||||
shipment = self.result.shipment
|
||||
|
@ -85,3 +85,66 @@ class ShipmentOutPacked:
|
|||
res['label'] = self.result.label
|
||||
res['label_name'] =self.result.label_name
|
||||
return res
|
||||
|
||||
|
||||
class ShipmentOutScanningStart:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'stock.shipment.out.scanning.start'
|
||||
carrier = fields.Boolean('Carrier',
|
||||
help='Send shipment to API carrier')
|
||||
|
||||
@staticmethod
|
||||
def default_carrier():
|
||||
return True
|
||||
|
||||
|
||||
class ShipmentOutScanningResult:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'stock.shipment.out.scanning.result'
|
||||
label = fields.Binary('Label', filename='label_name')
|
||||
label_name = fields.Char('Label Name')
|
||||
|
||||
|
||||
class ShipmentOutScanning:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'stock.shipment.out.scanning'
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super(ShipmentOutScanning, cls).__setup__()
|
||||
cls._error_messages.update({
|
||||
'not_label': 'Not return API "%(carrier)s" a label',
|
||||
})
|
||||
|
||||
def transition_packed(self):
|
||||
Shipment = Pool().get('stock.shipment.out')
|
||||
|
||||
packed = super(ShipmentOutScanning, self).transition_packed()
|
||||
if packed == 'start':
|
||||
return 'start'
|
||||
shipment = self.result.shipment
|
||||
|
||||
# Send shipment to carrier API
|
||||
if self.start.carrier and shipment.carrier:
|
||||
refs, labs, errs = Shipment.send_shipment_api(shipment)
|
||||
|
||||
if labs:
|
||||
lab, = labs
|
||||
self.result.labs = labs
|
||||
self.result.label = fields.Binary.cast(open(lab, "rb").read())
|
||||
self.result.label_name = lab.split('/')[2]
|
||||
return 'result'
|
||||
else:
|
||||
self.result.note += self.raise_user_error('not_label', {
|
||||
'carrier': shipment.carrier.rec_name,
|
||||
}, raise_exception=False)
|
||||
self.result.labs = None
|
||||
self.result.label = None
|
||||
self.result.label_name = None
|
||||
return 'result'
|
||||
|
||||
def default_result(self, fields):
|
||||
res = super(ShipmentOutScanning, self).default_result(fields)
|
||||
res['label'] = self.result.label
|
||||
res['label_name'] =self.result.label_name
|
||||
return res
|
||||
|
|
19
shipment.xml
19
shipment.xml
|
@ -3,15 +3,28 @@
|
|||
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
|
||||
<tryton>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="stock_shipment_out_picking">
|
||||
<!-- Stock Shipment Out Picking -->
|
||||
<record model="ir.ui.view" id="stock_shipment_out_picking_start">
|
||||
<field name="model">stock.shipment.out.picking</field>
|
||||
<field name="inherit" ref="stock_picking.stock_shipment_out_picking"/>
|
||||
<field name="name">stock_shipment_out_picking</field>
|
||||
<field name="inherit" ref="stock_picking.stock_shipment_out_picking_start"/>
|
||||
<field name="name">stock_shipment_out_picking_start</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="stock_shipment_out_picking_result">
|
||||
<field name="model">stock.shipment.out.picking.result</field>
|
||||
<field name="inherit" ref="stock_picking.stock_shipment_out_picking_result"/>
|
||||
<field name="name">stock_shipment_out_picking_result</field>
|
||||
</record>
|
||||
|
||||
<!-- Stock Shipment Out Scanning -->
|
||||
<record model="ir.ui.view" id="stock_shipment_out_scanning_start">
|
||||
<field name="model">stock.shipment.out.scanning.start</field>
|
||||
<field name="inherit" ref="stock_picking.stock_shipment_out_scanning_start"/>
|
||||
<field name="name">stock_shipment_out_scanning_start</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="stock_shipment_out_scanning_result">
|
||||
<field name="model">stock.shipment.out.scanning.result</field>
|
||||
<field name="inherit" ref="stock_picking.stock_shipment_out_scanning_result"/>
|
||||
<field name="name">stock_shipment_out_scanning_result</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of stock_picking_carrier. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/field[@name='shipment']" position="after">
|
||||
<label name="label"/>
|
||||
<field name="label"/>
|
||||
<field name="label_name" invisible="1"/>
|
||||
</xpath>
|
||||
</data>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- This file is part of stock_picking_carrier. The COPYRIGHT file at the top level of
|
||||
this repository contains the full copyright notices and license terms. -->
|
||||
<data>
|
||||
<xpath
|
||||
expr="/form/field[@name='product']" position="after">
|
||||
<label name="carrier"/>
|
||||
<field name="carrier"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in New Issue