<commit_before># Copyright 2022 <NAME> - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, fields, models
from odoo.exceptions import ValidationError
from datetime import timedelta, datetime


class StockPicking(models.Model):
    _inherit = "stock.picking"

    def _default_get_custom_date_done(self):
        return fields.Datetime.now()

    expiration_operation = fields.Boolean(
        string="Is Expiration Operation",
        default=False,
        related="picking_type_id.expiration_operation",
        store=True)
    custom_date_done = fields.Datetime(
        default=_default_get_custom_date_done)

    def action_emptying_expired(self):
        expiration_products = self.env["product.product"].search(
            [("use_expiration_date", "=", True)])
        for picking in self:
            if not picking.custom_date_done:
                raise ValidationError(_("You must enter the date done."))
            for product in expiration_products:
                time = product.expiration_time
                date = picking.custom_date_done - timedelta(days=time)
                date_stock = product.with_context(
                    to_date=date,
                    location=picking.location_id.id).qty_available
                out_ml = self.env["stock.move.line"].search([
                    ("product_id", "=", product.id),
                    ("location_id", "=", picking.location_id.id),
                    ("state", "=", "done"),
                    ("date", ">", date),
                    ("date", "<=", picking.custom_date_done)])
                out_qty = sum(out_ml.mapped("qty_done"))
                dif = date_stock - out_qty
                if dif > 0:
                    self.env["stock.move.line"].create(
                        {"product_id": product.id,
                         "location_id": picking.location_id.id,
                         "location_dest_id": picking.location_dest_id.id,
                         "product_uom_id": product.uom_id.id,
                         "qty_done": dif,<commit_msg>[FIX] stock_picking_empyting_expired: use float_compare<commit_after># Copyright 2022 <NAME> - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, fields, models
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare
from datetime import timedelta, datetime


class StockPicking(models.Model):
    _inherit = "stock.picking"

    def _default_get_custom_date_done(self):
        return fields.Datetime.now()

    expiration_operation = fields.Boolean(
        string="Is Expiration Operation",
        default=False,
        related="picking_type_id.expiration_operation",
        store=True)
    custom_date_done = fields.Datetime(
        default=_default_get_custom_date_done)

    def action_emptying_expired(self):
        expiration_products = self.env["product.product"].search(
            [("use_expiration_date", "=", True)])
        for picking in self:
            if not picking.custom_date_done:
                raise ValidationError(_("You must enter the date done."))
            for product in expiration_products:
                time = product.expiration_time
                date = picking.custom_date_done - timedelta(days=time)
                date_stock = product.with_context(
                    to_date=date,
                    location=picking.location_id.id).qty_available
                out_ml = self.env["stock.move.line"].search([
                    ("product_id", "=", product.id),
                    ("location_id", "=", picking.location_id.id),
                    ("state", "=", "done"),
                    ("date", ">", date),
                    ("date", "<=", picking.custom_date_done)])
                out_qty = sum(out_ml.mapped("qty_done"))
                dif = date_stock - out_qty
                if float_compare(
                        dif, 0.0, precision_rounding=product.uom_id.rounding) > 0.0:
                    self.env["stock.move.line"].create(
                        {"product_id": product.id,
                         "location_id": picking.location_id.id,
                         "location_dest_id": picking.location_dest_id.id,
                         "product_uom_id": product.uom_id.id,
                         "qty_done": dif,
{'fraction_non_alphanumeric': 0.10903284671532847, 'fraction_numerical': 0.0038777372262773723, 'mean_word_length': 1.9728813559322034, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6435924', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1207, 'n_words': 223}