diff --git a/stock_cycle_count/models/stock_cycle_count.py b/stock_cycle_count/models/stock_cycle_count.py index eebd29be0..89220e116 100644 --- a/stock_cycle_count/models/stock_cycle_count.py +++ b/stock_cycle_count/models/stock_cycle_count.py @@ -12,52 +12,60 @@ class StockCycleCount(models.Model): _description = "Stock Cycle Counts" _inherit = 'mail.thread' - @api.multi - def _compute_inventory_adj_count(self): - for rec in self: - rec.inventory_adj_count = len(rec.stock_adjustment_ids) - @api.model - def create(self, vals): - vals['name'] = self.env['ir.sequence'].next_by_code( - 'stock.cycle.count') or '' - return super(StockCycleCount, self).create(vals) - - @api.model - def _company_get(self): + def _default_company(self): company_id = self.env['res.company']._company_default_get(self._name) return company_id name = fields.Char(string='Name', readonly=True) location_id = fields.Many2one( - comodel_name='stock.location', string='Location', required=True, - readonly=True, states={'draft': [('readonly', False)]}) + comodel_name='stock.location', string='Location', + required=True, + readonly=True, states={'draft': [('readonly', False)]}, + ) responsible_id = fields.Many2one( comodel_name='res.users', string='Assigned to', readonly=True, states={'draft': [('readonly', False)]}, - track_visibility='onchange') + track_visibility='onchange', + ) date_deadline = fields.Date( - string='Required Date', readonly=True, - states={'draft': [('readonly', False)]}, track_visibility='onchange') + string='Required Date', + readonly=True, 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)]}, - track_visibility='onchange') + required=True, + readonly=True, states={'draft': [('readonly', False)]}, + track_visibility='onchange', + ) state = fields.Selection(selection=[ ('draft', 'Planned'), ('open', 'Execution'), ('cancelled', 'Cancelled'), ('done', 'Done') - ], string='State', default='draft', track_visibility='onchange') - stock_adjustment_ids = fields.One2many(comodel_name='stock.inventory', - inverse_name='cycle_count_id', - string='Inventory Adjustment', - track_visibility='onchange') + ], string='State', default='draft', track_visibility='onchange', + ) + stock_adjustment_ids = fields.One2many( + comodel_name='stock.inventory', inverse_name='cycle_count_id', + string='Inventory Adjustment', + track_visibility='onchange', + ) inventory_adj_count = fields.Integer( - compute='_compute_inventory_adj_count') + compute='_compute_inventory_adj_count', + ) company_id = fields.Many2one( - comodel_name='res.company', string='Company', required=True, - default=_company_get, readonly=True) + comodel_name='res.company', string='Company', + required=True, + default='_default_company', + readonly=True, + ) + + @api.depends('stock_adjustment_ids') + @api.multi + def _compute_inventory_adj_count(self): + for rec in self: + rec.inventory_adj_count = len(rec.stock_adjustment_ids) @api.multi def do_cancel(self): @@ -73,6 +81,12 @@ class StockCycleCount(models.Model): 'exclude_sublocation': True } + @api.model + def create(self, vals): + vals['name'] = self.env['ir.sequence'].next_by_code( + 'stock.cycle.count') or '' + return super(StockCycleCount, self).create(vals) + @api.multi def action_create_inventory_adjustment(self): if any([s != 'draft' for s in self.mapped('state')]): diff --git a/stock_cycle_count/models/stock_cycle_count_rule.py b/stock_cycle_count/models/stock_cycle_count_rule.py index 4b6879dd1..8ddebf202 100644 --- a/stock_cycle_count/models/stock_cycle_count_rule.py +++ b/stock_cycle_count/models/stock_cycle_count_rule.py @@ -83,7 +83,7 @@ class StockCycleCountRule(models.Model): ) @api.onchange('location_ids') - def _get_warehouses(self): + def _onchange_locaton_ids(self): """Get the warehouses for the selected locations.""" wh_ids = [] for loc in self.location_ids: diff --git a/stock_cycle_count/tests/test_stock_cycle_count.py b/stock_cycle_count/tests/test_stock_cycle_count.py index 2d55fc488..26d08735f 100644 --- a/stock_cycle_count/tests/test_stock_cycle_count.py +++ b/stock_cycle_count/tests/test_stock_cycle_count.py @@ -235,7 +235,7 @@ class TestStockCycleCount(common.TransactionCase): for r in rules: r._compute_rule_description() self.assertTrue(r.rule_description, 'No description provided') - self.rule_accuracy._get_warehouses() + self.rule_accuracy._onchange_locaton_ids() self.assertEqual(self.rule_accuracy.warehouse_ids.ids, self.big_wh.ids, 'Rules defined for zones are not getting the right ' 'warehouse.')