← Back to team overview

avanzosc team mailing list archive

Re: [Merge] lp:~dani-ds/avanzosc/dos_sale_group into lp:~avanzosc-security-team/avanzosc/72horas

 

Review: Needs Fixing code review

Varias mejoras que han salido en una segunda revisión, y un comentario sobre lo del campo sale_group_id.

Un saludo.

Diff comments:

> === modified file 'dos_sale_group/__init__.py'
> --- dos_sale_group/__init__.py	2014-06-11 10:23:47 +0000
> +++ dos_sale_group/__init__.py	2014-07-01 10:59:54 +0000
> @@ -19,7 +19,7 @@
>  #
>  ##############################################################################
>  
> -import sale_group
> -import sale_order_line
> +from . import models
> +from . import wizard
>  
>  # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === modified file 'dos_sale_group/__openerp__.py'
> --- dos_sale_group/__openerp__.py	2014-06-11 10:23:47 +0000
> +++ dos_sale_group/__openerp__.py	2014-07-01 10:59:54 +0000
> @@ -21,21 +21,18 @@
>  
>  
>  {
> -    "name" : "DOS Sale Group",
> -    "version" : "1.0",
> -    "author" : "DOS",
> -    "category" : "Production, Sale",
> -    "website" : "www.dos-sl.es",
> -    "description": "This module allows you to create groups which include product sales.",
> -    "depends" : ["sale", "sale_layout", "product"],
> -    "init_xml" : [],
> -    "update_xml" : [
> -		'security/ir.model.access.csv',
> -		'sale_group_view.xml',
> -		'sale_order_line_view.xml',
> -	],
> +    "name": "DOS Sale Group",
> +    "version": "1.0",
> +    "author": "DOS",
> +    "category": "Production, Sale",
> +    "website": "www.dos-sl.es",
> +    "description": "This module allows you to create groups which include "
> +    "product sales.",
> +    "depends": ["sale", "product"],
> +    "data": ['security/ir.model.access.csv',
> +             'views/sale_group_view.xml',
> +             'views/sale_order_line_view.xml',
> +             ],
>      "active": False,
>      "installable": True
>  }
> -
> -
> 
> === added directory 'dos_sale_group/models'
> === renamed file 'dos_sale_group/sale_group.py' => 'dos_sale_group/models/sale_group.py'
> --- dos_sale_group/sale_group.py	2014-06-11 10:23:47 +0000
> +++ dos_sale_group/models/sale_group.py	2014-07-01 10:59:54 +0000
> @@ -19,114 +19,118 @@
>  #
>  ##############################################################################
>  
> -from osv import osv
> -from osv import fields
> -from tools.translate import _
> -import time
> -
> -class sale_group(osv.osv):
> -
> -	_name = 'sale.group'
> -	_description = "Sale Group"
> -
> -	_columns = {	
> -		'name': fields.char('Group Name', size=250, required=True),
> -		'type' : fields.selection([('sim', 'SIM'), ('enlace', 'Enlace'), ('pack', 'Pack')], 'Type', required=True),
> -		'partner_sales': fields.boolean('Partner Sales', help="If checked the calculations of sales are made on the active client."),
> -		'sale_group_line_ids': fields.one2many('sale.group.line', 'sale_group_id', 'Sale Group Lines'),
> -	}
> -	
> -	def create(self, cr, uid, vals, context=None):
> -			
> -		sale_group_id = super(sale_group, self).create(cr, uid, vals, context=context)
> -		
> -		if sale_group_id:
> -			sale_group_obj = self.browse(cr, uid, sale_group_id, context)
> -			total = 0
> -			if sale_group_obj.sale_group_line_ids:
> -				""" Comprobamos que el porcentage total de las líneas sea 100 """
> -				for sale_group_line_obj in sale_group_obj.sale_group_line_ids:
> -					total += sale_group_line_obj.percentage
> -			"""
> -			if total != 100:
> -				raise osv.except_osv(_('Error'),
> -				_('It is necessary that the sum total of the percentages of sales of products is exactly 100.'))
> -			"""
> -			
> -		return sale_group_id
> -		
> -	def write(self, cr, uid, ids, vals, context=None):
> -		
> -		result =  super(sale_group, self).write(cr, uid, ids, vals, context = context)	
> -	
> -		for ident in ids:
> -			
> -			sale_group_obj = self.browse(cr, uid, ident, context)
> -			total = 0
> -			
> -			if sale_group_obj.sale_group_line_ids:
> -				""" Comprobamos que el porcentage total de las líneas sea 100 """
> -				for sale_group_line_obj in sale_group_obj.sale_group_line_ids:
> -					total += sale_group_line_obj.percentage
> -			
> -			"""
> -			if total != 100:
> -				raise osv.except_osv(_('Error'),
> -				_('It is necessary that the sum total of the percentages of sales of products is exactly 100.'))
> -
> -			"""
> -		return result
> -
> -sale_group()
> -
> -class sale_group_line(osv.osv):
> -
> -	_name = 'sale.group.line'
> -	_description = "Sale Group Line"
> -
> -	_columns = {	
> -		'sale_group_id': fields.many2one('sale.group', 'Sale Group', ondelete='cascade'),
> -		'product_id': fields.many2one('product.product', 'Product', required=True, ondelete='cascade'),
> -		'percentage': fields.integer('Percentage', required=True),
> -	}
> -	
> -	_order = 'percentage desc'
> -	
> -	def create(self, cr, uid, vals, context=None):
> -			
> -		sale_group_line_id = super(sale_group_line, self).create(cr, uid, vals, context=context)
> -		
> -		if sale_group_line_id:
> -			sale_group_line_obj = self.browse(cr, uid, sale_group_line_id, context)
> -
> -			if sale_group_line_obj.percentage:
> -				if sale_group_line_obj.percentage <= 0 or sale_group_line_obj.percentage > 100:
> -					""" Comprobamos que el porcentage de la lineas esté entre 0 y 100 """
> -					raise osv.except_osv(_('Error'),
> -					_('It is necessary the sales percentage of lines is between 0 and 100.'))
> -			else:
> -				raise osv.except_osv(_('Error'),
> -				_('The percentage of sales can not be 0.'))
> -				
> -		return sale_group_line_id
> -		
> -	def write(self, cr, uid, ids, vals, context=None):
> -		
> -		result =  super(sale_group_line, self).write(cr, uid, ids, vals, context = context)	
> -		
> -		for ident in ids:
> -			
> -			sale_group_line_obj = self.browse(cr, uid, ident, context)
> -
> -			if sale_group_line_obj.percentage:
> -				if sale_group_line_obj.percentage <= 0 or sale_group_line_obj.percentage > 100:
> -					""" Comprobamos que el porcentage de la lineas esté entre 0 y 100 """
> -					raise osv.except_osv(_('Error'),
> -					_('It is necessary the sales percentage of lines is between 0 and 100.'))
> -			else:
> -				raise osv.except_osv(_('Error'),
> -				_('The percentage of sales can not be 0.'))
> -	
> -		return result
> -	
> -sale_group_line()
> \ No newline at end of file
> +from openerp.orm import fields, orm
> +from openerp.tools.translate import _
> +
> +
> +class SaleGroup(orm.Model):
> +
> +    _name = 'sale.group'
> +    _description = "Sale Group"
> +
> +    _columns = {
> +        'name': fields.char('Group Name', size=250, required=True),
> +        'type': fields.selection([('sim', 'SIM'), ('enlace', 'Enlace'),
> +                                  ('pack', 'Pack')], 'Type', required=True),
> +        'partner_sales': fields.boolean('Partner Sales',
> +                                        help="If checked the calculations of "
> +                                        "sales are made on the active"
> +                                        " client."),
> +        'sale_group_line_ids': fields.one2many('sale.group.line',
> +                                               'sale_group_id',
> +                                               'Sale Group Lines'),
> +    }
> +
> +    def create(self, cr, uid, vals, context=None):

