mirror of
https://github.com/NaN-tic/trytond-stock_lot_out_autoassign.git
synced 2023-12-13 21:30:23 +01:00
Add support for configure priorization of other dates than lot date
This commit is contained in:
parent
94adc78a6e
commit
960ed312e0
7 changed files with 66 additions and 4 deletions
|
@ -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
20
configuration.py
Normal 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
15
configuration.xml
Normal 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>
|
13
stock.py
13
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:
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -6,3 +6,4 @@ depends:
|
|||
stock_lot
|
||||
stock_lot_date
|
||||
xml:
|
||||
configuration.xml
|
||||
|
|
11
view/configuration_form.xml
Normal file
11
view/configuration_form.xml
Normal 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="shipment_internal_sequence"]"
|
||||
position="after">
|
||||
<label name="lot_priority"/>
|
||||
<field name="lot_priority"/>
|
||||
</xpath>
|
||||
</data>
|
Loading…
Reference in a new issue