← Back to team overview

avanzosc team mailing list archive

Re: [Merge] lp:~oihanecruce/avanzosc/nayar_sales_extension into lp:~avanzosc-security-team/avanzosc/72horas

 

Review: Needs Fixing code review

Ya te he hecho los comentarios sobre res.partner.address.

Un saludo.

Diff comments:

> === modified file 'nayar_sales_extension/__init__.py'
> --- nayar_sales_extension/__init__.py	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/__init__.py	2014-07-03 14:22:37 +0000
> @@ -19,11 +19,4 @@
>  #
>  ##############################################################################
>  
> -import sale
> -import state
> -import sale_group
> -import annexe
> -import refund_products
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> -
> +from . import models
> 
> === modified file 'nayar_sales_extension/__openerp__.py'
> --- nayar_sales_extension/__openerp__.py	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/__openerp__.py	2014-07-03 14:22:37 +0000
> @@ -24,21 +24,18 @@
>      "version": "1.2",
>      "author": "Nayar Systems",
>      "category": "Enterprise Specific Modules",
> -    "description": "Proporciona funcionalidad extra para la web de pedidos de 72horas",
> +    "description": "Proporciona funcionalidad extra para la web de pedidos de "
> +    "72horas",
>      "depends": [
>          'sale',
>          'dos_sale_group',
>          'nayar_dos_contracts',
>          'account_payment_sepa_direct_debit',
> -        ],
> -    "init_xml": [],
> -    "demo_xml": [],
> -    "update_xml": [
> -        'sales_data.xml',
> -        ],
> +    ],
> +    "data": [
> +        'data/sales_data.xml',
> +    ],
>      "website": 'http://www.72horas.net/',
>      "active": False,
>      "installable": True
>  }
> -
> -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> 
> === added directory 'nayar_sales_extension/data'
> === renamed file 'nayar_sales_extension/sales_data.xml' => 'nayar_sales_extension/data/sales_data.xml'
> --- nayar_sales_extension/sales_data.xml	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/data/sales_data.xml	2014-07-03 14:22:37 +0000
> @@ -1,70 +1,90 @@
>  <?xml version="1.0" encoding="utf-8"?>
>  <openerp>
> -  <data noupdate="1">
> -    <record id="web_direct_debit_payment_type" model="ir.property" forcecreate="True">
> -      <field name="name">web_direct_debit_payment_type</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'payment_type_customer')]"/>
> -      <field name="value" eval="'payment.type,8'"/>
> -    </record>
> -
> -    <record id="web_transfer_payment_type" model="ir.property" forcecreate="True">
> -      <field name="name">web_transfer_payment_type</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'payment_type_customer')]"/>
> -      <field name="value" eval="'payment.type,9'"/>
> -    </record>
> -
> -    <record id="web_num_months_first_invoice" model="ir.property" forcecreate="True">
> -      <field name="name">web_num_months_first_invoice</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'num_months_first_invoice')]"/>
> -      <field name="type">integer</field>
> -      <field name="value">2</field>
> -    </record>
> -
> -    <record id="web_ciclo_cobro" model="ir.property" forcecreate="True">
> -      <field name="name">web_ciclo_cobro</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'ciclo_cobro')]"/>
> -      <field name="type">integer</field>
> -      <field name="value">1</field>
> -    </record>
> -
> -    <record id="web_tipo_ciclo_cobro" model="ir.property" forcecreate="True">
> -      <field name="name">web_tipo_ciclo_cobro</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'tipo_ciclo_cobro')]"/>
> -      <field name="type">char</field>
> -      <field name="value">mes</field>
> -    </record>
> -
> -    <record id="web_pre_pago" model="ir.property" forcecreate="True">
> -      <field name="name">web_pre_pago</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'pre_pago')]"/>
> -      <field name="type">boolean</field>
> -      <field name="value" eval="True"/>
> -    </record>
> -
> -    <record id="web_property_account_position" model="ir.property" forcecreate="True">
> -      <field name="name">web_property_account_position</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'property_account_position')]"/>
> -      <!-- Regimen Nacional -->
> -      <field name="value" eval="'account.fiscal.position,1'"/>
> -    </record>
> -
> -    <record id="web_property_payment_term" model="ir.property" forcecreate="True">
> -      <field name="name">web_property_payment_term</field>
> -      <field name="fields_id" search="[('model', '=', 'res.partner'), ('name', '=', 'property_payment_term')]"/>
> -      <!-- Dia 10 de factura -->
> -      <field name="value" eval="'account.payment.term,12'"/>
> -    </record>
> -
> -    <record id="web_parent_receivable_account" model="ir.property" forcecreate="True">
> -      <field name="name">web_parent_receivable_account</field>
> -      <field name="fields_id" search="[('model', '=', 'account.account'), ('name', '=', 'parent_id')]"/>
> -      <field name="value" eval="'account.account,518'"/>
> -    </record>
> -
> -    <record id="web_parent_payable_account" model="ir.property" forcecreate="True">
> -      <field name="name">web_parent_payable_account</field>
> -      <field name="fields_id" search="[('model', '=', 'account.account'), ('name', '=', 'parent_id')]"/>
> -      <field name="value" eval="'account.account,506'"/>
> -    </record>
> -  </data>
> +    <data noupdate="1">
> +        <record id="web_direct_debit_payment_type" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_direct_debit_payment_type</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'payment_type_customer')]" />
> +            <field name="value" eval="'payment.type,8'" />
> +        </record>
> +
> +        <record id="web_transfer_payment_type" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_transfer_payment_type</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'payment_type_customer')]" />
> +            <field name="value" eval="'payment.type,9'" />
> +        </record>
> +
> +        <record id="web_num_months_first_invoice" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_num_months_first_invoice</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'num_months_first_invoice')]" />
> +            <field name="type">integer</field>
> +            <field name="value">2</field>
> +        </record>
> +
> +        <record id="web_ciclo_cobro" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_ciclo_cobro</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'ciclo_cobro')]" />
> +            <field name="type">integer</field>
> +            <field name="value">1</field>
> +        </record>
> +
> +        <record id="web_tipo_ciclo_cobro" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_tipo_ciclo_cobro</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'tipo_ciclo_cobro')]" />
> +            <field name="type">char</field>
> +            <field name="value">mes</field>
> +        </record>
> +
> +        <record id="web_pre_pago" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_pre_pago</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'pre_pago')]" />
> +            <field name="type">boolean</field>
> +            <field name="value" eval="True" />
> +        </record>
> +
> +        <record id="web_property_account_position" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_property_account_position</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'property_account_position')]" />
> +            <!-- Regimen Nacional -->
> +            <field name="value" eval="'account.fiscal.position,1'" />
> +        </record>
> +
> +        <record id="web_property_payment_term" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_property_payment_term</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'res.partner'), ('name', '=', 'property_payment_term')]" />
> +            <!-- Dia 10 de factura -->
> +            <field name="value" eval="'account.payment.term,12'" />
> +        </record>
> +
> +        <record id="web_parent_receivable_account" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_parent_receivable_account</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'account.account'), ('name', '=', 'parent_id')]" />
> +            <field name="value" eval="'account.account,518'" />
> +        </record>
> +
> +        <record id="web_parent_payable_account" model="ir.property"
> +            forcecreate="True">
> +            <field name="name">web_parent_payable_account</field>
> +            <field name="fields_id"
> +                search="[('model', '=', 'account.account'), ('name', '=', 'parent_id')]" />
> +            <field name="value" eval="'account.account,506'" />
> +        </record>
> +    </data>
>  </openerp>
> 
> === added directory 'nayar_sales_extension/models'
> === added file 'nayar_sales_extension/models/__init__.py'
> --- nayar_sales_extension/models/__init__.py	1970-01-01 00:00:00 +0000
> +++ nayar_sales_extension/models/__init__.py	2014-07-03 14:22:37 +0000
> @@ -0,0 +1,26 @@
> +# -*- coding: utf-8 -*-
> +##############################################################################
> +#
> +#    OpenERP, Open Source Management Solution
> +#    Copyright (C) 2013 Nayar Systems (<http://www.72horas.net/>)
> +#
> +#    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 . import sale
> +from . import state
> +from . import sale_group
> +from . import annexe
> +from . import refund_products
> 
> === renamed file 'nayar_sales_extension/annexe.py' => 'nayar_sales_extension/models/annexe.py'
> --- nayar_sales_extension/annexe.py	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/models/annexe.py	2014-07-03 14:22:37 +0000
> @@ -19,31 +19,29 @@
>  #
>  ##############################################################################
>  
> -from osv import osv
> -import time
> -
> -
> -class annexe(osv.osv):
> +from openerp.osv import orm
> +
> +
> +class ContractAnnexe(orm.Model):
>      _inherit = 'contract.annexe'
>  
> -    def get_partner(self, cr, uid, data):
> +    def get_partner(self, cr, uid, data, context=None):
>          """Return partner from annexe:
> -    ref: Telephone number
> -	"""
> +        ref: Telephone number
> +        """
>          # Contract and partner
> -        annexe_obj = self.pool.get('contract.annexe')
> -        annexe_id = annexe_obj.search(cr, uid, [('production_lot_id.ref', '=', data.get('ref'))])
> +        annexe_id = self.search(
> +            cr, uid, [('production_lot_id.ref', '=', data.get('ref'))],
> +            context=context)
>          if not annexe_id:
>              return 'No se encuentra'
>  
> -        annexe = annexe_obj.browse(cr, uid, annexe_id[0])
> -	if not annexe.production_lot_2_id:
> -	    return 'Solo SIM'
> +        annexe = self.browse(cr, uid, annexe_id[0], context=context)
> +        if not annexe.production_lot_2_id:
> +            return 'Solo SIM'
>  
> -	#Partner
> +        #Partner
>          partner = annexe.contract_id.elevator_id.name
> -	if not partner:
> -	    return 'No existe cliente'
> -	return partner
> -
> -annexe()
> +        if not partner:
> +            return 'No existe cliente'
> +        return partner
> 
> === renamed file 'nayar_sales_extension/refund_products.py' => 'nayar_sales_extension/models/refund_products.py'
> --- nayar_sales_extension/refund_products.py	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/models/refund_products.py	2014-07-03 14:22:37 +0000
> @@ -18,84 +18,56 @@
>  #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
>  #
>  ##############################################################################
> +
>  import time
> -from osv import osv
> -
> -class refund_products(osv.osv):
> +from openerp.osv import orm
> +
> +
> +class RefundProducts(orm.Model):
>      _inherit = 'refund.products'
>  
> -    def new_refund(self, cr, uid, data):
> +    def new_refund(self, cr, uid, data, context=None):
>          """Make a new refund:
> -	ref:Telephone number
> -"""
> -	"""
> -	#Recibimos el diccionario
> -	partners = self.pool.get('res.partner')
> -        partner_id = partners.search(cr, uid, [('partner_id_72horas', '=', data.get('partner_id_72horas'))])
> -	if not partner_id:
> -		return []
> -	"""
> -
> -	new_refund = {'date' : time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
> -		      'state': 'draft',
> -		     }
> -	#Creating new refund
> -	refund_id = self.pool.get('refund.products').create(cr,uid, new_refund)
> -	refund = self.pool.get('refund.products').browse(cr,uid, refund_id)
> -
> -	#Check phonenumber
> -	phone = data.get('ref')
> -	print "lalalal"+str(phone)
> -	production_lots = self.pool.get('stock.production.lot')
> -	production_lot_ids = production_lots.search(cr,uid,[('ref', '=', phone)])
> -	if not production_lot_ids:
> -		return ["No se encuentra"]
> - 	print "Creado new refund"
> -	for lot in production_lot_ids:
> -		p = production_lots.browse(cr,uid, lot)
> -		if p.product_id.name.split()[0] == 'Pack':
> -			print p.product_id.name
> -			production_lot_id = p.id
> -	production_lot = production_lots.browse(cr,uid, production_lot_id)
> -	print "Encontrado el lote de produccion"
> -
> -	"""
> -	#El teléfono existe, comprobamos que está en un anexo
> -	annexes = self.pool.get('contract.annexe')
> -	annexe_id = annexes.search(['production_lot_id', '=', production_lot_id])
> -	if not annexe_id:
> -		return []
> -		
> -	#Comprobamos que el anexo es del cliente
> -	annexe = annexes.browse(cr,uid, annexe_id)
> -	partner_annexe_72horas_id = annexe.contract_id.customer_id.partner_id_72horas.id
> -	if partner_annexe_72horas_id != data.get('partner_id_72horas'):
> -		return []
> -
> -	#Creamos un pack de reposicion ficticio
> -	product_idle_id = production_lots.search('ref', '=', '665165794')
> -	product_idle = production_lots.browse(cr,uid, product_idle_id)
> -
> -	"""
> -	print production_lot.id
> -	#Creamos la línea de reposición
> -	new_refund = {'refund_id': refund.id,
> -		      'refund_product_id' : production_lot.product_id.id,
> -		      'refund_prodlot_id' : production_lot.id,
> -		      'product_id' : production_lot.product_id.id, #el mismo tipo de producto
> -		      'prodlot_id' : production_lot.product_id.id,
> -		      }
> -	print "Creada la lina de reposicion"
> -
> -	#Updade de la localización final del pack
> -	refund_ids = self.pool.get('refund.products')
> -	#new_refund.update(refund_ids.onchange_refund_products(cr, uid, [], production_lot.product_id.id)['value'])
> -	new_refund['location_dest_id'] = '15'
> -	new_refund['location_id'] = '9'
> -       
> -	new_refund_product = self.pool.get('refund.product').create(cr,uid, new_refund)
> -
> -	print "Update de la localiz"
> -	#¿Dónde indico que la linea que acabo de crear va relacionada con esa reposición?
> -
> -refund_products()
> +        ref:Telephone number
> +        """
> +
> +        new_refund = {
> +            'date': time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
> +            'state': 'draft',
> +        }
> +
> +        #Creating new refund

