Skip to content

Commit

Permalink
[REF] stock, stock_account: indices for fast move unlink
Browse files Browse the repository at this point in the history
Stock moves records can be unlinked in some cases, for example when
confirming a move containing a kit, the original move is unlinked and
replaced by the moves of the components of the kit.

This commit adds two indices to accelerate the unlink of stock move
records. The fields were the indices are added are foreign key on stock
move, and postgres checks the foreign keys of the rows before deleting
them.

closes odoo#44337

Signed-off-by: Simon Lejeune (sle) <[email protected]>
  • Loading branch information
sle-odoo committed Jan 31, 2020
1 parent 8f28b30 commit e34a176
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion addons/stock/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ def _default_group_id(self):
inventory_id = fields.Many2one('stock.inventory', 'Inventory', check_company=True)
move_line_ids = fields.One2many('stock.move.line', 'move_id')
move_line_nosuggest_ids = fields.One2many('stock.move.line', 'move_id', domain=[('product_qty', '=', 0.0)])
origin_returned_move_id = fields.Many2one('stock.move', 'Origin return move', copy=False, help='Move that created the return move', check_company=True)
origin_returned_move_id = fields.Many2one(
'stock.move', 'Origin return move', copy=False, index=True,
help='Move that created the return move', check_company=True)
returned_move_ids = fields.One2many('stock.move', 'origin_returned_move_id', 'All returned moves', help='Optional: all returned moves created from this move')
reserved_availability = fields.Float(
'Quantity Reserved', compute='_compute_reserved_availability',
Expand Down
2 changes: 1 addition & 1 deletion addons/stock_account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class AccountMove(models.Model):
_inherit = 'account.move'

stock_move_id = fields.Many2one('stock.move', string='Stock Move')
stock_move_id = fields.Many2one('stock.move', string='Stock Move', index=True)
stock_valuation_layer_ids = fields.One2many('stock.valuation.layer', 'account_move_id', string='Stock Valuation Layer')

# -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion addons/stock_account/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class StockValuationLayer(models.Model):
description = fields.Char('Description', readonly=True)
stock_valuation_layer_id = fields.Many2one('stock.valuation.layer', 'Linked To', readonly=True, check_company=True)
stock_valuation_layer_ids = fields.One2many('stock.valuation.layer', 'stock_valuation_layer_id')
stock_move_id = fields.Many2one('stock.move', 'Stock Move', readonly=True, check_company=True)
stock_move_id = fields.Many2one('stock.move', 'Stock Move', readonly=True, check_company=True, index=True)
account_move_id = fields.Many2one('account.move', 'Journal Entry', readonly=True, check_company=True)

def init(self):
Expand Down

0 comments on commit e34a176

Please sign in to comment.