<commit_before># -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#
#    Copyright (C) 2014-2018 Didotech srl (<http://www.didotech.com>).
#
#                       All Rights Reserved
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import orm, fields
from openerp.tools.translate import _


class account_invoice(orm.Model):
    _inherit = 'account.invoice'

    # def _get_sale_order(self, cr, uid, ids, field_name, model_name, context=None):
    #     result = {}
    #     crm_lead_obj = self.pool['crm.lead']
    #     sale_order_obj = self.pool['sale.order']
    #
    #     for crm_lead in crm_lead_obj.browse(cr, uid, ids, context):
    #         partner_id = crm_lead.partner_id.id
    #         contact_id = crm_lead.partner_address_id.id
    #         if contact_id:
    #             result[crm_lead.id] = sale_order_obj.search(cr, uid, [('partner_id', '=', partner_id), ('partner_order_id', '=', contact_id)])
    #         else:
    #             result[crm_lead.id] = sale_order_obj.search(cr, uid, [('partner_id', '=', partner_id)])
    #     return result

    def name_get(self, cr, uid, ids, context=None):
        context = context or self.pool['res.users'].context_get(cr, uid)
        if not ids:
            return []
        if isinstance(ids, (int, long)):
            ids = [ids]

        return [(x['id'], unicode(x.type in ['in_invoice', 'in_refund'] and x.supplier_invoice_number or x.number or x.name)) for x in self.browse(cr, uid, ids, context=context)]

    def _get_stock_picking(self, cr, uid, ids, field_name, model_name, context=None):
        context = context or self.pool['res.users'].context_get(cr, uid)
        result = {}
        stock_picking_obj = self.pool['stock.picking']

        for invoice in self.browse(cr, uid, ids, context):
            origins = {}

            for line in invoice.invoice_line:
                line_origin = line.origin or False
                if line_origin not in origins:
                    origins[line_origin] = invoice.id
            if invoice.origin:
                for invoice_origin in invoice.origin.split(', '):
                    if invoice_origin not in origins:
                        origins[invoice_origin] = invoice.id
            picking_ids = []
            for origin in origins:
                if origin:
                    # OUTxxx:SOyy
                    if len(origin.split(':')) == 2:
                        pickings_name = origin.split(':')[0]
                    else:
                        pickings_name = origin
                    picking_ids += stock_picking_obj.search(cr, uid, [('name', '=', pickings_name)], context=context)
<commit_msg>speedup name_get<commit_after># -*- encoding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#
#    Copyright (C) 2014-2018 Didotech srl (<http://www.didotech.com>).
#
#                       All Rights Reserved
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp.osv import orm, fields
from openerp.tools.translate import _


class account_invoice(orm.Model):
    _inherit = 'account.invoice'

    # def _get_sale_order(self, cr, uid, ids, field_name, model_name, context=None):
    #     result = {}
    #     crm_lead_obj = self.pool['crm.lead']
    #     sale_order_obj = self.pool['sale.order']
    #
    #     for crm_lead in crm_lead_obj.browse(cr, uid, ids, context):
    #         partner_id = crm_lead.partner_id.id
    #         contact_id = crm_lead.partner_address_id.id
    #         if contact_id:
    #             result[crm_lead.id] = sale_order_obj.search(cr, uid, [('partner_id', '=', partner_id), ('partner_order_id', '=', contact_id)])
    #         else:
    #             result[crm_lead.id] = sale_order_obj.search(cr, uid, [('partner_id', '=', partner_id)])
    #     return result

    def name_get(self, cr, uid, ids, context=None):
        context = context or self.pool['res.users'].context_get(cr, uid)
        if not ids:
            return []
        if isinstance(ids, (int, long)):
            ids = [ids]

        return [(x['id'], unicode(x['type'] in ['in_invoice', 'in_refund'] and x['supplier_invoice_number'] or x['number'] or x['name'])) for x in self.read(cr, uid, ids, ['id', 'type', 'number', 'name', 'supplier_invoice_number'], context=context)]

    def _get_stock_picking(self, cr, uid, ids, field_name, model_name, context=None):
        context = context or self.pool['res.users'].context_get(cr, uid)
        result = {}
        stock_picking_obj = self.pool['stock.picking']

        for invoice in self.browse(cr, uid, ids, context):
            origins = {}

            for line in invoice.invoice_line:
                line_origin = line.origin or False
                if line_origin not in origins:
                    origins[line_origin] = invoice.id
            if invoice.origin:
                for invoice_origin in invoice.origin.split(', '):
                    if invoice_origin not in origins:
                        origins[invoice_origin] = invoice.id
            picking_ids = []
            for origin in origins:
                if origin:
                    # OUTxxx:SOyy
                    if len(origin.split(':')) == 2:
                        pickings_name = origin.split(':')[0]
                    else:
                        pickings_name = origin
                    picking_ids += stock_picking_obj.search(cr, uid, [('name', '=', pickings_name)], context=context)

{'fraction_non_alphanumeric': 0.1512521343198634, 'fraction_numerical': 0.003414911781445646, 'mean_word_length': 2.4005805515239476, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '5005821', 'n_tokens_mistral': 2111, 'n_tokens_neox': 1991, 'n_words': 572}