This commit is contained in:
?ngel ?lvarez Serra 2014-01-29 10:59:05 +01:00
parent eb3d0add10
commit 48f153555a
2 changed files with 293 additions and 0 deletions

292
issue134_399.diff Normal file
View File

@ -0,0 +1,292 @@
Index: move.py
===================================================================
--- ./modules/stock/move.py
+++ ./modules/stock/move.py
@@ -181,7 +181,11 @@
| Eval('shipment'))
}, depends=['state', 'shipment'],
select=True)
- effective_date = fields.Date("Effective Date", readonly=True, select=True)
+ effective_date = fields.Date("Effective Date", readonly=True, select=True,
+ states={
+ 'required': Eval('state') == 'done',
+ },
+ depends=['state'])
state = fields.Selection([
('draft', 'Draft'),
('assigned', 'Assigned'),
@@ -565,36 +569,38 @@
product.default_uom, round=True)
return internal_quantity
+ def set_effective_date(self):
+ pool = Pool()
+ Date = pool.get('ir.date')
+
+ if not self.effective_date and self.shipment:
+ self.effective_date = self.shipment.effective_date
+ if not self.effective_date:
+ self.effective_date = Date.today()
+
@classmethod
@ModelView.button
@Workflow.transition('draft')
def draft(cls, moves):
- pass
+ cls.write(moves, {
+ 'effective_date': None,
+ })
@classmethod
@ModelView.button
@Workflow.transition('assigned')
def assign(cls, moves):
- pool = Pool()
- Date = pool.get('ir.date')
-
- today = Date.today()
for move in moves:
if not move.effective_date:
- move.effective_date = today
- move.save()
+ move.set_effective_date()
+ move.save()
@classmethod
@ModelView.button
@Workflow.transition('done')
def do(cls, moves):
- pool = Pool()
- Date = pool.get('ir.date')
-
- today = Date.today()
for move in moves:
- if not move.effective_date:
- move.effective_date = today
+ move.set_effective_date()
if (move.from_location.type in ('supplier', 'production')
and move.to_location.type == 'storage'
and move.product.cost_price_method == 'average'):
@@ -660,11 +666,11 @@
cls.raise_user_error('modify_done_cancel',
(move.rec_name,))
+ super(Move, cls).write(moves, vals)
+
if any(f not in cls._allow_modify_closed_period for f in vals):
cls.check_period_closed(moves)
- super(Move, cls).write(moves, vals)
-
for move in moves:
internal_quantity = cls._get_internal_quantity(move.quantity,
move.uom, move.product)
Index: shipment.py
===================================================================
--- ./modules/stock/shipment.py
+++ ./modules/stock/shipment.py
@@ -40,7 +40,9 @@
"Supplier Shipment"
__name__ = 'stock.shipment.in'
_rec_name = 'code'
- effective_date = fields.Date('Effective Date', readonly=True)
+ effective_date = fields.Date('Effective Date', states={
+ 'readonly': Eval('state').in_(['cancel', 'done']),
+ }, depends=['state'])
planned_date = fields.Date('Planned Date', states={
'readonly': Not(Equal(Eval('state'), 'draft')),
}, depends=['state'])
@@ -465,7 +467,7 @@
Move = pool.get('stock.move')
Date = pool.get('ir.date')
Move.do([m for s in shipments for m in s.inventory_moves])
- cls.write(shipments, {
+ cls.write([s for s in shipments if not s.effective_date], {
'effective_date': Date.today(),
})
@@ -474,7 +476,9 @@
"Supplier Return Shipment"
__name__ = 'stock.shipment.in.return'
_rec_name = 'code'
- effective_date = fields.Date('Effective Date', readonly=True)
+ effective_date = fields.Date('Effective Date', states={
+ 'readonly': ~Eval('state').in_(['cancel', 'done']),
+ }, depends=['state'])
planned_date = fields.Date('Planned Date',
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
@@ -718,7 +722,7 @@
Date = pool.get('ir.date')
Move.do([m for s in shipments for m in s.moves])
- cls.write(shipments, {
+ cls.write([s for s in shipments if not s.effective_date], {
'effective_date': Date.today(),
})
@@ -780,7 +784,9 @@
"Customer Shipment"
__name__ = 'stock.shipment.out'
_rec_name = 'code'
- effective_date = fields.Date('Effective Date', readonly=True)
+ effective_date = fields.Date('Effective Date', states={
+ 'readonly': Eval('state').in_(['cancel', 'done']),
+ }, depends=['state'])
planned_date = fields.Date('Planned Date',
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
@@ -1194,7 +1200,7 @@
Date = pool.get('ir.date')
Move.do([m for s in shipments for m in s.outgoing_moves])
- cls.write(shipments, {
+ cls.write([s for s in shipments if not s.effective_date], {
'effective_date': Date.today(),
})
@@ -1312,7 +1318,9 @@
"Customer Return Shipment"
__name__ = 'stock.shipment.out.return'
_rec_name = 'code'
- effective_date = fields.Date('Effective Date', readonly=True)
+ effective_date = fields.Date('Effective Date', states={
+ 'readonly': Eval('state').in_(['cancel', 'done']),
+ }, depends=['state'])
planned_date = fields.Date('Planned Date',
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
@@ -1654,7 +1662,7 @@
Move = pool.get('stock.move')
Date = pool.get('ir.date')
Move.do([m for s in shipments for m in s.inventory_moves])
- cls.write(shipments, {
+ cls.write([s for s in shipments if not s.effective_date], {
'effective_date': Date.today(),
})
@@ -1752,7 +1760,9 @@
"Internal Shipment"
__name__ = 'stock.shipment.internal'
_rec_name = 'code'
- effective_date = fields.Date('Effective Date', readonly=True)
+ effective_date = fields.Date('Effective Date', states={
+ 'readonly': Eval('state').in_(['cancel', 'done']),
+ }, depends=['state'])
planned_date = fields.Date('Planned Date',
states={
'readonly': Not(Equal(Eval('state'), 'draft')),
@@ -1972,7 +1982,7 @@
Move = pool.get('stock.move')
Date = pool.get('ir.date')
Move.do([m for s in shipments for m in s.moves])
- cls.write(shipments, {
+ cls.write([s for s in shipments if not s.effective_date], {
'effective_date': Date.today(),
})
Index: tests/scenario_stock_shipment_out.rst
===================================================================
--- ./modules/stock/tests/scenario_stock_shipment_out.rst
+++ ./modules/stock/tests/scenario_stock_shipment_out.rst
@@ -13,6 +13,7 @@
>>> from decimal import Decimal
>>> from proteus import config, Model, Wizard
>>> today = datetime.date.today()
+ >>> yesterday = today - relativedelta(days=1)
Create database::
@@ -158,6 +159,14 @@
>>> states.sort()
>>> states
[u'assigned', u'draft']
+ >>> effective_dates = [m.effective_date for m in
+ ... shipment_out.inventory_moves]
+ >>> effective_dates == [today, None]
+ True
+ >>> planned_dates = [m.planned_date for m in
+ ... shipment_out.outgoing_moves]
+ >>> planned_dates == [today, today]
+ True
Delete the draft move, assign and pack shipment::
@@ -188,6 +197,14 @@
>>> shipment_out.reload()
>>> set([m.state for m in shipment_out.outgoing_moves])
set([u'done'])
+ >>> planned_dates = [m.planned_date for m in
+ ... shipment_out.outgoing_moves]
+ >>> planned_dates == [today, today]
+ True
+ >>> effective_dates = [m.effective_date for m in
+ ... shipment_out.outgoing_moves]
+ >>> effective_dates == [today, today]
+ True
>>> len(shipment_out.outgoing_moves)
2
>>> len(shipment_out.inventory_moves)
@@ -197,3 +214,56 @@
>>> sum([m.quantity for m in shipment_out.inventory_moves]) == \
... sum([m.quantity for m in shipment_out.outgoing_moves])
True
+
+Create Shipment Out with effective date::
+
+ >>> ShipmentOut = Model.get('stock.shipment.out')
+ >>> shipment_out = ShipmentOut()
+ >>> shipment_out.planned_date = yesterday
+ >>> shipment_out.effective_date = yesterday
+ >>> shipment_out.customer = customer
+ >>> shipment_out.warehouse = warehouse_loc
+ >>> shipment_out.company = company
+ >>> move = StockMove()
+ >>> shipment_out.outgoing_moves.append(move)
+ >>> move.product = product
+ >>> move.uom =unit
+ >>> move.quantity = 1
+ >>> move.from_location = output_loc
+ >>> move.to_location = customer_loc
+ >>> move.company = company
+ >>> move.unit_price = Decimal('1')
+ >>> move.currency = currency
+ >>> shipment_out.save()
+ >>> ShipmentOut.wait([shipment_out.id], config.context)
+
+Make 1 unit of the product available::
+
+ >>> incoming_move = StockMove()
+ >>> incoming_move.product = product
+ >>> incoming_move.uom = unit
+ >>> incoming_move.quantity = 1
+ >>> incoming_move.from_location = supplier_loc
+ >>> incoming_move.to_location = storage_loc
+ >>> incoming_move.planned_date = yesterday
+ >>> incoming_move.effective_date = yesterday
+ >>> incoming_move.company = company
+ >>> incoming_move.unit_price = Decimal('1')
+ >>> incoming_move.currency = currency
+ >>> incoming_move.save()
+ >>> StockMove.do([incoming_move.id], config.context)
+
+Finish the shipment::
+
+ >>> ShipmentOut.assign_try([shipment_out.id], config.context)
+ True
+ >>> ShipmentOut.pack([shipment_out.id], config.context)
+ >>> ShipmentOut.done([shipment_out.id], config.context)
+ >>> shipment_out.reload()
+ >>> shipment_out.state
+ u'done'
+ >>> shipment_out.outgoing_moves[0].effective_date == yesterday
+ True
+ >>> shipment_out.inventory_moves[0].effective_date == yesterday
+ True
+

1
series
View File

@ -10,4 +10,5 @@ add_db_client.diff
issue2661002_20001.diff
issue101_226.diff
issue2731002_20001.diff
issue134_399.diff
issue2961002_20001_30001.diff