<commit_before># Copyright 2012-2014 <NAME>, Camptocamp SA
# Copyright 2018 Tecnativa - <NAME>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models

from odoo.exceptions import UserError


class StockBatchPicking(models.Model):
    """ This object allow to manage multiple stock.picking at the same time.
    """
    _name = 'stock.batch.picking'

    name = fields.Char(
        'Name',
        required=True, index=True,
        copy=False, unique=True,
        states={'draft': [('readonly', False)]},
        default=lambda self: self.env['ir.sequence'].next_by_code(
            'stock.batch.picking'
        ),
    )

    state = fields.Selection([
        ('draft', 'Draft'),
        ('assigned', 'Available'),
        ('done', 'Done'),
        ('cancel', 'Cancelled')],
        string='State',
        readonly=True, index=True, copy=False,
        default='draft',
        help='the state of the batch picking. '
        'Workflow is draft -> assigned -> done or cancel'
    )

    date = fields.Date(
        'Date',
        required=True, readonly=True, index=True,
        states={
            'draft': [('readonly', False)],
            'assigned': [('readonly', False)]
        },
        default=fields.Date.context_today,
        help='date on which the batch picking is to be processed'
    )

    picker_id = fields.Many2one(
        'res.users', 'Picker',
        readonly=True, index=True,
        states={
            'draft': [('readonly', False)],
            'assigned': [('readonly', False)]
        },
        help='the user to which the pickings are assigned'
    )

    picking_ids = fields.One2many(
        'stock.picking', 'batch_picking_id', 'Pickings',
        readonly=True,
        states={'draft': [('readonly', False)]},
        help='List of picking managed by this batch.'
    )

    active_picking_ids = fields.One2many(
        'stock.picking', 'batch_picking_id', 'Pickings',
        readonly=True,
        domain=[('state', 'not in', ('cancel', 'done'))],
    )

    notes = fields.Text('Notes', help='free form remarks')

    move_lines = fields.One2many(
        'stock.move',
        readonly=True,
        string='Related stock moves',
        compute='_compute_move_lines'
    )

    move_line_ids = fields.One2many(
        'stock.move.line',
        readonly=True,
        string='Related pack operations',
        compute='_compute_move_line_ids'
    )

    entire_package_ids = fields.One2many(
        comodel_name='stock.quant.package',
        compute='_compute_entire_package_ids',
        help='Those are the entire packages of a picking shown in the view of '
             'operations',
    )

    entire_package_detail_ids = fields.One2many(
        comodel_name='stock.quant.package',
        compute='_compute_entire_package_ids',
        help='Those are the entire packages of a picking shown in the view of '
             'detailed operations',
    )

    @api.depends('picking_ids')
    def _compute_move_lines(self):
        for batch in self:
            batch.move_lines = batch.picking_ids.mapped("move_lines")

    @api.depends('picking_ids')
    def _compute_move_line_ids(self):
        for batch in self:
            batch.move_line_ids = batch.picking_ids.mapped(
                'move_line_ids'
            )

    @api.depends('picking_ids')
    def _compute_entire_package_ids(self):
        for batch in self:
            batch.update({
                'entire_package_ids': batch.picking_ids.mapped(
                    'entire_package_ids'),
                'entire_package_detail_ids': batch.picking_ids.mapped(
                    'entire_package_detail_ids'),<commit_msg>[IMP] stock_batch_picking: Make move_line_ids writable + computed m2m<commit_after># Copyright 2012-2014 <NAME>, Camptocamp SA
# Copyright 2018 Tecnativa - <NAME>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import _, api, fields, models

from odoo.exceptions import UserError


class StockBatchPicking(models.Model):
    """ This object allow to manage multiple stock.picking at the same time.
    """
    _name = 'stock.batch.picking'

    name = fields.Char(
        'Name',
        required=True, index=True,
        copy=False, unique=True,
        states={'draft': [('readonly', False)]},
        default=lambda self: self.env['ir.sequence'].next_by_code(
            'stock.batch.picking'
        ),
    )

    state = fields.Selection([
        ('draft', 'Draft'),
        ('assigned', 'Available'),
        ('done', 'Done'),
        ('cancel', 'Cancelled')],
        string='State',
        readonly=True, index=True, copy=False,
        default='draft',
        help='the state of the batch picking. '
        'Workflow is draft -> assigned -> done or cancel'
    )

    date = fields.Date(
        'Date',
        required=True, readonly=True, index=True,
        states={
            'draft': [('readonly', False)],
            'assigned': [('readonly', False)]
        },
        default=fields.Date.context_today,
        help='date on which the batch picking is to be processed'
    )

    picker_id = fields.Many2one(
        'res.users', 'Picker',
        readonly=True, index=True,
        states={
            'draft': [('readonly', False)],
            'assigned': [('readonly', False)]
        },
        help='the user to which the pickings are assigned'
    )

    picking_ids = fields.One2many(
        'stock.picking', 'batch_picking_id', 'Pickings',
        readonly=True,
        states={'draft': [('readonly', False)]},
        help='List of picking managed by this batch.'
    )

    active_picking_ids = fields.One2many(
        'stock.picking', 'batch_picking_id', 'Pickings',
        readonly=True,
        domain=[('state', 'not in', ('cancel', 'done'))],
    )

    notes = fields.Text('Notes', help='free form remarks')

    move_lines = fields.Many2many(
        'stock.move',
        readonly=True,
        string='Related stock moves',
        compute='_compute_move_lines'
    )

    move_line_ids = fields.Many2many(
        'stock.move.line',
        string='Related pack operations',
        compute='_compute_move_line_ids',
        # HACK: Allow to write sml fields from this model
        inverse=lambda self: self,
    )

    entire_package_ids = fields.Many2many(
        comodel_name='stock.quant.package',
        compute='_compute_entire_package_ids',
        help='Those are the entire packages of a picking shown in the view of '
             'operations',
    )

    entire_package_detail_ids = fields.Many2many(
        comodel_name='stock.quant.package',
        compute='_compute_entire_package_ids',
        help='Those are the entire packages of a picking shown in the view of '
             'detailed operations',
    )

    @api.depends('picking_ids')
    def _compute_move_lines(self):
        for batch in self:
            batch.move_lines = batch.picking_ids.mapped("move_lines")

    @api.depends('picking_ids')
    def _compute_move_line_ids(self):
        for batch in self:
            batch.move_line_ids = batch.picking_ids.mapped(
                'move_line_ids'
            )

    @api.depends('picking_ids')
    def _compute_entire_package_ids(self):
        for batch in self:
            batch.update({
                'entire_package_ids': batch.picking_ids.mapped(
                    'entire_package_ids'),
                'entire_package_detail_ids': batch.picking_ids.mapped(
                    'entire_package_detail_ids'),
{'fraction_non_alphanumeric': 0.12415439713489852, 'fraction_numerical': 0.005703674227351107, 'mean_word_length': 2.3690795352993743, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3011984', 'n_tokens_mistral': 2309, 'n_tokens_neox': 2225, 'n_words': 506}