Skip to content

Commit

Permalink
[9.0][IMP] stock_cycle_count: update existing cycle counts instead of…
Browse files Browse the repository at this point in the history
… cancel them.
  • Loading branch information
LoisRForgeFlow committed May 12, 2017
1 parent b032c0a commit eccf763
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
5 changes: 3 additions & 2 deletions stock_cycle_count/models/stock_cycle_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ def _company_get(self):
track_visibility='onchange')
date_deadline = fields.Date(
string='Required Date', readonly=True,
states={'draft': [('readonly', False)]})
states={'draft': [('readonly', False)]}, track_visibility='onchange')
cycle_count_rule_id = fields.Many2one(
comodel_name='stock.cycle.count.rule', string='Cycle count rule',
required=True, readonly=True, states={'draft': [('readonly', False)]})
required=True, readonly=True, states={'draft': [('readonly', False)]},
track_visibility='onchange')
state = fields.Selection(selection=[
('draft', 'Planned'),
('open', 'Execution'),
Expand Down
8 changes: 3 additions & 5 deletions stock_cycle_count/models/stock_warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,13 @@ def action_compute_cycle_count_rules(self):
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({
cc_to_update = existing_cycle_counts.search([
('date_deadline', '=', existing_earliest_date)])
cc_to_update.write({
'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()
Expand Down
13 changes: 7 additions & 6 deletions stock_cycle_count/tests/test_stock_cycle_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ def test_cycle_count_planner(self):
('location_id', 'in', locs.ids)])
self.assertFalse(
counts, 'Existing cycle counts before execute planner.')
date = datetime.today() + timedelta(days=30)
date_pre_existing_cc = datetime.today() + timedelta(days=30)
loc = locs[0]
pre_existing_count = self.cycle_count_model.create({
'name': 'To be cancelled when running cron job.',
'cycle_count_rule_id': self.rule_periodic.id,
'location_id': loc.id,
'date_deadline': date
'date_deadline': date_pre_existing_cc
})
self.assertEqual(pre_existing_count.state, 'draft',
'Testing data not generated properly.')
Expand All @@ -179,9 +179,10 @@ def test_cycle_count_planner(self):
})
move1.action_done()
wh.cron_cycle_count()
self.assertEqual(pre_existing_count.state, 'cancelled',
'Existing cycle counts not cancelled when an earlier '
'cycle count is scheduled.')
self.assertNotEqual(pre_existing_count.date_deadline,
date_pre_existing_cc,
'Date of pre-existing cycle counts has not been '
'updated.')
counts = self.cycle_count_model.search([
('location_id', 'in', locs.ids)])
self.assertTrue(counts, 'Cycle counts not planned')
Expand Down Expand Up @@ -221,7 +222,7 @@ def test_cycle_count_workflow(self):
'Cycle count not set as cancelled.')

def test_view_methods(self):
"""Tests the methods used for handle views."""
"""Tests the methods used to handle views."""
self.cycle_count_1.action_create_inventory_adjustment()
self.cycle_count_1.action_view_inventory()
inv_count = self.cycle_count_1.inventory_adj_count
Expand Down

0 comments on commit eccf763

Please sign in to comment.