Espacio después de la #

> +        refund_id = self.create(cr, uid, new_refund, context=context)
> +        refund = self.browse(cr, uid, refund_id, context=context)
> +
> +        #Check phonenumber

Espacio después de #

> +        phone = data['ref']
> +
> +        lot_obj = self.pool['stock.production.lot']
> +        lot_ids = lot_obj.search(cr, uid, [('ref', '=', phone)],
> +                                 context=context)
> +        if not lot_ids:
> +            return ["No se encuentra"]
> +
> +        for lot in lot_ids:
> +            p = lot_obj.browse(cr, uid, lot)
> +            if p.product_id.name.split()[0] == 'Pack':
> +                production_lot_id = p.id
> +        production_lot = lot_obj.browse(cr, uid, production_lot_id,
> +                                        context=context)
> +
> +        #Creamos la línea de reposición

Espacio después de #

> +        new_refund = {
> +            'refund_id': refund.id,
> +            'refund_product_id': production_lot.product_id.id,
> +            'refund_prodlot_id': production_lot.id,
> +            #el mismo tipo de producto
> +            'product_id': production_lot.product_id.id,
> +            'prodlot_id': production_lot.product_id.id,
> +        }
> +
> +        #Updade de la localización final del pack

Espacio después de #

> +        new_refund['location_dest_id'] = '15'
> +        new_refund['location_id'] = '9'
> +
> +        return self.create(cr, uid, new_refund, context=context)
> 
> === renamed file 'nayar_sales_extension/sale.py' => 'nayar_sales_extension/models/sale.py'
> --- nayar_sales_extension/sale.py	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/models/sale.py	2014-07-03 14:22:37 +0000
> @@ -19,42 +19,59 @@
>  #
>  ##############################################################################
>  
> -from osv import osv
> +from openerp.osv import orm
>  import time
> -from tools.translate import _
> -
> -class sale_order(osv.osv):
> +from openerp.tools.translate import _
> +
> +
> +class SaleOrder(orm.Model):
>      _inherit = 'sale.order'
>  
> -    def create_order(self, cr, uid, data):
> +    def create_order(self, cr, uid, data, context=None):
>          """Make a new sale order:
> -    order_id_72horas: Order id at 72horas system.
> -    contract_id: Contract for the order.
> -    branch: Company branch (optional).
> -    notes: Order notes and observations (optional).
> -    lines: Order lines list with format {'sale_type', 'sale_group' (optional), 'ref' (optional), 'cabins' (list of strings with references), 'line_id_72horas' (optional)}."""
> +        order_id_72horas: Order id at 72horas system.
> +        contract_id: Contract for the order.
> +        branch: Company branch (optional).
> +        notes: Order notes and observations (optional).
> +        lines: Order lines list with format {'sale_type',
> +            'sale_group' (optional), 'ref' (optional),
> +            'cabins' (list of strings with references),
> +            'line_id_72horas' (optional)}."""
> +
> +        product_obj = self.pool['product.product']
>  
>          # Contract and partner
> -        contract_obj = self.pool.get('contract.contract')
> -        contract_ids = contract_obj.search(cr, uid, [('ref', '=', data.get('contract_id'))])
> +        contract_obj = self.pool['contract.contract']
> +        contract_ids = contract_obj.search(cr, uid,
> +                                           [('ref', '=', data['contract_id'])],
> +                                           context=context)
>          if not contract_ids:
>              return []
> -        contract = contract_obj.browse(cr, uid, contract_ids[0])
> -
> -        new_order = {'order_id_72horas': data.get('order_id_72horas'),
> -                     'partner_id': contract.customer_id.id,
> -                     'date_order': time.strftime("%Y-%m-%d", time.localtime()),
> -                     'invoice_quantity': 'procurement',
> -                     'note': data.get('notes')}
> -
> -        order_obj = self.pool.get('sale.order')
> -        new_order.update(order_obj.onchange_partner_id(cr, uid, [], contract.customer_id.id)['value'])
> +        contract = contract_obj.browse(cr, uid, contract_ids[0],
> +                                       context=context)
> +
> +        new_order = {
> +            'order_id_72horas': data.get('order_id_72horas'),
> +            'partner_id': contract.customer_id.id,
> +            'date_order': time.strftime("%Y-%m-%d", time.localtime()),
> +            'invoice_quantity': 'procurement',
> +            'note': data.get('notes'),
> +        }
> +
> +        order_obj = self.pool['sale.order']
> +        new_order.update(
> +            order_obj.onchange_partner_id(cr, uid, [],
> +                                          contract.customer_id.id)['value'])
>          new_order['contract_id'] = contract_ids[0]
> -        new_order.update(order_obj.onchange_contract_id(cr, uid, [], contract_ids[0])['value'])
> +        new_order.update(
> +            order_obj.onchange_contract_id(cr, uid, [],
> +                                           contract_ids[0])['value'])
>  
>          # Company branches
>          if data.get('branch'):
> -            address_ids = self.pool.get('res.partner.address').search(cr, uid, [('partner_id', '=', contract.elevator_id.id), ('partner_id_72horas', '=', data['branch'])])
> +            address_ids = self.pool['res.partner.address'].search(
> +                cr, uid, [('partner_id', '=', contract.elevator_id.id),
> +                          ('partner_id_72horas', '=', data['branch'])])
>              if address_ids:
>                  new_order['partner_shipping_id'] = address_ids[0]

Faltaría por saber qué data contiene 'branch', que yo estimo que será eso de 'default', 'shipping', 'invoice' y similar. Lo que vamos a poner es directamente:

new_order['partner_shipping_id'] = contract.elevator_id.id

>                  new_order.update(order_obj.onchange_partner_shipping_id(cr, uid, [], address_ids[0])['value'])
> @@ -76,7 +93,7 @@
>  
>          # Creating order lines
>          if 'lines' in data:
> -            line_obj = self.pool.get('sale.order.line')
> +            line_obj = self.pool['sale.order.line']
>              for l in data['lines']:
>                  cabins = l.get('cabins', [])
>                  new_line = {'order_id': order_id,
> @@ -97,21 +114,22 @@
>                          pass
>  
>                      if new_line.get('sale_group_id') and l.get('model'):
> -                        product_obj = self.pool.get('product.product')
> -                        product_ids = product_obj.search(cr, uid, [('name', 'like', 'Pack (%s +' % l['model'].strip())])
> +                        product_ids = product_obj.search(
> +                            cr, uid, [('name', 'like',
> +                                       'Pack (%s +' % l['model'].strip())],
> +                            context=context)
>                          if product_ids:
>                              new_line['product_id'] = line_obj.get_suggested_sale_product(cr, uid, new_line['sale_group_id'], order.partner_id.id, order.date_order, product_ids=product_ids)
>                              new_line.update(line_obj.product_id_change_inherit(cr, uid, [], order.pricelist_id.id, new_line['product_id'], contract_id=order.contract_id.id, partner_id=order.partner_id.id, date_order=order.date_order, fiscal_position=order.fiscal_position.id)['value'])
>  
>                  else:
>                      # We are expecting a product code
> -                    product_ids = self.pool.get('product.product').search(cr, uid, [('default_code', '=', l['sale_type'])])
> +                    product_ids = product_obj.search(cr, uid, [('default_code', '=', l['sale_type'])])
>                      if not product_ids:
>                          raise Exception("Product [%s] not found!!!" % l['sale_type'])
>  
>                      new_line['product_id'] = product_ids[0]
>                      new_line.update(line_obj.product_id_change_inherit(cr, uid, [], order.pricelist_id.id, new_line['product_id'], contract_id=order.contract_id.id, partner_id=order.partner_id.id, date_order=order.date_order, fiscal_position=order.fiscal_position.id)['value'])
> -                    
>  
>                  if new_line.get('tax_id'):
>                      new_line['tax_id'] = [(6, 0, new_line['tax_id'])]
> @@ -121,62 +139,69 @@
>                  line_obj.create(cr, uid, new_line)
>  
>                  # Si es un 4H, creamos tantas líneas de placas de audio como cabinas
> -		if 'model' in l and "3bymesa 4H" in l['model']:
> -		    new_line['product_id'] = 215
> -                    new_line.update(line_obj.product_id_change_inherit(cr, uid, [], order.pricelist_id.id, new_line['product_id'], contract_id=order.contract_id.id, partner_id=order.partner_id.id, date_order=order.date_order, fiscal_position=order.fiscal_position.id)['value'])
> -                    for c in xrange(len(cabins)-1):
> -			line_obj.create(cr, uid, new_line)
> +        if 'model' in l and "3bymesa 4H" in l['model']:
> +            new_line['product_id'] = 215
> +            new_line.update(line_obj.product_id_change_inherit(cr, uid, [], order.pricelist_id.id, new_line['product_id'], contract_id=order.contract_id.id, partner_id=order.partner_id.id, date_order=order.date_order, fiscal_position=order.fiscal_position.id)['value'])
> +            for c in xrange(len(cabins) - 1):
> +                line_obj.create(cr, uid, new_line)
>  
>              # Creating shipping costs line (or update existing one)
>              self.shipping_costs(cr, uid, [order.id])
>  
>          return [order.name]
>  
> -
> -    def create_basic_order(self, cr, uid, data):
> -        """Make a new sale order for a neighboring community or particular customer:
> -    order_id_72horas: Order id at 72horas system.
> -    customer_id or customer_id_72horas: Customer that makes the order.
> -    name: Community name.
> -    vat: Community VAT.
> -    address: Community address.
> -    zip: Community postal code.
> -    city: Community city.
> -    state: Community region or state.
> -    phone: Community phone (optional).
> -    email: Community e-mail (optional).
> -    bank_account: Community bank account (optional).
> -    agent_name: Agent name (optional).
> -    price: Price for the new contract.
> -    document: Contract document (attachment).
> -    mandate: SEPA Mandate (attachment).
> -    mandate_date: SEPA Mandate signature date.
> -    branch: Company branch (optional).
> -    notes: Order notes and observations (optional).
> -    invoicing_rules: {'track': 'elevator', 'sim': 'customer'} (optional).
> -    lines: Order lines list with format {'sale_type', 'sale_group' (optional), 'ref' (optional), 'cabins' (list of strings with references), 'line_id_72horas' (optional)}."""
> -
> +    def create_basic_order(self, cr, uid, data, context=None):
> +        """Make a new sale order for a neighboring community or particular
> +        customer:
> +        order_id_72horas: Order id at 72horas system.
> +        customer_id or customer_id_72horas: Customer that makes the order.
> +        name: Community name.
> +        vat: Community VAT.
> +        address: Community address.
> +        zip: Community postal code.
> +        city: Community city.
> +        state: Community region or state.
> +        phone: Community phone (optional).
> +        email: Community e-mail (optional).
> +        bank_account: Community bank account (optional).
> +        agent_name: Agent name (optional).
> +        price: Price for the new contract.
> +        document: Contract document (attachment).
> +        mandate: SEPA Mandate (attachment).
> +        mandate_date: SEPA Mandate signature date.
> +        branch: Company branch (optional).
> +        notes: Order notes and observations (optional).
> +        invoicing_rules: {'track': 'elevator', 'sim': 'customer'} (optional).
> +        lines: Order lines list with format
> +            {'sale_type', 'sale_group' (optional), 'ref' (optional),
> +             'cabins' (list of strings with references),
> +             'line_id_72horas' (optional)}."""
>  
>          # Get elevator
> -        partner_obj = self.pool.get('res.partner')
> +        partner_obj = self.pool['res.partner']
>          elevator_ids = False
>          if 'customer_id' in data:
> -            elevator_ids = partner_obj.search(cr, uid, [('ref', '=', data['customer_id'])])
> +            elevator_ids = partner_obj.search(
> +                cr, uid, [('ref', '=', data['customer_id'])], context=context)
>          elif 'customer_id_72horas' in data:
> -            elevator_ids = partner_obj.search(cr, uid, [('res_partner_h72_partner_ids.partner_id_72horas', '=', data['customer_id_72horas'])])
> +            elevator_ids = partner_obj.search(
> +                cr, uid, [('res_partner_h72_partner_ids.partner_id_72horas',
> +                           '=', data['customer_id_72horas'])],
> +                context=context)
>  
>          if not elevator_ids:
> -            raise osv.except_osv(_('Error !'), _("Elevator not found!!"))
> +            raise orm.except_orm(_('Error !'), _("Elevator not found!!"))
>          elevator_id = elevator_ids[0]
>          elevator = partner_obj.browse(cr, uid, elevator_id)
>  
>          # Create new partner for the community
>          vat = self._get_formatted_VAT(cr, uid, data['vat'])
>          if partner_obj.search(cr, uid, [('vat', '=', vat)]):
> -            raise osv.except_osv(_('Error !'), _('VAT duplicated !!'))
> +            raise orm.except_orm(_('Error !'), _('VAT duplicated !!'))
>  
> -        property_obj = self.pool.get('ir.property')
> -        direct_debit_payment_type = property_obj.get_generic(cr, uid, 'web_direct_debit_payment_type')
> +        property_obj = self.pool['ir.property']
> +        dd_pay_type = property_obj.get_generic(
> +            cr, uid, 'web_direct_debit_payment_type')
>          transfer_payment_type = property_obj.get_generic(cr, uid, 'web_transfer_payment_type')
>          num_months_first_invoice = property_obj.get_generic(cr, uid, 'web_num_months_first_invoice')
>          ciclo_cobro = property_obj.get_generic(cr, uid, 'web_ciclo_cobro')
> @@ -185,37 +210,36 @@
>          property_account_position = property_obj.get_generic(cr, uid, 'web_property_account_position')
>          property_payment_term = property_obj.get_generic(cr, uid, 'web_property_payment_term')
>  
> -        partner_id = partner_obj.create(cr, uid,
> -                                        {'name': data['name'],
> -                                         'payment_type_customer': direct_debit_payment_type.id if data.get('bank_account') else transfer_payment_type.id,
> -                                         'vat': self._get_formatted_VAT(cr, uid, data['vat']),
> -                                         'vat_subjected': True,
> -                                         'tipo_cliente': 'particular',
> -                                         'tipo_envio_correo': 'electronico' if data.get('email') else 'postal',
> -                                         'num_months_first_invoice': num_months_first_invoice,
> -                                         'ciclo_cobro': ciclo_cobro,
> -                                         'tipo_ciclo_cobro': tipo_ciclo_cobro,
> -                                         'pre_pago': pre_pago,
> -                                         'user_id': elevator.user_id.id,
> -                                         'property_account_position': property_account_position.id,
> -                                         'property_payment_term': property_payment_term.id,
> -                                         })
> +        partner_id = partner_obj.create(
> +            cr, uid, {'name': data['name'],
> +                      'payment_type_customer': dd_pay_type.id if data['bank_account'] else transfer_payment_type.id,

Poner 'is_company': True.

> +                      'vat': self._get_formatted_VAT(cr, uid, data['vat']),
> +                      'vat_subjected': True,
> +                      'tipo_cliente': 'particular',
> +                      'tipo_envio_correo': 'electronico' if data['email'] else 'postal',
> +                      'num_months_first_invoice': num_months_first_invoice,
> +                      'ciclo_cobro': ciclo_cobro,
> +                      'tipo_ciclo_cobro': tipo_ciclo_cobro,
> +                      'pre_pago': pre_pago,
> +                      'user_id': elevator.user_id.id,
> +                      'property_account_position': property_account_position.id,
> +                      'property_payment_term': property_payment_term.id,
> +                      }, context=context)
>          partner = partner_obj.browse(cr, uid, partner_id)
>  
>          # Create automatic accounts
> -        account_obj = self.pool.get('account.account')
>          parent_receivable = property_obj.get_generic(cr, uid, 'web_parent_receivable_account')
>          parent_payable = property_obj.get_generic(cr, uid, 'web_parent_payable_account')
>          partner_obj.create_accounts(cr, uid, [partner_id], context={'num_digits': 8, 'parent_receivable': parent_receivable, 'parent_payable': parent_payable})
>  
>          # Create address
> -        address_obj = self.pool.get('res.partner.address')
> +        address_obj = self.pool['res.partner.address']
>          address_id = address_obj.create(cr, uid,
>                                          {'partner_id': partner_id,
>                                           'type': 'default',
>                                           'street': data['address'],

Lo que aquí hay que hacer es poner estos datos directamente en el partner: street, city...

>                                           'city': data['city'],
> -                                         'state_id': self.pool.get('res.country.state').search_by_name(cr, uid, data['state']),
> +                                         'state_id': self.pool['res.country.state'].search_by_name(cr, uid, data['state']),
>                                           'country_id': 67,
>                                           'zip': data['zip'],
>                                           'phone': data.get('phone'),
> @@ -223,22 +247,21 @@
>                                           })
>  
>          if data.get('agent_name'):
> -            contact_id = self.pool.get('res.partner.contact').create(cr, uid,
> -                                                                     {'name': data['agent_name']})
> -            self.pool.get('res.partner.job').create(cr, uid,
> -                                                    {'address_id': address_id, 'contact_id': contact_id})
> +            contact_obj = self.pool['res.partner.contact']
> +            contact_id = contact_obj.create(cr, uid, {'name': data['agent_name']})

Aquí hay que crear otro res.partner que tenga por parent_id al anterior.

> +            self.pool['res.partner.job'].create(cr, uid, {'address_id': address_id, 'contact_id': contact_id})
>  
>          # Create bank account
>          if data.get('bank_account'):
> -            bank_obj = self.pool.get('res.partner.bank')
> +            bank_obj = self.pool['res.partner.bank']
>              bank_account = data['bank_account'].replace(" ", "")
>              if len(bank_account) == 24:
>                  bank_id = bank_obj.create(cr, uid,
>                                            {'state': 'iban',
>                                             'partner_id': partner_id,
> -                                           'acc_country_id': self.pool.get('res.country').search(cr, uid, [('code', '=', bank_account[:2])])[0],
> +                                           'acc_country_id': self.pool['res.country'].search(cr, uid, [('code', '=', bank_account[:2])])[0],
>                                             'iban': bank_account,
> -                                           'bank': self.pool.get('res.bank').search(cr, uid, [('code', '=', bank_account[4:8])])[0],
> +                                           'bank': self.pool['res.bank'].search(cr, uid, [('code', '=', bank_account[4:8])])[0],
>                                             'default_bank': True,
>                                             })
>              else:
> @@ -248,14 +271,14 @@
>                                             'partner_id': partner_id,
>                                             'acc_country_id': 67,
>                                             'acc_number': bank_account,
> -                                           'bank': self.pool.get('res.bank').search(cr, uid, [('code', '=', bank_account[:4])])[0],
> +                                           'bank': self.pool['res.bank'].search(cr, uid, [('code', '=', bank_account[:4])])[0],
>                                             'default_bank': True,
>                                             })

propagar context

>  
>              # Store SEPA Mandate
> -            mandate_attch = data.get('mandate') or data.get('document') or False
> +            mandate_attch = data['mandate'] or data['document'] or False

Déjalo de la otra forma, por si data no contiene el dato:

mandate_attch = data.get('mandate') or data.get('document') or False

>              if mandate_attch:
> -                mandate_obj = self.pool.get('sdd.mandate')
> +                mandate_obj = self.pool['sdd.mandate']
>                  new_mandate = {
>                      'company_id': partner.company_id.id,
>                      'partner_bank_id': bank_id,
> @@ -264,17 +287,17 @@
>                      'scan': str(mandate_attch),
>                      'sdd_scheme': 'core',
>                      'sepa_migrated': True,
> -                    'signature_date': data.get('mandate_date', time.strftime("%Y-%m-%d", time.localtime())),
> +                    'signature_date': data['mandate_date'] or time.strftime("%Y-%m-%d", time.localtime()),

Pon data.get por la misma razón

>                      'state': 'valid',
>                      'type': 'recurrent',
> -                    }
> +                }
>                  mandate_obj.create(cr, uid, new_mandate)
>  
>          else:
>              bank_id = False
>  
>          # Create contract for the new community
> -        template_obj = self.pool.get('contract.template')
> +        template_obj = self.pool['contract.template']
>          template_ids = template_obj.search(cr, uid, [('partner_id', '=', elevator_id), ('contract_type_id', 'in', [1, 3])])

propagar context

>          if template_ids:
>              template = template_obj.browse(cr, uid, template_ids[0])

propagar context

> @@ -287,7 +310,7 @@
>              contract_template_prices_rules_ids = template.contract_template_price_rules_ids
>              permanence_month = template.permanence_month
>          else:
> -            contract_type_obj = self.pool.get('contract.type')
> +            contract_type_obj = self.pool['contract.type']
>              template_ids = contract_type_obj.search(cr, uid, [('ref', '=', 'Basico')])
>              template = contract_type_obj.browse(cr, uid, template_ids[0])
>              contract_type_id = template_ids[0]
> @@ -298,8 +321,10 @@
>              permanence_month = template.permanence_month
>  
>          # Si la plantilla tiene un valor -1, False o None, cogemos el valor por defecto en el contrato.
> -        if (type(permanence_month) == bool and permanence_month == False) or (type(permanence_month) == int and permanence_month < 0) or permanence_month == None:
> -            contract_type_obj = self.pool.get('contract.type')
> +        if ((type(permanence_month) == bool and not permanence_month) or
> +                (type(permanence_month) == int and permanence_month < 0) or
> +                permanence_month is None):
> +            contract_type_obj = self.pool['contract.type']
>              t_ids = contract_type_obj.search(cr, uid, [('ref', '=', 'Basico')])

propagar context

>              t = contract_type_obj.browse(cr, uid, template_ids[0])

propagar context

>              permanence_month = t.permanence_month
> @@ -307,48 +332,56 @@
>          base_price = template.fixed_price - template.fixed_commission
>          fixed_price = data['price'] if data.get('price', 0) > base_price else base_price
>  
> -        contract_obj = self.pool.get('contract.contract')
> -        contract_id = contract_obj.create(cr, uid,
> -                                          {'contract_type_id': contract_type_id,
> -                                           'contract_date': time.strftime("%Y-%m-%d", time.localtime()),
> -                                           'customer_id': partner_id,
> -                                           'customer_address_id': address_id,
> -                                           'elevator_id': elevator_id,
> -                                           'elevator_address_id': address_obj.search(cr, uid, [('partner_id', '=', elevator_id), ('type', '=', 'default')])[0],
> -                                           'middleman_id': elevator_id,
> -                                           'customer_bank_id': bank_id,
> -                                           'payment_type': partner.payment_type_customer.id,
> -                                           'billing_cycle': partner.ciclo_cobro,
> -                                           'billing_cycle_type': partner.tipo_ciclo_cobro,
> -                                           'pre_paid': partner.pre_pago,
> -                                           'fixed_price': fixed_price,
> -                                           'differential_price': template.differential_price,
> -                                           'extra_cabin_price': template.extra_cabin_price,
> -                                           'fixed_commission': fixed_price - base_price,
> -                                           'fixed_link_price': template.fixed_link_price,
> -                                           'differential_link_price': template.differential_link_price,
> -                                           'user_id': elevator.user_id.id,
> -                                           'sale_group_sim_id': sale_group_sim_id,
> -                                           'sale_group_link_id': sale_group_link_id,
> -                                           'sale_group_pack_id': sale_group_pack_id,
> -                                           'permanence_month': permanence_month,
> -                                           'start_billing_days': template.start_billing_days,
> -                                           })
> -        contract = contract_obj.browse(cr, uid, contract_id)
> +        contract_obj = self.pool['contract.contract']
> +        contract_id = contract_obj.create(
> +            cr, uid, {'contract_type_id': contract_type_id,
> +                      'contract_date': time.strftime("%Y-%m-%d", time.localtime()),
> +                      'customer_id': partner_id,
> +                      'customer_address_id': address_id,

Esta línea se elimina.

> +                      'elevator_id': elevator_id,
> +                      'elevator_address_id': address_obj.search(cr, uid, [('partner_id', '=', elevator_id), ('type', '=', 'default')])[0],

Esta línea se elimina.

> +                      'middleman_id': elevator_id,
> +                      'customer_bank_id': bank_id,
> +                      'payment_type': partner.payment_type_customer.id,
> +                      'billing_cycle': partner.ciclo_cobro,
> +                      'billing_cycle_type': partner.tipo_ciclo_cobro,
> +                      'pre_paid': partner.pre_pago,
> +                      'fixed_price': fixed_price,
> +                      'differential_price': template.differential_price,
> +                      'extra_cabin_price': template.extra_cabin_price,
> +                      'fixed_commission': fixed_price - base_price,
> +                      'fixed_link_price': template.fixed_link_price,
> +                      'differential_link_price': template.differential_link_price,
> +                      'user_id': elevator.user_id.id,
> +                      'sale_group_sim_id': sale_group_sim_id,
> +                      'sale_group_link_id': sale_group_link_id,
> +                      'sale_group_pack_id': sale_group_pack_id,
> +                      'permanence_month': permanence_month,
> +                      'start_billing_days': template.start_billing_days,
> +                      }, context=context)
> +        contract = contract_obj.browse(cr, uid, contract_id, context=context)
>  
>          # Shipping costs
>          if contract_shipping_cost_ids is not False:
> -            shipping_cost_obj = self.pool.get('contract.shipping.cost')
> +            shipping_cost_obj = self.pool['contract.shipping.cost']
>              shipping_cost_obj.unlink(cr, uid, shipping_cost_obj.search(cr, uid, [('contract_id', '=', contract_id)]))

propagar context

>              for cost in contract_shipping_cost_ids:
>                  shipping_cost_obj.create(cr, uid, {'contract_id': contract_id, 'min_units': cost.min_units, 'max_units': cost.max_units, 'price': cost.price})

Propagar context y PEP8

>  
>          # Invoicing rules
> -        info_invoice_obj = self.pool.get('contract.info.invoice')
> +        info_invoice_obj = self.pool['contract.info.invoice']
>          if info_invoice_ids is not False:
> -            info_invoice_obj.unlink(cr, uid, info_invoice_obj.search(cr, uid, [('contract_id', '=', contract_id)]))
> +            info_invoice_obj.unlink(
> +                cr, uid, info_invoice_obj.search(
> +                    cr, uid, [('contract_id', '=', contract_id)],
> +                    context=context),
> +                context=context)
>              for info in info_invoice_ids:
> -                info_invoice_obj.create(cr, uid, {'contract_id': contract_id, 'categ_id': info.categ_id.id, 'receiver': info.receiver})
> +                info_invoice_obj.create(
> +                    cr, uid, {'contract_id': contract_id,
> +                              'categ_id': info.categ_id.id,
> +                              'receiver': info.receiver},
> +                    context=context)
>  
>          if data.get('invoicing_rules'):
>              for rule in data['invoicing_rules']:
> @@ -365,35 +398,67 @@
>                      receiver = 'cliente'
>  
>                  if categ_id and receiver:
> -                    if not info_invoice_obj.search(cr, uid, [('contract_id', '=', contract_id), ('categ_id', '=', categ_id), ('receiver', '=', receiver)]):
> -                        info_ids = info_invoice_obj.search(cr, uid, [('contract_id', '=', contract_id), ('categ_id', '=', categ_id)])
> +                    if not info_invoice_obj.search(
> +                            cr, uid, [('contract_id', '=', contract_id),
> +                                      ('categ_id', '=', categ_id),
> +                                      ('receiver', '=', receiver)],
> +                            context=context):
> +                        info_ids = info_invoice_obj.search(
> +                            cr, uid, [('contract_id', '=', contract_id),
> +                                      ('categ_id', '=', categ_id)],
> +                            context=context)
>                          if info_ids:
> -                            info_invoice_obj.write(cr, uid, info_ids, {'receiver': receiver})
> +                            info_invoice_obj.write(
> +                                cr, uid, info_ids, {'receiver': receiver},
> +                                context=context)
>                          else:
> -                            info_invoice_obj.create(cr, uid, {'contract_id': contract_id, 'categ_id': categ_id, 'receiver': receiver})
> +                            info_invoice_obj.create(
> +                                cr, uid, {'contract_id': contract_id,
> +                                          'categ_id': categ_id,
> +                                          'receiver': receiver},
> +                                context=context)
>  
>          # Price rules
>          if contract_template_prices_rules_ids is not False:
> -            contract_price_rules_obj = self.pool.get('contract.price.rules')
> -            contract_price_rules_obj.unlink(cr, uid, contract_price_rules_obj.search(cr, uid, [('contract_id', '=', contract_id)]))
> -            for template_price in contract_template_prices_rules_ids:
> -                contract_price_rules_obj.create(cr, uid, {'contract_id': contract_id, 'product_id': template_price.product_id.id, 'product_2_id': template_price.product_2_id.id, 'fixed_price': template_price.fixed_price, 'differential_price': template_price.differential_price, 'extra_cabin_price': template_price.extra_cabin_price, 'fixed_link_price': template_price.fixed_link_price, 'differential_link_price': template_price.differential_link_price, 'fixed_commission': template_price.fixed_commission, 'differential_commission': template_price.differential_commission})
> +            rules_obj = self.pool['contract.price.rules']
> +            rules_obj.unlink(cr, uid, rules_obj.search(
> +                cr, uid, [('contract_id', '=', contract_id)], context=context),
> +                context=context)
> +            for tmpl_price in contract_template_prices_rules_ids:
> +                rules_obj.create(
> +                    cr, uid, {'contract_id': contract_id,
> +                              'product_id': tmpl_price.product_id.id,
> +                              'product_2_id': tmpl_price.product_2_id.id,
> +                              'fixed_price': tmpl_price.fixed_price,
> +                              'differential_price': tmpl_price.differential_price,
> +                              'extra_cabin_price': tmpl_price.extra_cabin_price,
> +                              'fixed_link_price': tmpl_price.fixed_link_price,
> +                              'differential_link_price': tmpl_price.differential_link_price,
> +                              'fixed_commission': tmpl_price.fixed_commission,
> +                              'differential_commission': tmpl_price.differential_commission},
> +                    context=context)
>  
>          # Store document contract
> -        if data.get('document'):
> -            attach_obj = self.pool.get('ir.attachment')
> -            attach_obj.create(cr, uid, {'datas': data['document'], 'datas_fname': '%s.pdf' % contract_id, 'name': '%s.pdf' % contract_id, 'res_id': contract_id, 'res_model': 'contract.contract'})
> +        if data['document']:
> +            attach_obj = self.pool['ir.attachment']
> +            attach_obj.create(
> +                cr, uid, {'datas': data['document'],
> +                          'datas_fname': '%s.pdf' % contract_id,
> +                          'name': '%s.pdf' % contract_id,
> +                          'res_id': contract_id,
> +                          'res_model': 'contract.contract'},
> +                context=context)
>  
>          # Create a new sale order
> -        order_refs = self.create_order(cr, uid, {'order_id_72horas': data.get('order_id_72horas'),
> -                                                 'contract_id': contract.ref,
> -                                                 'branch': data.get('branch'),
> -                                                 'notes': data.get('notes'),
> -                                                 'lines': data['lines'],
> -                                                 })
> +        order_refs = self.create_order(
> +            cr, uid, {'order_id_72horas': data['order_id_72horas'],
> +                      'contract_id': contract.ref,
> +                      'branch': data['branch'],
> +                      'notes': data['notes'],
> +                      'lines': data['lines'],
> +                      }, context=context)
>          return order_refs
>  
> -
>      def _get_formatted_VAT(self, cr, uid, vat):
>          vat = vat.replace('-', '').strip()
>          if len(vat) != 9:
> @@ -402,18 +467,18 @@
>              vat = 'ES' + vat
>          return vat
>  
> -
>      def shipping_costs(self, cr, uid, ids, context=None):
> -        line_obj = self.pool.get('sale.order.line')
> -        acc_fp_obj = self.pool.get('account.fiscal.position')
> -        carrier_obj = self.pool.get('delivery.carrier')
> +        line_obj = self.pool['sale.order.line']
> +        acc_fp_obj = self.pool['account.fiscal.position']
> +        carrier_obj = self.pool['delivery.carrier']
>  
> -        carrier_ids = carrier_obj.search(cr, uid, [])
> +        carrier_ids = carrier_obj.search(cr, uid, [], context=context)
>          if not carrier_ids:
>              return False
> -        shipping_product = carrier_obj.browse(cr, uid, carrier_ids[0]).product_id
> +        shipping_product = carrier_obj.browse(
> +            cr, uid, carrier_ids[0]).product_id
>  
> -        for order in self.browse(cr, uid, ids):
> +        for order in self.browse(cr, uid, ids, context=context):
>              line_costs = None
>  
>              # Product quantity
> @@ -428,14 +493,17 @@
>              price = 0
>              found_ship_cost = False
>              for ship_cost in order.contract_id.contract_shipping_cost_ids:
> -                if ship_cost.min_units <= product_qty and ship_cost.max_units >= product_qty:
> +                if (ship_cost.min_units <= product_qty and
> +                        ship_cost.max_units >= product_qty):
>                      price = ship_cost.price
> -                    found_ship_cost=True
> +                    found_ship_cost = True
>  
>              if found_ship_cost:
>                  if line_costs:
>                      # Update shipping costs line
> -                    line_obj.write(cr, uid, [line_costs.id], {'price_unit': price})
> +                    line_obj.write(
> +                        cr, uid, [line_costs.id], {'price_unit': price},
> +                        context=context)
>                  else:
>                      # Add shipping costs line
>                      taxes = shipping_product.taxes_id
> @@ -444,26 +512,26 @@
>  
>                      receiver = False
>                      for info in order.contract_id.info_invoice_ids:
> -                        receiver = line_obj._find_receiver(shipping_product.categ_id, info)
> +                        receiver = line_obj._find_receiver(
> +                            shipping_product.categ_id, info)
>                          if receiver:
>                              break
>                      if not receiver:
>                          receiver = 'cliente'
>  
> -                    line_obj.create(cr, uid, {'order_id': order.id,
> -                                              'name': shipping_product.name,
> -                                              'product_uom_qty': 1,
> -                                              'product_uom': shipping_product.uom_id.id,
> -                                              'product_id': shipping_product.id,
> -                                              'price_unit': price,
> -                                              'receiver': receiver,
> -                                              'num_cabins': 0,
> -                                              'tax_id': [(6, 0, tax_ids)],
> -                                              'type': 'make_to_stock',
> -                                              'sequence': 30,
> -                                              })
> +                    line_obj.create(
> +                        cr, uid, {'order_id': order.id,
> +                                  'name': shipping_product.name,
> +                                  'product_uom_qty': 1,
> +                                  'product_uom': shipping_product.uom_id.id,
> +                                  'product_id': shipping_product.id,
> +                                  'price_unit': price,
> +                                  'receiver': receiver,
> +                                  'num_cabins': 0,
> +                                  'tax_id': [(6, 0, tax_ids)],
> +                                  'type': 'make_to_stock',
> +                                  'sequence': 30,
> +                                  }, context=context)
>              elif line_costs:
>                  # Remove shipping costs line
> -                line_obj.unlink(cr, uid, [line_costs.id])
> -
> -sale_order()
> +                line_obj.unlink(cr, uid, [line_costs.id], context=context)
> 
> === renamed file 'nayar_sales_extension/sale_group.py' => 'nayar_sales_extension/models/sale_group.py'
> --- nayar_sales_extension/sale_group.py	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/models/sale_group.py	2014-07-03 14:22:37 +0000
> @@ -19,58 +19,57 @@
>  #
>  ##############################################################################
>  
> -from osv import osv
> -import time
> -
> -
> -class sale_group(osv.osv):
> +from openerp.osv import orm
> +
> +
> +class SaleGroup(orm.Model):
>      _inherit = 'sale.group'
>  
>      def get_model(self, cr, uid, data):
>          """Return sale group models:
> -    contract_id: Contract
> -	"""
> +        contract_id: Contract
> +        """
>          # Contract and partner
> -        contract_obj = self.pool.get('contract.contract')
> -        contract_ids = contract_obj.search(cr, uid, [('ref', '=', data.get('contract_id'))])
> +        contract_obj = self.pool['contract.contract']
> +        contract_ids = contract_obj.search(cr, uid,
> +                                           [('ref', '=', data['contract_id'])])

