<commit_before># -*- coding: utf-8 -*-
# © 2016 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api, fields


class SaleOrder(models.Model):

    _inherit = 'sale.order'

    is_all_reserved = fields.Boolean(compute='_compute_is_all_reserved',
                                     search='_search_is_all_reserved')
    is_some_reserved = fields.Boolean(compute='_compute_is_some_reserved',
                                      search='_search_is_some_reserved')

    @api.multi
    def action_ship_create(self):
        res = super(SaleOrder, self).action_ship_create()
        for sale in self:
            sale.picking_ids.write({'commercial': sale.user_id.id})
        return res

    @api.multi
    def _search_is_all_reserved(self, operator, operand):
        self.env.cr.execute(
            """
SELECT B.order_id
FROM
(SELECT distinct order_id
 FROM sale_order_line
    INNER JOIN stock_reservation ON stock_reservation.sale_line_id = sale_order_line.id
    INNER JOIN stock_move ON stock_move.id = stock_reservation.move_id
 WHERE stock_move.state != 'assigned') A
RIGHT JOIN
(SELECT distinct order_id
 FROM sale_order_line
    INNER JOIN stock_reservation ON stock_reservation.sale_line_id = sale_order_line.id
    INNER JOIN stock_move ON stock_move.id = stock_reservation.move_id
 WHERE stock_move.state = 'assigned') B
on A.order_id = B.order_id
WHERE A.order_id IS NULL
            """)
        orders = self.env.cr.fetchall()
        order_ids = [x[0] for x in orders]
        if operator == '=' and operand == True:
            return [('id', 'in', order_ids)]<commit_msg>[IMP] 'stock_custom': Llamada a la funcion de creacion de producto de albaran, esto se realiza en este archivo ya que el stock move tiene un picking asociado cuando llega a este punto.<commit_after># -*- coding: utf-8 -*-
# © 2016 Comunitea
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp import models, api, fields, SUPERUSER_ID
from openerp.addons.connector.event import (on_record_create,
                    on_record_write,
                    on_record_unlink)
from openerp.addons.connector.session import ConnectorSession

class SaleOrder(models.Model):

    _inherit = 'sale.order'

    is_all_reserved = fields.Boolean(compute='_compute_is_all_reserved',
                                     search='_search_is_all_reserved')
    is_some_reserved = fields.Boolean(compute='_compute_is_some_reserved',
                                      search='_search_is_some_reserved')

    @api.multi
    def action_ship_create(self):
        res = super(SaleOrder, self).action_ship_create()
        for sale in self:
            sale.picking_ids.write({'commercial': sale.user_id.id})
            session = ConnectorSession(self.env.cr, SUPERUSER_ID,
                                       context=self.env.context)
            for picking in sale.picking_ids:
                for move in picking.move_lines:
                    on_record_create.fire(session, 'stock.move',
                                          move.id)

        return res

    @api.multi
    def _search_is_all_reserved(self, operator, operand):
        self.env.cr.execute(
            """
SELECT B.order_id
FROM
(SELECT distinct order_id
 FROM sale_order_line
    INNER JOIN stock_reservation ON stock_reservation.sale_line_id = sale_order_line.id
    INNER JOIN stock_move ON stock_move.id = stock_reservation.move_id
 WHERE stock_move.state != 'assigned') A
RIGHT JOIN
(SELECT distinct order_id
 FROM sale_order_line
    INNER JOIN stock_reservation ON stock_reservation.sale_line_id = sale_order_line.id
    INNER JOIN stock_move ON stock_move.id = stock_reservation.move_id
 WHERE stock_move.state = 'assigned') B
on A.order_id = B.order_id
WHERE A.order_id IS NULL
            """)
        orders = self.env.cr.fetchall()
        order_ids = [x[0] for x in orders]
        if operator == '=' and operand == True:
            return [('id', 'in', order_ids)]
{'fraction_non_alphanumeric': 0.09002493765586035, 'fraction_numerical': 0.00399002493765586, 'mean_word_length': 2.673076923076923, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1768083', 'n_tokens_mistral': 1268, 'n_tokens_neox': 1201, 'n_words': 292}