<commit_before># -*- coding: utf-8 -*-
# © 2016 <NAME> - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, api


class StockMove(models.Model):

    _inherit = 'stock.move'

    @api.multi
    def _get_expiry_dates(self, production):
        moves = (production.move_created_ids |
                 production.move_created_ids2.filtered(lambda x:
                                                       x.state != 'cancel'))
        lots = moves.mapped('lot_ids') | moves.mapped('restrict_lot_id')
        removal_date = min([x.removal_date for x in
                            lots.filtered(lambda x: x.removal_date)]) or False
        life_date = min([x.life_date for x in
                         lots.filtered(lambda x: x.life_date)]) or False
        alert_date = min([x.alert_date for x in
                          lots.filtered(lambda x: x.alert_date)]) or False
        use_date = min([x.use_date for x in
                        lots.filtered(lambda x: x.use_date)]) or False
        return removal_date, life_date, alert_date, use_date

    @api.multi
    def action_done(self):
        for move in self.filtered(
                lambda x: x.production_id and x.production_id.production and
                x.restrict_lot_id):
            removal, life, alert, use = self._get_expiry_dates(
                move.production_id.production)
            move.restrict_lot_id.write({
                'removal_date': removal,
                'life_date': life,
                'alert_date': alert,
                'use_date': use
            })
        return super(StockMove, self).action_done()<commit_msg>[FIX] mrp_packaging_expiry: traceback when no dates in component lots<commit_after># -*- coding: utf-8 -*-
# © 2016 <NAME> - AvanzOSC
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import models, api


class StockMove(models.Model):

    _inherit = 'stock.move'

    @api.multi
    def _get_expiry_dates(self, production):
        moves = (production.move_created_ids |
                 production.move_created_ids2.filtered(lambda x:
                                                       x.state != 'cancel'))
        lots = moves.mapped('lot_ids') | moves.mapped('restrict_lot_id')
        removal_lots = lots.filtered(lambda x: x.removal_date)
        removal_date = removal_lots and min(removal_lots.mapped(
            'removal_date')) or False
        life_lots = lots.filtered(lambda x: x.life_date)
        life_date = (life_lots and min(life_lots.mapped('life_date')) or
                     False)
        alert_lots = lots.filtered(lambda x: x.alert_date)
        alert_date = (alert_lots and min(alert_lots.mapped('alert_date')) or
                      False)
        use_lots = lots.filtered(lambda x: x.use_date)
        use_date = use_lots and min(use_lots.mapped('use_date')) or False
        return removal_date, life_date, alert_date, use_date

    @api.multi
    def action_done(self):
        for move in self.filtered(
                lambda x: x.production_id and x.production_id.production and
                x.restrict_lot_id):
            removal, life, alert, use = self._get_expiry_dates(
                move.production_id.production)
            move.restrict_lot_id.write({
                'removal_date': removal,
                'life_date': life,
                'alert_date': alert,
                'use_date': use
            })
        return super(StockMove, self).action_done()
{'fraction_non_alphanumeric': 0.10159362549800798, 'fraction_numerical': 0.005122367672168469, 'mean_word_length': 1.9438860971524288, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1776109', 'n_tokens_mistral': 1087, 'n_tokens_neox': 1044, 'n_words': 228}