Propagar context

>          if not contract_ids:
>              return ['No contract']
>  
>          contract = contract_obj.browse(cr, uid, contract_ids[0])

Propagar context

>  
> -	#Groups
> +        #Groups
>          sale_group = contract.sale_group_pack_id
> -	if not sale_group:
> -	    return ['No sale group']
> -	group_lines = sale_group.sale_group_line_ids
> +        if not sale_group:
> +            return ['No sale group']
> +        group_lines = sale_group.sale_group_line_ids
>          models = []
> -	for line in group_lines:
> -		desc = line.product_id.name
> -		desc = desc.split('(')[1].split('+')[0]
> -		models.append(desc)
> -	return list(set(models))
> +        for line in group_lines:
> +            desc = line.product_id.name
> +            desc = desc.split('(')[1].split('+')[0]
> +            models.append(desc)
> +        return list(set(models))
>  
>      def get_modelCP(self, cr, uid, data):
> -        """Return models 
> -    customer72h_id: 72horas ID from customer
> -	"""
> +        """Return models
> +        customer72h_id: 72horas ID from customer
> +        """
>          # Plantilla
> -        templates_obj = self.pool.get('contract.template')
> -        template_ids = templates_obj.search(cr, uid, [('partner_id.res_partner_h72_partner_ids.partner_id_72horas', '=', data.get('customer72h_id'))])
> -	if not template_ids:
> +        templates_obj = self.pool['contract.template']
> +        domain = [('partner_id.res_partner_h72_partner_ids.partner_id_72horas',
> +                   '=', data['customer72h_id'])]
> +        template_ids = templates_obj.search(cr, uid, domain)

