[9.0][FIX] stock_cycle_count: Fix a bug when combining automatic and manual creation of cycle counts.

This commit is contained in:
lreficent
2017-05-10 16:38:20 +02:00
committed by Lois Rilo
parent 6e7f9c38a6
commit e3b6358cda

View File

@@ -87,16 +87,19 @@ class StockWarehouse(models.Model):
('state', 'in', ['draft'])]
existing_cycle_counts = self.env['stock.cycle.count'].search(
domain)
if existing_cycle_counts and cycle_count_proposed['date'] <\
existing_cycle_counts.date_deadline:
self.env['stock.cycle.count'].create({
'date_deadline': cycle_count_proposed['date'],
'location_id': cycle_count_proposed['location'].id,
'cycle_count_rule_id': cycle_count_proposed[
'rule_type'].id,
'state': 'draft'
})
existing_cycle_counts.state = 'cancelled'
if existing_cycle_counts:
existing_earliest_date = sorted(
existing_cycle_counts.mapped('date_deadline'))[0]
if cycle_count_proposed['date'] < existing_earliest_date:
self.env['stock.cycle.count'].create({
'date_deadline': cycle_count_proposed['date'],
'location_id': cycle_count_proposed['location'].id,
'cycle_count_rule_id': cycle_count_proposed[
'rule_type'].id,
'state': 'draft'
})
# TODO: cancel all or just the closest in time?
existing_cycle_counts.write({'state': 'cancelled'})
delta = datetime.strptime(
cycle_count_proposed['date'],
DEFAULT_SERVER_DATETIME_FORMAT) - datetime.today()