mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[9.0][IMP] stock_cycle_count: update existing cycle counts instead of cancel them.
This commit is contained in:
@@ -36,10 +36,11 @@ class StockCycleCount(models.Model):
|
||||
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'),
|
||||
|
||||
@@ -91,15 +91,13 @@ class StockWarehouse(models.Model):
|
||||
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()
|
||||
|
||||
@@ -147,13 +147,13 @@ class TestStockCycleCount(common.TransactionCase):
|
||||
('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.')
|
||||
@@ -179,9 +179,10 @@ class TestStockCycleCount(common.TransactionCase):
|
||||
})
|
||||
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')
|
||||
@@ -221,7 +222,7 @@ class TestStockCycleCount(common.TransactionCase):
|
||||
'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
|
||||
|
||||
Reference in New Issue
Block a user