# -*- coding: utf-8 -*-
##############################################################################
#
#    Copyright (C) 2014-15 Agile Business Group sagl
#    (<http://www.agilebg.com>)
#
#    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/>.
#
##############################################################################

from openerp import models, api
from openerp.tools.translate import _
from openerp.exceptions import except_orm


class SaleOrderLine(models.Model):
    _inherit = 'sale.order.line'

    @api.onchange(
        'property_ids', 'product_id', 'product_uom_qty', 'product_uom'
    )
    def property_ids_changed(self):
        prop_dict = {}
        prop_ctx = self.env.context.copy()
        if 'lang' in prop_ctx:
            del prop_ctx['lang']
        for prop in self.env['mrp.property'].with_context(prop_ctx).browse(
            [p.id for p in self.property_ids]
        ):
            if prop.group_id.name in prop_dict:
                raise except_orm(
                    _('Error'),
                    _('Property of group %s already present')
                    % prop.group_id.name)
            prop_dict[prop.group_id.name] = prop.value
        self.price_unit = self.pool.get('product.pricelist').price_get(
            self._cr, self._uid, [self.order_id.pricelist_id.id],
            self.product_id.id, self.product_uom_qty or 1.0,
            self.order_id.partner_id.id, {
                'uom': self.product_uom.id,
                'date': self.order_id.date_order,
                'properties': prop_dict,
            })[self.order_id.pricelist_id.id]

@@ -1239,16 +1239,22 @@
     def 
+price_
 property
@@ -1273,16 +1273,16 @@
 (self):%0A
-
         
@@ -1403,16 +1403,48 @@
 'lang'%5D%0A
+        if self.product_id:%0A    
         
@@ -1511,16 +1511,20 @@
 browse(%0A
+    
         
@@ -1569,19 +1569,27 @@
         
-):%0A
+    ):%0A    
         
@@ -1628,16 +1628,20 @@
 p_dict:%0A
+    
         
@@ -1686,16 +1686,20 @@
         
+    
 _('Error
@@ -1702,16 +1702,20 @@
 rror'),%0A
+    
         
@@ -1768,16 +1768,20 @@
 esent')%0A
+    
         
@@ -1818,32 +1818,36 @@
 me)%0A            
+    
 prop_dict%5Bprop.g
@@ -1873,16 +1873,20 @@
 p.value%0A
+    
         
@@ -1949,16 +1949,20 @@
 ce_get(%0A
+    
         
@@ -2027,24 +2027,28 @@
             
+    
 self.product
@@ -2092,24 +2092,28 @@
             
+    
 self.order_i
@@ -2131,16 +2131,20 @@
 d.id, %7B%0A
+    
         
@@ -2195,16 +2195,20 @@
         
+    
 'date': 
@@ -2241,32 +2241,36 @@
                 
+    
 'properties': pr
@@ -2278,16 +2278,20 @@
 p_dict,%0A
+    
         

Fix onchange method name and add check on product_id