# Copyright 2026 Criptomart # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import api from odoo import fields from odoo import models class StockMoveLine(models.Model): _inherit = "stock.move.line" _order = "product_categ_id, product_id, picking_partner_id, id" product_categ_id = fields.Many2one( comodel_name="product.category", string="Product Category (Batch)", related="product_id.categ_id", store=True, readonly=True, ) product_default_code = fields.Char( string="Product Code", related="product_id.default_code", readonly=True, ) picking_partner_id = fields.Many2one( related="picking_id.partner_id", store=True, readonly=True, ) is_collected = fields.Boolean( string="Collected", default=False, copy=False, ) home_delivery = fields.Boolean( related="picking_id.home_delivery", readonly=True, ) consumer_group_id = fields.Many2one( comodel_name="res.partner", compute="_compute_consumer_group_id", readonly=True, ) def write(self, vals): res = super().write(vals) if vals.get("is_collected"): # Collecting a line is the operator saying the goods are in the # basket: its quantity must survive the reservation engine even if # it was never retyped. The demand is left alone, only a quantity # typed by hand adjusts it. lines = self.filtered( lambda line: not line.picked and line.state not in ("done", "cancel") ) if lines: lines.picked = True lines._freeze_manual_quantity(align_demand=False) return res @api.depends("picking_id") def _compute_consumer_group_id(self): for line in self: picking = line.picking_id if picking: line.consumer_group_id = picking.batch_consumer_group_id else: line.consumer_group_id = False