<commit_before>##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, api, _
from odoo.exceptions import UserError


class StockPicking(models.Model):
    _inherit = 'stock.picking'

    number_of_packages = fields.Integer(
        string='Number of Packages',
        copy=False,
    )
    book_id = fields.Many2one(
        'stock.book',
        'Voucher Book',
        copy=False,
        ondelete='restrict',
    )
    vouchers = fields.Char(
        compute='_compute_vouchers',
        string='Vouchers (string)'
    )
    voucher_ids = fields.One2many(
        'stock.picking.voucher',
        'picking_id',
        'Vouchers',
        copy=False,
    )
    declared_value = fields.Float(
        digits='Account',
    )
    observations = fields.Text(
    )
    automatic_declare_value = fields.Boolean(
        related='picking_type_id.automatic_declare_value',
    )
    book_required = fields.Boolean(
        related='picking_type_id.book_required',
    )
    voucher_required = fields.Boolean(
        related='picking_type_id.voucher_required',
    )
    next_number = fields.Integer(
        related='book_id.next_number',
    )

    @api.depends('voucher_ids.display_name')
    def _compute_vouchers(self):
        for rec in self:
            rec.vouchers = ', '.join(rec.mapped('voucher_ids.display_name'))

    def get_estimated_number_of_pages(self):
        self.ensure_one()
        res = 1
        lines_per_voucher = self.book_id.lines_per_voucher
        if lines_per_voucher == 0:
            return res

        operations = len(self.move_lines)
        res = int(-(-float(operations) // float(lines_per_voucher)))
        return res

    @api.constrains('picking_type_id')
    @api.onchange('picking_type_id')
    def _get_book(self):
        for rec in self.filtered(lambda x: x.picking_type_id.book_id):
            rec.book_id = rec.picking_type_id.book_id.id

    def do_print_voucher(self):
        '''This function prints the voucher'''
        report = self.env['ir.actions.report'].search(
            [('report_name', '=', 'stock.report_picking')],
            limit=1).report_action(self)
        return report

    def assign_numbers(self, estimated_number_of_pages, book):
        self.ensure_one()
        list_of_vouchers = []
        for page in range(estimated_number_of_pages):
            list_of_vouchers.append({
                'name': book.sequence_id.next_by_id(),
                'book_id': book.id,
                'picking_id': self.id,
            })
        self.env['stock.picking.voucher'].create(list_of_vouchers)
        self.message_post(body=_(
            'Números de remitos asignados: %s') % (self.vouchers))
        self.write({'book_id': book.id})

    def clean_voucher_data(self):
        self.voucher_ids.unlink()
        self.book_id = False<commit_msg>[FIX] stock_voucher: print delivery slip<commit_after>##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from odoo import fields, models, api, _
from odoo.exceptions import UserError


class StockPicking(models.Model):
    _inherit = 'stock.picking'

    number_of_packages = fields.Integer(
        string='Number of Packages',
        copy=False,
    )
    book_id = fields.Many2one(
        'stock.book',
        'Voucher Book',
        copy=False,
        ondelete='restrict',
    )
    vouchers = fields.Char(
        compute='_compute_vouchers',
        string='Vouchers (string)'
    )
    voucher_ids = fields.One2many(
        'stock.picking.voucher',
        'picking_id',
        'Vouchers',
        copy=False,
    )
    declared_value = fields.Float(
        digits='Account',
    )
    observations = fields.Text(
    )
    automatic_declare_value = fields.Boolean(
        related='picking_type_id.automatic_declare_value',
    )
    book_required = fields.Boolean(
        related='picking_type_id.book_required',
    )
    voucher_required = fields.Boolean(
        related='picking_type_id.voucher_required',
    )
    next_number = fields.Integer(
        related='book_id.next_number',
    )

    @api.depends('voucher_ids.display_name')
    def _compute_vouchers(self):
        for rec in self:
            rec.vouchers = ', '.join(rec.mapped('voucher_ids.display_name'))

    def get_estimated_number_of_pages(self):
        self.ensure_one()
        res = 1
        lines_per_voucher = self.book_id.lines_per_voucher
        if lines_per_voucher == 0:
            return res

        operations = len(self.move_lines)
        res = int(-(-float(operations) // float(lines_per_voucher)))
        return res

    @api.constrains('picking_type_id')
    @api.onchange('picking_type_id')
    def _get_book(self):
        for rec in self.filtered(lambda x: x.picking_type_id.book_id):
            rec.book_id = rec.picking_type_id.book_id.id

    def do_print_voucher(self):
        '''This function prints the voucher'''
        report = self.env['ir.actions.report'].search(
            [('report_name', '=', 'stock.report_delivery_document')],
            limit=1).report_action(self)
        return report

    def assign_numbers(self, estimated_number_of_pages, book):
        self.ensure_one()
        list_of_vouchers = []
        for page in range(estimated_number_of_pages):
            list_of_vouchers.append({
                'name': book.sequence_id.next_by_id(),
                'book_id': book.id,
                'picking_id': self.id,
            })
        self.env['stock.picking.voucher'].create(list_of_vouchers)
        self.message_post(body=_(
            'Números de remitos asignados: %s') % (self.vouchers))
        self.write({'book_id': book.id})

    def clean_voucher_data(self):
        self.voucher_ids.unlink()
        self.book_id = False
{'fraction_non_alphanumeric': 0.1569682151589242, 'fraction_numerical': 0.0016299918500407497, 'mean_word_length': 2.6808638272345533, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1543454', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1904, 'n_words': 311}