diff --git a/__init__.py b/__init__.py
index c079802..bace584 100644
--- a/__init__.py
+++ b/__init__.py
@@ -2,11 +2,13 @@
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.pool import Pool
+from .configuration import *
from .stock import *
def register():
Pool.register(
+ Configuration,
ShipmentOut,
module='stock_lot_out_autoassign', type_='model')
diff --git a/configuration.py b/configuration.py
new file mode 100644
index 0000000..df13c88
--- /dev/null
+++ b/configuration.py
@@ -0,0 +1,20 @@
+# This file is part of the stock_lot_out_autoassign module for Tryton.
+# The COPYRIGHT file at the top level of this repository contains
+# the full copyright notices and license terms.
+from trytond.model import fields
+from trytond.pool import PoolMeta
+
+__all__ = ['Configuration']
+__metaclass__ = PoolMeta
+
+
+class Configuration:
+ __name__ = 'stock.configuration'
+ lot_priority = fields.Selection([
+ ('lot_date', 'Date Lot'),
+ ],
+ 'Lot Priority', required=True)
+
+ @staticmethod
+ def default_lot_priority():
+ return 'lot_date'
diff --git a/configuration.xml b/configuration.xml
new file mode 100644
index 0000000..0176ab2
--- /dev/null
+++ b/configuration.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+ stock.configuration
+ form
+
+ configuration_form
+
+
+
diff --git a/stock.py b/stock.py
index 3c87e95..350b5de 100644
--- a/stock.py
+++ b/stock.py
@@ -16,6 +16,7 @@ class ShipmentOut:
@Workflow.transition('assigned')
def assign(cls, shipments):
pool = Pool()
+ Configuration = pool.get('stock.configuration')
Lot = pool.get('stock.lot')
Move = pool.get('stock.move')
Location = pool.get('stock.location')
@@ -23,14 +24,19 @@ class ShipmentOut:
super(ShipmentOut, cls).assign(shipments)
- context = {}
+ configuration = Configuration(1)
+ lot_priority = configuration.lot_priority or 'lot_date'
+
+ transaction = Transaction()
+ context = transaction.context
+
locations = Location.search([
('type', '=', 'storage'),
])
context['locations'] = [l.id for l in locations]
context['stock_date_end'] = Date.today()
- with Transaction().set_context(context):
+ with transaction.set_context(context):
for shipment in shipments:
for move in shipment.inventory_moves:
if not move.lot and move.product.lot_is_required(
@@ -39,9 +45,10 @@ class ShipmentOut:
lots = Lot.search([
('product', '=', move.product.id),
('quantity', '>', 0.0),
- ], order=[('lot_date', 'ASC')])
+ ], order=[(lot_priority, 'ASC')])
for lot in lots:
stock_available = lot.forecast_quantity
+ stock_quantity = lot.quantity
if stock_available <= 0.0:
continue
if stock_available < rest:
diff --git a/tests/test_stock_lot_out_autoassign.py b/tests/test_stock_lot_out_autoassign.py
index 56bae73..f951ca4 100644
--- a/tests/test_stock_lot_out_autoassign.py
+++ b/tests/test_stock_lot_out_autoassign.py
@@ -12,7 +12,7 @@ if os.path.isdir(DIR):
import unittest
import trytond.tests.test_tryton
-from trytond.tests.test_tryton import test_depends
+from trytond.tests.test_tryton import test_depends, test_view
class StockLotOutAutoassignTestCase(unittest.TestCase):
@@ -23,6 +23,12 @@ class StockLotOutAutoassignTestCase(unittest.TestCase):
def setUp(self):
trytond.tests.test_tryton.install_module('stock_lot_out_autoassign')
+ def test0005views(self):
+ '''
+ Test views.
+ '''
+ test_view('stock_lot_out_autoassign')
+
def test0006depends(self):
'''
Test depends.
diff --git a/tryton.cfg b/tryton.cfg
index 2ca6453..7eedd3b 100644
--- a/tryton.cfg
+++ b/tryton.cfg
@@ -6,3 +6,4 @@ depends:
stock_lot
stock_lot_date
xml:
+ configuration.xml
diff --git a/view/configuration_form.xml b/view/configuration_form.xml
new file mode 100644
index 0000000..960aa79
--- /dev/null
+++ b/view/configuration_form.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+