Propagar context

> +        if not template_ids:
>              return ['No template']
>          template = templates_obj.browse(cr, uid, template_ids[0])
> -	#Groups
> +        #Groups
>          sale_group = template.sale_group_pack_id
> -	if not sale_group:
> -	    return ['No sale group']
> -	group_lines = sale_group.sale_group_line_ids
> +        if not sale_group:
> +            return ['No sale group']
> +        group_lines = sale_group.sale_group_line_ids
>          models = []
> -	for line in group_lines:
> -		desc = line.product_id.name
> -		desc = desc.split('(')[1].split('+')[0]
> -		models.append(desc)
> -	return list(set(models))
> -
> -       
> -sale_group()
> +        for line in group_lines:
> +            desc = line.product_id.name
> +            desc = desc.split('(')[1].split('+')[0]
> +            models.append(desc)
> +        return list(set(models))
> 
> === renamed file 'nayar_sales_extension/state.py' => 'nayar_sales_extension/models/state.py'
> --- nayar_sales_extension/state.py	2014-06-11 10:23:47 +0000
> +++ nayar_sales_extension/models/state.py	2014-07-03 14:22:37 +0000
> @@ -19,9 +19,10 @@
>  #
>  ##############################################################################
>  
> -from osv import osv
> -
> -class res_country_state(osv.osv):
> +from openerp.osv import orm
> +
> +
> +class ResCountryState(orm.Model):
>      _inherit = 'res.country.state'
>  
>      def search_by_name(self, cr, uid, name):
> @@ -38,5 +39,3 @@
>              if state_id:
>                  state_id = state_id[0]
>          return state_id
> -
> -res_country_state()
> 


-- 
https://code.launchpad.net/~oihanecruce/avanzosc/nayar_sales_extension/+merge/224980
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.