##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

from odoo import models, fields


class StockMove(models.Model):
    _inherit = 'stock.move'

    request_order_id = fields.Many2one(
        related='stock_request_ids.order_id',
        readonly=True,
    )

    def _split(self, qty, restrict_partner_id=False):
        """ When we are on a move created by a stock_request and we create a
        backorder, we create a new allocation linked to this new move and
        update quantities
        """
        new_move_id = super(StockMove, self)._split(
            qty, restrict_partner_id=restrict_partner_id)

        remaining_to_allocate = qty
        for allocation in self.allocation_ids:
            if not remaining_to_allocate:
                break
            to_allocate = min(
                remaining_to_allocate, allocation.requested_product_uom_qty)
            remaining_to_allocate -= to_allocate

            allocation.copy({
                'stock_move_id': new_move_id,
                'requested_product_uom_qty': to_allocate,
            })
            allocation.requested_product_uom_qty -= to_allocate

        return new_move_id

##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

from odoo import models, fields


class StockMove(models.Model):
    _inherit = 'stock.move'

    request_order_id = fields.Many2one(
        related='stock_request_ids.order_id',
        readonly=True,
    )

    def _split(self, qty, restrict_partner_id=False):
        """ When we are on a move created by a stock_request and we create a
        backorder, we create a new allocation linked to this new move and
        update quantities
        """
        new_move_id = super(StockMove, self)._split(
            qty, restrict_partner_id=restrict_partner_id)

        remaining_to_allocate = qty
        for allocation in self.allocation_ids:
            if not remaining_to_allocate:
                break
            to_allocate = min(
                remaining_to_allocate, allocation.requested_product_uom_qty)
            remaining_to_allocate -= to_allocate

            allocation.copy({
                'stock_move_id': new_move_id,
                'requested_product_uom_qty': to_allocate,
            })
            allocation.requested_product_uom_qty -= to_allocate

        return new_move_id

    # TODO remove in v12 if this part are not implemented
    def copy_data(self, default=None):
        """ Nosotros ya copiamos la allocation en el split de arriba y ademas
        si se copiasen en el copy data, con algunas rutas se esta duplicando
        el allocation en casos donde no debe hacerlo, solo queremos duplicar
        allocation en entregas parciales (con el split)
        """
        if 'allocation_ids' in default:
            default.pop('allocation_ids')
        return super(StockMove, self).copy_data(default)

Fix a problem with the allocations
[FIX] stock_request_ux: Fix a problem with the allocations

For this change https://github.com/OCA/stock-logistics-warehouse/commit/4464be475999c8ada492c56a1c30ca2b0eaa264e

If you confirm with a rute with 3 steps and create 3 pickings them has related with the request by allocation, and the qty_done, qty_In_progress are the sum of all of them moves and the are duplicated the values, that it's wrong behavior

In this Module are introduce the modification in the "Split" method to fix the behavior related when do an backorder or not.
