<commit_before># -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from openerp import models, api


class StockQuant(models.Model):
    _inherit = 'stock.quant'

    @api.one
    def merge_stock_quants(self):
        if not self.reservation_id:
            quants = self.search(
                [('id', '!=', self.id),
                 ('product_id', '=', self.product_id.id),
                 ('lot_id', '=', self.lot_id.id),
                 ('package_id', '=', self.package_id.id),
                 ('location_id', '=', self.location_id.id),
                 ('reservation_id', '=', False),
                 ('propagated_from_id', '=', self.propagated_from_id.id)])
            for quant in quants:
                if self._get_latest_move(self) == self._get_latest_move(quant):
                    self.qty += quant.qty
                    self.cost += quant.cost
                    quant.sudo().unlink()

    @api.model
    def quants_unreserve(self, move):
        related_quants = [x for x in move.reserved_quant_ids]
        super(StockQuant, self).quants_unreserve(move)
        for quant in related_quants:
            quant.merge_stock_quants()
<commit_msg>[MOD] error when merging just deleted quants<commit_after># -*- encoding: utf-8 -*-
##############################################################################
# For copyright and license notices, see __openerp__.py file in root directory
##############################################################################

from openerp import models, api


class StockQuant(models.Model):
    _inherit = 'stock.quant'

    @api.multi
    def merge_stock_quants(self):
        pending_quants_ids = self.ids
        for quant2merge in self:
            if (quant2merge.id in pending_quants_ids and
                    not quant2merge.reservation_id):
                quants = self.search(
                    [('id', '!=', quant2merge.id),
                     ('product_id', '=', quant2merge.product_id.id),
                     ('lot_id', '=', quant2merge.lot_id.id),
                     ('package_id', '=', quant2merge.package_id.id),
                     ('location_id', '=', quant2merge.location_id.id),
                     ('reservation_id', '=', False),
                     ('propagated_from_id', '=',
                      quant2merge.propagated_from_id.id)])
                for quant in quants:
                    if (self._get_latest_move(quant2merge) ==
                            self._get_latest_move(quant)):
                        quant2merge.qty += quant.qty
                        quant2merge.cost += quant.cost
                        if quant.id in pending_quants_ids:
                            pending_quants_ids.remove(quant.id)
                        quant.sudo().unlink()

    @api.model
    def quants_unreserve(self, move):
        quants = move.reserved_quant_ids
        super(StockQuant, self).quants_unreserve(move)
        quants.merge_stock_quants()

{'fraction_non_alphanumeric': 0.20466729738252917, 'fraction_numerical': 0.004415011037527594, 'mean_word_length': 2.085603112840467, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7228625', 'n_tokens_mistral': 892, 'n_tokens_neox': 836, 'n_words': 161}