Ensure coherence between planned date of shipments and moves
review121001
This commit is contained in:
1 parent
9b01f404eb
commit
9703a67226
3 files changed
+135
-5
No files matched your search
@@ -1,3 +1,5 @@
|
||||
* Ensure coherence between planned date of shipments and moves
|
||||
|
||||
Version 2.0.0 - 2011-04-27
|
||||
* Bug fixes (see mercurial logs for details)
|
||||
* Add period to reduce data computation
|
||||
|
||||
@@ -61,7 +61,13 @@ class Move(ModelSQL, ModelView):
|
||||
ondelete='CASCADE')
|
||||
shipment_internal = fields.Many2One('stock.shipment.internal',
|
||||
'Internal Shipment', readonly=True, select=1, ondelete='CASCADE')
|
||||
planned_date = fields.Date("Planned Date", states=STATES, depends=DEPENDS,
|
||||
planned_date = fields.Date("Planned Date", states={
|
||||
'readonly': (In(Eval('state'), ['cancel', 'assigned', 'done'])
|
||||
| Eval('shipment_in') | Eval('shipment_out')
|
||||
| Eval('shipment_in_return') | Eval('shipment_out_return')
|
||||
| Eval('shipment_internal'))
|
||||
}, depends=['state', 'shipment_in', 'shipment_out',
|
||||
'shipment_in_return', 'shipment_out_return', 'shipment_internal'],
|
||||
select=2)
|
||||
effective_date = fields.Date("Effective Date", readonly=True, select=2)
|
||||
state = fields.Selection([
|
||||
|
||||
+126
-4
@@ -297,6 +297,31 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView):
|
||||
'state': 'draft',
|
||||
})
|
||||
|
||||
def _get_move_planned_date(self, shipment):
|
||||
'''
|
||||
Return the planned date for incoming moves and inventory_moves
|
||||
'''
|
||||
return shipment.planned_date, shipment.planned_date
|
||||
|
||||
def _set_move_planned_date(self, shipment_ids):
|
||||
'''
|
||||
Set planned date of moves for the shipments
|
||||
'''
|
||||
move_obj = Pool().get('stock.move')
|
||||
if isinstance(shipment_ids, (int, long)):
|
||||
shipment_ids = [shipment_ids]
|
||||
for shipment in self.browse(shipment_ids):
|
||||
dates = self._get_move_planned_date(shipment)
|
||||
incoming_date, inventory_date = dates
|
||||
move_obj.write([x.id for x in shipment.incoming_moves
|
||||
if x.state not in ('assigned', 'done', 'cancel')], {
|
||||
'planned_date': incoming_date,
|
||||
})
|
||||
move_obj.write([x.id for x in shipment.inventory_moves
|
||||
if x.state not in ('assigned', 'done', 'cancel')], {
|
||||
'planned_date': inventory_date,
|
||||
})
|
||||
|
||||
def create(self, values):
|
||||
sequence_obj = Pool().get('ir.sequence')
|
||||
config_obj = Pool().get('stock.configuration')
|
||||
@@ -304,7 +329,14 @@ class ShipmentIn(ModelWorkflow, ModelSQL, ModelView):
|
||||
values = values.copy()
|
||||
config = config_obj.browse(1)
|
||||
values['code'] = sequence_obj.get_id(config.shipment_in_sequence.id)
|
||||
return super(ShipmentIn, self).create(values)
|
||||
shipment_id = super(ShipmentIn, self).create(values)
|
||||
self._set_move_planned_date(shipment_id)
|
||||
return shipment_id
|
||||
|
||||
def write(self, ids, values):
|
||||
result = super(ShipmentIn, self).write(ids, values)
|
||||
self._set_move_planned_date(ids)
|
||||
return result
|
||||
|
||||
def copy(self, ids, default=None):
|
||||
if default is None:
|
||||
@@ -437,6 +469,26 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView):
|
||||
})
|
||||
self._order[0] = ('id', 'DESC')
|
||||
|
||||
def _get_move_planned_date(self, shipment):
|
||||
'''
|
||||
Return the planned date for the moves
|
||||
'''
|
||||
return shipment.planned_date
|
||||
|
||||
def _set_move_planned_date(self, shipment_ids):
|
||||
'''
|
||||
Set planned date of moves for the shipments
|
||||
'''
|
||||
move_obj = Pool().get('stock.move')
|
||||
if isinstance(shipment_ids, (int, long)):
|
||||
shipment_ids = [shipment_ids]
|
||||
for shipment in self.browse(shipment_ids):
|
||||
date = self._get_move_planned_date(shipment)
|
||||
move_obj.write([x.id for x in shipment.moves
|
||||
if x.state not in ('assigned', 'done', 'cancel')], {
|
||||
'planned_date': date,
|
||||
})
|
||||
|
||||
def create(self, values):
|
||||
sequence_obj = Pool().get('ir.sequence')
|
||||
config_obj = Pool().get('stock.configuration')
|
||||
@@ -445,7 +497,14 @@ class ShipmentInReturn(ModelWorkflow, ModelSQL, ModelView):
|
||||
config = config_obj.browse(1)
|
||||
values['code'] = sequence_obj.get_id(
|
||||
config.shipment_in_return_sequence.id)
|
||||
return super(ShipmentInReturn, self).create(values)
|
||||
shipment_id = super(ShipmentInReturn, self).create(values)
|
||||
self._set_move_planned_date(shipment_id)
|
||||
return shipment_id
|
||||
|
||||
def write(self, ids, values):
|
||||
result = super(ShipmentInReturn, self).write(ids, values)
|
||||
self._set_move_planned_date(ids)
|
||||
return result
|
||||
|
||||
def wkf_draft(self, shipment):
|
||||
move_obj = Pool().get('stock.move')
|
||||
@@ -920,6 +979,31 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView):
|
||||
'unit_price': move.unit_price,
|
||||
})
|
||||
|
||||
def _get_move_planned_date(self, shipment):
|
||||
'''
|
||||
Return the planned date for outgoing moves and inventory moves
|
||||
'''
|
||||
return shipment.planned_date, shipment.planned_date
|
||||
|
||||
def _set_move_planned_date(self, shipment_ids):
|
||||
'''
|
||||
Set planned date of moves for the shipments
|
||||
'''
|
||||
move_obj = Pool().get('stock.move')
|
||||
if isinstance(shipment_ids, (int, long)):
|
||||
shipment_ids = [shipment_ids]
|
||||
for shipment in self.browse(shipment_ids):
|
||||
dates = self._get_move_planned_date(shipment)
|
||||
outgoing_date, inventory_date = dates
|
||||
move_obj.write([x.id for x in shipment.outgoing_moves
|
||||
if x.state not in ('assigned', 'done', 'cancel')], {
|
||||
'planned_date': outgoing_date,
|
||||
})
|
||||
move_obj.write([x.id for x in shipment.inventory_moves
|
||||
if x.state not in ('assigned', 'done', 'cancel')], {
|
||||
'planned_date': inventory_date,
|
||||
})
|
||||
|
||||
def create(self, values):
|
||||
sequence_obj = Pool().get('ir.sequence')
|
||||
config_obj = Pool().get('stock.configuration')
|
||||
@@ -927,7 +1011,14 @@ class ShipmentOut(ModelWorkflow, ModelSQL, ModelView):
|
||||
values = values.copy()
|
||||
config = config_obj.browse(1)
|
||||
values['code'] = sequence_obj.get_id(config.shipment_out_sequence.id)
|
||||
return super(ShipmentOut, self).create(values)
|
||||
shipment_id = super(ShipmentOut, self).create(values)
|
||||
self._set_move_planned_date(shipment_id)
|
||||
return shipment_id
|
||||
|
||||
def write(self, ids, values):
|
||||
result = super(ShipmentOut, self).write(ids, values)
|
||||
self._set_move_planned_date(ids)
|
||||
return result
|
||||
|
||||
def copy(self, ids, default=None):
|
||||
if default is None:
|
||||
@@ -1193,6 +1284,30 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView):
|
||||
'moves': value,
|
||||
})
|
||||
|
||||
def _get_move_planned_date(self, shipment):
|
||||
'''
|
||||
Return the planned date for incoming moves and inventory moves
|
||||
'''
|
||||
return shipment.planned_date, shipment.planned_date
|
||||
|
||||
def _set_move_planned_date(self, shipment_ids):
|
||||
'''
|
||||
Set planned date of moves for the shipments
|
||||
'''
|
||||
move_obj = Pool().get('stock.move')
|
||||
if isinstance(shipment_ids, (int, long)):
|
||||
shipment_ids = [shipment_ids]
|
||||
for shipment in self.browse(shipment_ids):
|
||||
dates = self._get_move_planned_date(shipment)
|
||||
incoming_date, inventory_date = dates
|
||||
move_obj.write([x.id for x in shipment.incoming_moves
|
||||
if x.state not in ('assigned', 'done', 'cancel')], {
|
||||
'planned_date': incoming_date,
|
||||
})
|
||||
move_obj.write([x.id for x in shipment.inventory_moves], {
|
||||
'planned_date': inventory_date,
|
||||
})
|
||||
|
||||
def create(self, values):
|
||||
sequence_obj = Pool().get('ir.sequence')
|
||||
config_obj = Pool().get('stock.configuration')
|
||||
@@ -1201,7 +1316,14 @@ class ShipmentOutReturn(ModelWorkflow, ModelSQL, ModelView):
|
||||
config = config_obj.browse(1)
|
||||
values['code'] = sequence_obj.get_id(
|
||||
config.shipment_out_return_sequence.id)
|
||||
return super(ShipmentOutReturn, self).create(values)
|
||||
shipment_id = super(ShipmentOutReturn, self).create(values)
|
||||
self._set_move_planned_date(shipment_id)
|
||||
return shipment_id
|
||||
|
||||
def write(self, ids, values):
|
||||
result = super(ShipmentOutReturn, self).write(ids, values)
|
||||
self._set_move_planned_date(ids)
|
||||
return result
|
||||
|
||||
def copy(self, ids, default=None):
|
||||
if default is None:
|
||||
|
||||
Reference in new issue
Block a user