Add support for configure priorization of other dates than lot date

This commit is contained in:
jmartin 2014-04-11 13:19:27 +02:00
parent 94adc78a6e
commit 960ed312e0
7 changed files with 66 additions and 4 deletions

View file

@ -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')

20
configuration.py Normal file
View file

@ -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'

15
configuration.xml Normal file
View file

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!-- 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. -->
<tryton>
<data>
<record model="ir.ui.view" id="stock_configuration_view_form">
<field name="model">stock.configuration</field>
<field name="type">form</field>
<field name="inherit"
ref="stock.stock_configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
</data>
</tryton>

View file

@ -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:

View file

@ -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.

View file

@ -6,3 +6,4 @@ depends:
stock_lot
stock_lot_date
xml:
configuration.xml

View file

@ -0,0 +1,11 @@
<?xml version="1.0"?>
<!-- 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. -->
<data>
<xpath expr="/form/field[@name=&quot;shipment_internal_sequence&quot;]"
position="after">
<label name="lot_priority"/>
<field name="lot_priority"/>
</xpath>
</data>