addons-cm/stock_picking_batch_custom/models/stock_picking.py
snt ce393b6034 [FIX] TestConfirmEskaera_Integration: limpieza de decoradores @patch y corrección de bugs
- Convertir 4 tests de decorador @patch a context manager 'with patch(...)' para evitar RuntimeError en LocalProxy de Werkzeug
- Corregir patrón env(user=..., context=dict(...)) en Odoo 18 (sin .with_context())
- Agregar website real al mock para integración con helpers de pricing (_get_pricing_info)
- Añadir pickup_date en fixture de existing_order para que _find_recent_draft_order localice correctamente
- BUGFIX: Agregar (5,) a order_line para limpiar líneas previas al actualizar pedido existente

Resultado: 0 failed, 0 errors de 4 tests en Docker para TestConfirmEskaera_Integration

BREAKING: _create_or_update_sale_order ahora limpia las líneas anteriores con (5,) antes de asignar las nuevas cuando se actualiza un pedido existente. Comportamiento previo (duplicación de líneas) era un bug.
2026-04-08 17:26:57 +02:00

57 lines
1.9 KiB
Python

# Copyright 2026 Criptomart
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields
from odoo import models
class StockPicking(models.Model):
_inherit = "stock.picking"
batch_consumer_group_id = fields.Many2one(
comodel_name="res.partner",
compute="_compute_batch_consumer_group_id",
readonly=True,
string="Consumer Group",
)
def _compute_batch_consumer_group_id(self):
for picking in self:
sale = picking.sale_id if "sale_id" in picking._fields else False
if sale and "consumer_group_id" in sale._fields:
picking.batch_consumer_group_id = sale.consumer_group_id
else:
picking.batch_consumer_group_id = False
def _pre_action_done_hook(self):
"""Run collected checks only after Odoo resolves backorders.
This keeps the product summary checkbox informative during the initial
batch validation click, but still enforces it once the user confirms the
actual picking flow that will be processed.
"""
res = super()._pre_action_done_hook()
if res is not True:
return res
self._check_batch_collected_products()
return res
def _check_batch_collected_products(self):
for batch in self.batch_id:
batch_pickings = self.filtered(
lambda picking, batch=batch: picking.batch_id == batch
)
processed_product_ids = (
batch_pickings.move_line_ids.filtered(
lambda line: line.move_id.state not in ("cancel", "done")
and line.product_id
and line.quantity
)
.mapped("product_id")
.ids
)
if not processed_product_ids:
continue
batch._check_all_products_collected(processed_product_ids)