Estoy viendo que las comprobaciones del create y el write se pueden hacer a nivel de constraints, y así te evitas tener que hacerlas dos veces y de forma "tan fea". Cámbialo por favor entonces a un constraint. Tendrás que también cambiar las traducciones para que hagan referencia al constraint, no al código.

> +        sale_group_id = super(SaleGroup, self).create(cr, uid, vals,
> +                                                      context=context)
> +        if sale_group_id:
> +            sale_group_obj = self.browse(cr, uid, sale_group_id, context)
> +            total = 0
> +            if sale_group_obj.sale_group_line_ids:
> +                """ Comprobamos que el porcentaje total de las líneas"
> +                " sea 100 """
> +                for sale_group_line_obj in sale_group_obj.sale_group_line_ids:
> +                    total += sale_group_line_obj.percentage
> +                    """ if total != 100:
> +                    raise orm.except_orm(_('Error'),
> +                    _('It is necessary that the sum total of the percentages
> +                     of sales of products is exactly 100.'))
> +                    """
> +        return sale_group_id
> +
> +    def write(self, cr, uid, ids, vals, context=None):
> +        result = super(SaleGroup, self).write(cr, uid, ids, vals,
> +                                              context=context)
> +        for ident in ids:
> +            sale_group_obj = self.browse(cr, uid, ident, context)
> +            total = 0
> +            if sale_group_obj.sale_group_line_ids:
> +                """ Comprobamos que el porcentaje total de las líneas
> +                sea 100 """
> +                for sale_group_line_obj in sale_group_obj.sale_group_line_ids:
> +                    total += sale_group_line_obj.percentage
> +            """
> +            if total != 100:
> +                raise orm.except_orm(_('Error'),
> +                _('It is necessary that the sum total of the percentages of
> +                sales of products is exactly 100.'))
> +            """
> +        return result
> +
> +
> +class SaleGroupLine(orm.Model):
> +
> +    _name = 'sale.group.line'
> +    _description = "Sale Group Line"
> +
> +    _columns = {
> +        'sale_group_id': fields.many2one('sale.group', 'Sale Group',
> +                                         ondelete='cascade'),
> +        'product_id': fields.many2one('product.product', 'Product',
> +                                      required=True, ondelete='cascade'),
> +        'percentage': fields.integer('Percentage', required=True),
> +    }
> +
> +    _order = 'percentage desc'
> +
> +    def create(self, cr, uid, vals, context=None):
> +        sale_group_line_id = super(SaleGroupLine, self).create(cr, uid, vals,
> +                                                               context=context)
> +        if sale_group_line_id:

