# -*- 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 PurchaseOrderLine(orm.Model):
    """ Model name: PurchaseOrderLine
    """    
    _inherit = 'purchase.order.line'

    # Override onchange for update name
    def onchange_product_id(self, cr, uid, ids, pricelist_id, product_id, qty, 
            uom_id, partner_id, date_order=False, fiscal_position_id=False, 
            date_planned=False, name=False, price_unit=False, state='draft', 
            context=None):
            
        res = super(PurchaseOrderLine, self).onchange_product_id(
            cr, uid, ids, pricelist_id, product_id, qty, 
            uom_id, partner_id, date_order=date_order, 
            fiscal_position_id=fiscal_position_id, date_planned=date_planned, 
            name=name, price_unit=price_unit, state=state, context=context)   
        
        if not product_id:
            return res
        
        product_pool = self.pool.get('product.product')
        product_proxy = product_pool.browse(cr, uid, product_id, context=context)

        supp_name = ''
        for suppinfo in product_proxy.seller_ids:
            if suppinfo.name.id == partner_id:
                supp_name = '\n%s%s' % (
                    '[%s] ' % suppinfo.product_code \
                        if suppinfo.product_code else '',
                    suppinfo.product_name or '',
                    )
                    
        name = '%s%s%s' % (
            '[%s] ' % product_proxy.default_code if \
                product_proxy.default_code else '',
            product_proxy.name or '',
            supp_name,
            )
        if 'value' not in res:
            res['value'] = {}
        res['value']['name'] = name
        return res    
       
            
        


# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

@@ -2923,18 +2923,16 @@
  = '%25s%25s
-%25s
 ' %25 (%0A  
@@ -2933,32 +2933,33 @@
 %25 (%0A            
+#
 '%5B%25s%5D ' %25 produc
@@ -2988,32 +2988,33 @@
 f %5C%0A            
+#
     product_prox
@@ -3244,32 +3244,8 @@
    %0A
-            %0A        %0A%0A%0A
 # vi

remove product code in name