When a backorder was created and the auto_batch was activated for this picking_type, no batch was assigned to the created backorder, even if it matched the auto-batch criterias. Now when a picking is done, we check if backorders were created. If they are eligible for auto-batchs (given their picking_type, etc.), they also get the auto_batch done for them. We can't simply use the previous picking's batch, because if this batch is now done, then introducing a non-done picking into the batch would raise an inconsistency between the pickings' states and raise an error. Removes the old override of backorder confirmation as now batch dissociation is done in the picking's 'action_done()' override. Allows the validation of a batch that has pickings 'waiting for another operation', as they now will get removed from the batch in the process, no longer blocking the batch's validation. Finally, makes that pickings that had no quantities done when validating a batch aren't cancelled when selecting 'No backorder' in the confirmation wizard, but are instead removed from the batch. Task-2971346 X-original-commit: 1720840b7bd9b3e3e90f7cf860f60f1d0746ce63 Part-of: odoo/odoo#102382
24 lines
853 B
Python
24 lines
853 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models
|
|
from odoo.osv import expression
|
|
|
|
|
|
class StockMove(models.Model):
|
|
_inherit = "stock.move"
|
|
|
|
def _search_picking_for_assignation_domain(self):
|
|
domain = super()._search_picking_for_assignation_domain()
|
|
domain = expression.AND([domain, ['|', ('batch_id', '=', False), ('batch_id.is_wave', '=', False)]])
|
|
return domain
|
|
|
|
def _action_cancel(self):
|
|
res = super()._action_cancel()
|
|
|
|
for picking in self.picking_id:
|
|
# Remove the picking from the batch if the whole batch isn't cancelled.
|
|
if picking.state == 'cancel' and picking.batch_id and any(p.state != 'cancel' for p in picking.batch_id.picking_ids):
|
|
picking.batch_id = None
|
|
return res
|