<commit_before># -*- coding: utf-8 -*-
###############################################################################
#
#    Copyright (C) 2001-2014 Micronaet SRL (<http://www.micronaet.it>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
import os
import sys
import logging
import openerp
import openerp.netsvc as netsvc
import openerp.addons.decimal_precision as dp
from openerp.osv import fields, osv, expression, orm
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID, api
from openerp import tools
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, 
    DEFAULT_SERVER_DATETIME_FORMAT, 
    DATETIME_FORMATS_MAP, 
    float_compare)


_logger = logging.getLogger(__name__)

class SaleOrderLine(orm.Model):
    """ Model name: SaleOrderLine
    """
    
    _inherit = 'sale.order.line'
    
    def force_all_mrp_id(self, cr, uid, ids, context=None):
        ''' Update
        '''
        sol_ids = self.search(cr, uid, [
            ('family_id', '=', False)], context=context)
        for line in self.browse(cr, uid, sol_ids, context=context):
            self.write(cr, uid, line.id, {
                'is_manufactured': line.product_id.internal_manufacture,
                'family_id': line.product_id.family_id.id or False,
                }, context=context)                
        return True
        
    def _get_date_order_from_order(self, cr, uid, ids, context=None):
        ''' When change sol line order
        '''
        sale_pool = self.pool['sale.order']
        res = []
        for sale in sale_pool.browse(cr, uid, ids, context=context):
            for line in sale.order_line:
                res.append(line.id)
        return res

    def _get_date_order_from_sol(self, cr, uid, ids, context=None):
        ''' When change sol line order
        '''
        return ids

    def _get_default_code_from_sol(self, cr, uid, ids, context=None):
        ''' When change sol line order
        '''
        return ids

    _columns = {
        'default_code': fields.related(
            'product_id', 'default_code', type='char',
            store={
                'sale.order.line': (
                    _get_default_code_from_sol, ['product_id'], 10),
                }, string='Default code', 
            ),

        'destination_partner_id': fields.related(
            'order_id', 'destination_partner_id', 
            type='many2one', string='Destination', relation='res.partner',
            store=False),

        'order_date': fields.related(
            'order_id', 'date_order', type='date',
            store={
                'sale.order.line': (_get_date_order_from_sol, ['order_id'], 10),
                'sale.order': (_get_date_order_from_order, [
                    'date_order'], 10),
                }, string='Order date',            
            )
        }
    
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:<commit_msg>add default code change when change product<commit_after># -*- coding: utf-8 -*-
###############################################################################
#
#    Copyright (C) 2001-2014 Micronaet SRL (<http://www.micronaet.it>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
import os
import sys
import logging
import openerp
import openerp.netsvc as netsvc
import openerp.addons.decimal_precision as dp
from openerp.osv import fields, osv, expression, orm
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID, api
from openerp import tools
from openerp.tools.translate import _
from openerp.tools.float_utils import float_round as round
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, 
    DEFAULT_SERVER_DATETIME_FORMAT, 
    DATETIME_FORMATS_MAP, 
    float_compare)


_logger = logging.getLogger(__name__)

class SaleOrderLine(orm.Model):
    """ Model name: SaleOrderLine
    """
    
    _inherit = 'sale.order.line'
    
    def force_all_mrp_id(self, cr, uid, ids, context=None):
        ''' Update
        '''
        sol_ids = self.search(cr, uid, [
            ('family_id', '=', False)], context=context)
        for line in self.browse(cr, uid, sol_ids, context=context):
            self.write(cr, uid, line.id, {
                'is_manufactured': line.product_id.internal_manufacture,
                'family_id': line.product_id.family_id.id or False,
                }, context=context)                
        return True
        
    def _get_date_order_from_order(self, cr, uid, ids, context=None):
        ''' When change sol line order
        '''
        sale_pool = self.pool['sale.order']
        res = []
        for sale in sale_pool.browse(cr, uid, ids, context=context):
            for line in sale.order_line:
                res.append(line.id)
        return res

    def _get_date_order_from_sol(self, cr, uid, ids, context=None):
        ''' When change sol line order
        '''
        return ids

    def _get_default_code_from_sol(self, cr, uid, ids, context=None):
        ''' When change sol line order
        '''
        return ids

    def _get_default_code_from_product(self, cr, uid, ids, context=None):
        ''' Change defauld code in product
        '''
        sol_pool = self.pool.get('sale.order.line')
        return sol_pool.search(cr, uid, [
            ('product_id', 'in', ids),
            ], context=context)
        
    _columns = {
        'default_code': fields.related(
            'product_id', 'default_code', type='char',
            store={
                'sale.order.line': (
                    _get_default_code_from_sol, ['product_id'], 10),
                }, string='Default code', 
                'product.product': (
                    _get_default_code_from_product, ['default_code'], 10),
                }, string='Default code', 
            ),

        'destination_partner_id': fields.related(
            'order_id', 'destination_partner_id', 
            type='many2one', string='Destination', relation='res.partner',
            store=False),

        'order_date': fields.related(
            'order_id', 'date_order', type='date',
            store={
                'sale.order.line': (_get_date_order_from_sol, ['order_id'], 10),
                'sale.order': (_get_date_order_from_order, [
                    'date_order'], 10),
                }, string='Order date',            
            )
        }
    
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
{'fraction_non_alphanumeric': 0.13705080545229245, 'fraction_numerical': 0.0052044609665427505, 'mean_word_length': 2.5523767605633805, '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': '3802098', 'n_tokens_mistral': 2364, 'n_tokens_neox': 2228, 'n_words': 633}