Ídem

> +            sale_group_line_obj = self.browse(cr, uid, sale_group_line_id,
> +                                              context)
> +            if sale_group_line_obj.percentage:
> +                if (sale_group_line_obj.percentage <= 0 or
> +                        sale_group_line_obj.percentage > 100):
> +                    """ Comprobamos que el porcentaje de la lineas esté entre
> +                    0 y 100 """
> +                    raise orm.except_orm(_('Error'),
> +                                         _('It is necessary the sales '
> +                                           'percentage of lines is between 0'
> +                                           ' and 100.'))
> +            else:
> +                raise orm.except_orm(_('Error'),
> +                                     _('The percentage of sales can not'
> +                                       ' be 0.'))
> +        return sale_group_line_id
> +
> +    def write(self, cr, uid, ids, vals, context=None):
> +        result = super(SaleGroupLine, self).write(cr, uid, ids, vals,
> +                                                  context=context)
> +        for ident in ids:
> +            sale_group_line_obj = self.browse(cr, uid, ident, context)
> +            if sale_group_line_obj.percentage:
> +                if (sale_group_line_obj.percentage <= 0 or
> +                        sale_group_line_obj.percentage > 100):
> +                    """ Comprobamos que el porcentaje de la lineas esté
> +                    entre 0 y 100 """
> +                    raise orm.except_orm(_('Error'),
> +                                         _('It is necessary the sales '
> +                                           'percentage of lines is between 0 '
> +                                           'and 100.'))
> +            else:
> +                raise orm.except_orm(_('Error'),
> +                                     _('The percentage of sales can not '
> +                                       'be 0.'))
> +        return result
> 
> === renamed file 'dos_sale_group/sale_order_line.py' => 'dos_sale_group/models/sale_order_line.py'
> --- dos_sale_group/sale_order_line.py	2014-06-11 10:23:47 +0000
> +++ dos_sale_group/models/sale_order_line.py	2014-07-01 10:59:54 +0000
> @@ -19,196 +19,197 @@
>  #
>  ##############################################################################
>  
> -from osv import osv
> -from osv import fields
> -from tools.translate import _
> -import time
> +from openerp.orm import orm, fields
> +from openerp.tools.translate import _
>  from datetime import datetime
> -from dateutil.relativedelta import relativedelta
> -
> -class sale_order_line(osv.osv): 
> -
> -    _name = 'sale.order.line'
> +
> +
> +class SaleOrderLine(orm.Model):
>      _inherit = 'sale.order.line'
> -    
> +
>      _columns = {
> -        'sale_group_type': fields.selection([('sim', 'SIM'), ('enlace', 'Enlace'), ('pack', 'Pack')], 'Sale Type', change_default=True, help="When you select a type of sales will recommend the necessary product sales according to the group defined in the customer contract."),
> -        'sale_group_id': fields.many2one('sale.group', 'Sale Group', change_default=True, help="When you select a sales group will recommend the product necessary to fulfill the rules of sale."),
> +        'sale_group_type': fields.selection(
> +            [('sim', 'SIM'), ('enlace', 'Enlace'), ('pack', 'Pack')],
> +            'Sale Type', change_default=True, help="When you select a type of "
> +            "sales will recommend the necessary product sales according to the"
> +            " group defined in the customer contract."),
> +        'sale_group_id': fields.many2one('sale.group', 'Sale Group',
> +                                         change_default=True,
> +                                         help="When you select a sales group "
> +                                         "will recommend the product necessary"
> +                                         "to fulfill the rules of sale."),
>      }
> -    
> -    def get_suggested_sale_product(self, cr, uid, sale_group_id, partner_id, date_order, product_ids=[]):
> -        
> +
> +    def get_suggested_sale_product(self, cr, uid, sale_group_id,
> +                                   partner_id, date_order, product_ids=[],
> +                                   context=None):
>          product_id = None
> -        
>          if sale_group_id:
>              sale_group_obj = self.pool.get('sale.group')
> -            sale_group = sale_group_obj.browse(cr, uid, sale_group_id, context=None)
> -            
> +            sale_group = sale_group_obj.browse(cr, uid, sale_group_id,
> +                                               context=None)
>              date_order_obj = datetime.strptime(date_order, "%Y-%m-%d")
>              date_start = date_order_obj.strftime('%Y-%m-01')
>              date_end = date_order_obj.strftime('%Y-%m-%d')
> -            
> -            sql = "     SELECT COALESCE(SUM(sl.product_uom_qty), 0) AS total "
> -            sql += "    FROM sale_order_line sl "
> -            sql += "    INNER JOIN sale_order s ON sl.order_id=s.id "
> -            sql += "    INNER JOIN sale_group_line gl ON sl.product_id=gl.product_id "
> -            sql += "    INNER JOIN sale_group g ON gl.sale_group_id=g.id "
> -            sql += "    WHERE g.id=" + str(sale_group_id) + " AND s.date_order >= '" + date_start + "' AND s.date_order <= '" + date_end + "' "
> -            sql += "    UNION "
> -            sql += "    SELECT COALESCE(SUM(sl.product_uom_qty), 0) AS total "
> -            sql += "    FROM (SELECT DISTINCT order_id, pack_product_id, pack_prodlot_id, product_uom_qty "
> -            sql += "          FROM sale_order_line "
> -            sql += "          WHERE NOT pack_product_id IS NULL) sl" 
> -            sql += "    INNER JOIN sale_order s ON sl.order_id=s.id "
> -            sql += "    INNER JOIN sale_group_line gl ON sl.pack_product_id=gl.product_id "
> -            sql += "    INNER JOIN sale_group g ON gl.sale_group_id=g.id "
> -            sql += "    WHERE g.id=" + str(sale_group_id) + " AND s.date_order >= '" + date_start + "' AND s.date_order <= '" + date_end + "' "
> -            sql += "    UNION"    
> -            sql += "    SELECT COALESCE(SUM(sl.product_uom_qty), 0) AS total "
> -            sql += "    FROM (SELECT DISTINCT l.order_id, b.product_id, l.prodlot_id, l.product_uom_qty "
> -            sql += "          FROM sale_order_line l "
> -            sql += "          INNER JOIN product_product p ON l.product_id=p.id "
> -            sql += "          INNER JOIN product_template t ON p.product_tmpl_id=t.id AND t.supply_method='produce' "
> -            sql += "          INNER JOIN mrp_bom b ON b.bom_id IN (SELECT id FROM mrp_bom where product_id=p.id) "
> -            sql += "          WHERE pack_product_id IS NULL) sl "
> -            sql += "    INNER JOIN sale_order s ON sl.order_id=s.id "
> -            sql += "    INNER JOIN sale_group_line gl ON sl.product_id=gl.product_id "
> -            sql += "    INNER JOIN sale_group g ON gl.sale_group_id=g.id "
> -            sql += "    WHERE g.id=" + str(sale_group_id) + " AND s.date_order >= '" + date_start + "' AND s.date_order <= '" + date_end + "' "            
> -
> -
> +            sql = (
> +                "     SELECT COALESCE(SUM(sl.product_uom_qty), 0) AS total "
> +                "    FROM sale_order_line sl "
> +                "    INNER JOIN sale_order s ON sl.order_id=s.id "
> +                "    INNER JOIN "
> +                "sale_group_line gl ON sl.product_id=gl.product_id "
> +                "    INNER JOIN sale_group g ON gl.sale_group_id=g.id "
> +                "    WHERE g.id= %(salegroup) AND s.date_order >= '%(date_s)' "
> +                "AND s.date_order <= '(date_end)' "
> +                "    UNION "
> +                "    SELECT COALESCE(SUM(sl.product_uom_qty), 0) AS total "
> +                "    FROM (SELECT DISTINCT order_id, pack_product_id, "
> +                "pack_prodlot_id, product_uom_qty "
> +                "          FROM sale_order_line "
> +                "          WHERE NOT pack_product_id IS NULL) sl"
> +                "    INNER JOIN sale_order s ON sl.order_id=s.id "
> +                "    INNER JOIN sale_group_line gl ON "
> +                "sl.pack_product_id=gl.product_id "
> +                "    INNER JOIN sale_group g ON gl.sale_group_id=g.id "
> +                "    WHERE g.id= %(salegroup) AND s.date_order >= '%(date_s)' "
> +                "AND s.date_order <= '%(date_e)' "
> +                "    UNION"
> +                "    SELECT COALESCE(SUM(sl.product_uom_qty), 0) AS total "
> +                "    FROM (SELECT DISTINCT l.order_id, "
> +                "b.product_id, l.prodlot_id, l.product_uom_qty "
> +                "     FROM sale_order_line l "
> +                "     INNER JOIN product_product p ON l.product_id=p.id "
> +                "     INNER JOIN product_template t ON p.product_tmpl_id=t.id"
> +                " AND t.supply_method='produce' "
> +                "     INNER JOIN mrp_bom b ON b.bom_id IN (SELECT id FROM"
> +                " mrp_bom where product_id=p.id) "
> +                "          WHERE pack_product_id IS NULL) sl "
> +                "    INNER JOIN sale_order s ON sl.order_id=s.id "
> +                "    INNER JOIN sale_group_line gl "
> +                "ON sl.product_id=gl.product_id "
> +                "    INNER JOIN sale_group g ON gl.sale_group_id=g.id "
> +                "    WHERE g.id=%(salegroup) AND s.date_order >= '%(date_s)' "
> +                "AND s.date_order <= '%(date_e)' ") % {
> +                    "salegroup": str(sale_group_id),
> +                    "date_s": date_start,
> +                    "date_e": date_end
> +                    }
>              """ Contamos total de productos vendidos del grupo de ventas """
> -            
>              sql_total = "SELECT SUM(total) FROM ( "
>              sql_total += sql
> -        
>              if sale_group.partner_sales and partner_id:
> -                sql_total += "AND s.partner_id= " + str(partner_id)            
> -            
> +                sql_total += "AND s.partner_id= %s" % str(partner_id)
>              sql_total += ") t "
> -
>              cr.execute(sql_total)
> -            
>              t = cr.fetchall()
>              total = t[0][0] or 0
> -            
> -            """ Calculamos porcentajes actuales de los productos del grupo de ventas """
> +            """ Calculamos porcentajes actuales de los productos del grupo de
> +             ventas """
>              products = []
>              for line in sale_group.sale_group_line_ids:
>                  product = {}
> -                
>                  sql_total = "SELECT SUM(total) FROM ( "
>                  sql_total += sql
> -                sql_total += "AND gl.product_id=" + str(line.product_id.id) + " "
> -                
> +                sql_total += ("AND gl.product_id=%s") % (
> +                    str(line.product_id.id))
> +                + " "
>                  if sale_group.partner_sales and partner_id:
> -                    sql_total += "AND s.partner_id= " + str(partner_id)        
> -                
> +                    sql_total += ("AND s.partner_id= %s") % (str(partner_id))
>                  sql_total += ") t "
> -                
>                  cr.execute(sql_total)
> -                
>                  t = cr.fetchall()
>                  total_product = t[0][0] or 0
> -                            
>                  product['id'] = line.product_id.id
>                  product['percentage'] = line.percentage
>                  if total > 0:
> -                    product['actual_percentage'] = (total_product / total) * 100
> +                    product['actual_percentage'] = total_product / total * 100
>                  else:
>                      product['actual_percentage'] = 0
> -                
>                  products.append(product)
> -                
>              """ Filtramos por productos """
>              if product_ids:
>                  products = filter(lambda x: x['id'] in product_ids, products)
> -
> -            """ Devolvemos el primer producto que no cumpla su porcentage estimado """
> +            """ Devolvemos el primer producto que no cumpla su porcentage
> +             estimado """
>              if products and len(products) > 0:
> -                
> -                """ Guardamos primer producto con mayor porcentage del grupo de ventas """
> +                """ Guardamos primer producto con mayor porcentage del
> +                 grupo de ventas """
>                  product_id = products[0]['id']
> -                
>                  """ Recorremos productos """
>                  for p in products:
>                      if p['actual_percentage'] < p['percentage']:
> -                        product_id = p['id'] 
> -                        return product_id
> -                
> +                        return p['id']
>          return product_id
> -    
> -    def sale_group_type_change(self, cr, uid, ids, sale_group_type, pricelist, product, contract_id=False, prodlot_id=False, num_cabins=0, qty=0,
> -            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
> -            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
> -    
> -        result = {}
> -        domain = {}
> -        warning = {}
> -        
> +
> +    def sale_group_type_change(self, cr, uid, ids, sale_group_type,
> +                               pricelist, product, contract_id=False,
> +                               prodlot_id=False, num_cabins=0, qty=0,
> +                               uom=False, qty_uos=0, uos=False, name='',
> +                               partner_id=False, lang=False, update_tax=True,
> +                               date_order=False, packaging=False,
> +                               fiscal_position=False, flag=False,
> +                               context=None):
>          if sale_group_type:
>              if contract_id:
> -                contract_obj = self.pool.get('contract.contract')
> -                contract = contract_obj.browse(cr, uid, contract_id, context=None)
> +                contract_obj = self.pool['contract.contract']
> +                contract = contract_obj.browse(cr, uid, contract_id,
> +                                               context=context)
>                  sale_group_id = None
> -                
>                  if sale_group_type == 'sim':
> -                    sale_group_id = contract.sale_group_sim_id and contract.sale_group_sim_id.id or None
> +                    sale_group_id = (contract.sale_group_sim_id and

Esto se puede poner directamente:

sale_group_id = contract.sale_group_sim_id.id

Ya que devolverá False en caso de que contract.sale_group_sim_id sea un browser_record_null.

> +                                     contract.sale_group_sim_id.id or None)
>                  elif sale_group_type == 'enlace':
> -                    sale_group_id = contract.sale_group_link_id and contract.sale_group_link_id.id or None
> +                    sale_group_id = (contract.sale_group_link_id and

sale_group_id = contract.sale_group_link_id.id

> +                                     contract.sale_group_link_id.id or None)
>                  elif sale_group_type == 'pack':
> -                    sale_group_id = contract.sale_group_pack_id and contract.sale_group_pack_id.id or None
> -                    
> +                    sale_group_id = (contract.sale_group_pack_id and

sale_group_id = contract.sale_group_pack_id.id

> +                                     contract.sale_group_pack_id.id or None)
>                  if sale_group_id:
> -                    product_id = self.get_suggested_sale_product(cr, uid, sale_group_id, partner_id, date_order)
> -                    
> -                    """ Llamamos a la funcion on_change por defecto de product_id """
> -                    product_id_change = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product_id, qty, uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag)
> -                    
> -                    if product_id_change != None:    
> -                        if product_id_change.has_key('value'):
> -                            result = product_id_change['value']
> -                        if product_id_change.has_key('domain'):
> -                            domain = product_id_change['domain']
> -                        if product_id_change.has_key('warning'):
> -                            warning = product_id_change['warning']    
> -                            
> -                    result['sale_group_id'] = sale_group_id
> -                    result['product_id'] = product_id
> -                
> -                else:        
> -                    raise osv.except_osv(_('No Sales Group Defined !'), _('You have to select a sales group in the partner contract form !\nPlease set one sales group before choosing a sales type.'))
> +                    product_id = self.get_suggested_sale_product(
> +                        cr, uid, sale_group_id, partner_id, date_order,
> +                        context)
> +                    """ Llamamos a la funcion on_change por defecto de
> +                     product_id """
> +                    super_sol = super(SaleOrderLine, self)
> +                    pro_id_chng = super_sol.product_id_change(
> +                        cr, uid, ids, pricelist, product_id, qty, uom, qty_uos,
> +                        uos, name, partner_id, lang, update_tax, date_order,
> +                        packaging, fiscal_position, flag, context)
> +                    pro_id_chng['value']['sale_group_id'] = sale_group_id
> +                    pro_id_chng['value']['product_id'] = product_id
> +                else:
> +                    raise orm.except_orm(_('No Sales Group Defined !'),
> +                                         _('You have to select a sales group '
> +                                           'in the partner contract form '
> +                                           '!\nPlease set one sales group '
> +                                           'before choosing a sales type.'))
>              else:
> -                raise osv.except_osv(_('No Contract Defined !'), _('You have to select a contract in the sales form !\nPlease set one contract before choosing a sales type.'))
> -                
> -        return {'value': result, 'domain': domain, 'warning': warning}
> -    
> -    def sale_group_id_change(self, cr, uid, ids, sale_group_id, pricelist, product, contract_id=False, prodlot_id=False, num_cabins=0, qty=0,
> -            uom=False, qty_uos=0, uos=False, name='', partner_id=False,
> -            lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False):
> -    
> -        result = {}
> -        domain = {}
> -        warning = {}
> -        
> +                raise orm.except_orm(_('No Contract Defined !'),
> +                                     _('You have to select a contract in the '
> +                                       'sales form !\nPlease set one contract '
> +                                       'before choosing a sales type.'))
> +        return {'value': pro_id_chng.get('value', {}),
> +                'domain': pro_id_chng.get('domain', {}),
> +                'warning': pro_id_chng.get('warning', {})
> +                }
> +
> +    def sale_group_id_change(self, cr, uid, ids, sale_group_id, pricelist,
> +                             product, contract_id=False, prodlot_id=False,
> +                             num_cabins=0, qty=0, uom=False, qty_uos=0,
> +                             uos=False, name='', partner_id=False, lang=False,
> +                             update_tax=True, date_order=False,
> +                             packaging=False, fiscal_position=False,
> +                             flag=False, context=None):
>          if sale_group_id:
> -            
> -            product_id = self.get_suggested_sale_product(cr, uid, sale_group_id, partner_id, date_order)
> -            
> +            product_id = self.get_suggested_sale_product(
> +                cr, uid, sale_group_id, partner_id, date_order)
>              """ Llamamos a la funcion on_change por defecto de product_id """
> -            product_id_change = super(sale_order_line, self).product_id_change(cr, uid, ids, pricelist, product_id, qty, uom, qty_uos, uos, name, partner_id, lang, update_tax, date_order, packaging, fiscal_position, flag)
> -            
> -            if product_id_change != None:    
> -                if product_id_change.has_key('value'):
> -                    result = product_id_change['value']
> -                if product_id_change.has_key('domain'):
> -                    domain = product_id_change['domain']
> -                if product_id_change.has_key('warning'):
> -                    warning = product_id_change['warning']
> -                    
> -            result['sale_group_type'] = None
> -            result['product_id'] = product_id
> -        
> -        return {'value': result, 'domain': domain, 'warning': warning}
> -        
> -sale_order_line()
> +            product_id_change = super(SaleOrderLine, self).product_id_change(
> +                cr, uid, ids, pricelist, product_id, qty, uom, qty_uos, uos,
> +                name, partner_id, lang, update_tax, date_order, packaging,
> +                fiscal_position, flag, context)
> +            product_id_change['value']['sale_group_id'] = sale_group_id
> +            product_id_change['value']['product_id'] = product_id
> +        return {'value': product_id_change.get('value', {}),
> +                'domain': product_id_change.get('domain', {}),
> +                'warning': product_id_change.get('warning', {})
> +                }
> 
> === added directory 'dos_sale_group/views'
> === renamed file 'dos_sale_group/sale_group_view.xml' => 'dos_sale_group/views/sale_group_view.xml'
> --- dos_sale_group/sale_group_view.xml	2014-06-11 10:23:47 +0000
> +++ dos_sale_group/views/sale_group_view.xml	2014-07-01 10:59:54 +0000
> @@ -1,11 +1,10 @@
>  <?xml version="1.0" encoding="utf-8"?>
>  <openerp>
> -    <data>
> +	<data>
>  		<!-- Pieces Search View-->
>  		<record model="ir.ui.view" id="sale_group_search_view">
>  			<field name="name">sale.group.search.view</field>
>  			<field name="model">sale.group</field>
> -			<field name="type">search</field>
>  			<field name="arch" type="xml">
>  				<search string="Sale Group">
>  					<field name="type" string="Type"/>	
> @@ -15,11 +14,10 @@
>  			</field>
>  		</record>
>  		
> -         <!--Sale Group Tree View -->
> -        <record model="ir.ui.view" id="sale_group_tree_view">
> +			<!--Sale Group Tree View -->
> +		<record model="ir.ui.view" id="sale_group_tree_view">
>  			<field name="name">sale.group.tree.view</field>
>  			<field name="model">sale.group</field>
> -			<field name="type">tree</field>
>  			<field name="arch" type="xml">
>  				<tree string="Sale Group">
>  					<field name="type"/>
> @@ -27,13 +25,12 @@
>  					<field name="partner_sales"/>
>  				</tree>
>  			</field>
> -        </record>
> +		</record>
>  		
>  		<!--Sale Group Form View -->
> -        <record model="ir.ui.view" id="sale_group_form_view">
> +		<record model="ir.ui.view" id="sale_group_form_view">
>  			<field name="name">sale.group.form.view</field>
>  			<field name="model">sale.group</field>
> -			<field name="type">form</field>
>  			<field name="arch" type="xml">
>  				<form string="Sale Group">
>  					<group colspan="4" col="4">
> @@ -60,24 +57,22 @@
>          <menuitem name="Sales Groups" action="action_see_sale_group" id="menu_sale_groups" parent="base.menu_product" sequence="2"/>
>  		
>  		
> -         <!--Sale Group Line Tree View -->
> -        <record model="ir.ui.view" id="sale_group_line_tree_view">
> +		<!--Sale Group Line Tree View -->
> +		<record model="ir.ui.view" id="sale_group_line_tree_view">
>  			<field name="name">sale.group.line.tree.view</field>
>  			<field name="model">sale.group.line</field>
> -			<field name="type">tree</field>
>  			<field name="arch" type="xml">
>  				<tree string="Sale Group">
>  					<field name="product_id"/>
>  					<field name="percentage"/>
>  				</tree>
>  			</field>
> -        </record>
> +		</record>
>  		
>  		<!--Sale Group Form View -->
> -        <record model="ir.ui.view" id="sale_group_line_form_view">
> +		<record model="ir.ui.view" id="sale_group_line_form_view">
>  			<field name="name">sale.group.line.form.view</field>
>  			<field name="model">sale.group.line</field>
> -			<field name="type">form</field>
>  			<field name="arch" type="xml">
>  				<form string="Sale Group Line">
>  					<group colspan="4" col="4">
> 
> === renamed file 'dos_sale_group/sale_order_line_view.xml' => 'dos_sale_group/views/sale_order_line_view.xml'
> --- dos_sale_group/sale_order_line_view.xml	2014-06-11 10:23:47 +0000
> +++ dos_sale_group/views/sale_order_line_view.xml	2014-07-01 10:59:54 +0000
> @@ -6,22 +6,21 @@
>  		<record model="ir.ui.view" id="view_order_group_sales_form_inherit">

¿Está puesto con tabuladores en lugar de espacios?

>  			<field name="name">sale.order.group.sales.form.inherit</field>
>  			<field name="model">sale.order</field>
> -			<field name="inherit_id" ref="sale_layout.view_order_form_inherit_1"/>
> -			<field name="type">form</field>
> +			<field name="inherit_id" ref="sale.view_order_form"/>
>  			<field name="arch" type="xml">
> -				<xpath expr="/form/notebook/page/field[@name='abstract_line_ids']/form/notebook/page/field[@name='product_id']" position="before">		
> +				<xpath expr="//field[@name='order_line']/form//field[@name='product_id']" position="before">		
>  					<field colspan="4" 
>  						   name="sale_group_type"
>  						   on_change="sale_group_type_change(sale_group_type, parent.pricelist_id, product_id, parent.contract_id, prodlot_id, num_cabins, product_uom_qty, product_uom, product_uos_qty,
>  						   product_uos,name,parent.partner_id, 'lang' in context and context['lang'], True, parent.date_order, 
>  						   product_packaging, parent.fiscal_position, False)"
> -					/>
> -					<field colspan="4" 
> -						   name="sale_group_id"
> -						   on_change="sale_group_id_change(sale_group_id, parent.pricelist_id,product_id, parent.contract_id, prodlot_id, num_cabins, product_uom_qty, product_uom, product_uos_qty,
> -						   product_uos, name, parent.partner_id, 'lang' in context and context['lang'], True, parent.date_order, 
> -						   product_packaging, parent.fiscal_position, False)"
> -					/>	
> +<!-- 					/> -->

¿Por qué has comentado este código? Si es justo lo que añade este módulo, lo que pasa que es un campo de sale.order.line, y por eso la referencia al xpath del one2many. Descoméntalo, por favor.

> +<!-- 					<field colspan="4"  -->
> +<!-- 						   name="sale_group_id" -->
> +<!-- 						   on_change="sale_group_id_change(sale_group_id, parent.pricelist_id,product_id, parent.contract_id, prodlot_id, num_cabins, product_uom_qty, product_uom, product_uos_qty, -->
> +<!-- 						   product_uos, name, parent.partner_id, 'lang' in context and context['lang'], True, parent.date_order,  -->
> +<!-- 						   product_packaging, parent.fiscal_position, False)" -->
> +<!-- 					/>	 -->
>                  </xpath> 
>  			</field>
>  		</record>
> 


-- 
https://code.launchpad.net/~dani-ds/avanzosc/dos_sale_group/+merge/223900
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.


References