avanzosc team mailing list archive
-
avanzosc team
-
Mailing list archive
-
Message #00528
Re: [Merge] lp:~mikelarregi/avanzosc/nayar_h72_sync into lp:~avanzosc-security-team/avanzosc/72horas
Review: Needs Fixing code review
Algunos comentarios, incluidas las cuestiones sobre res.partner.address.
Diff comments:
> === modified file 'nayar_h72_sync/__init__.py'
> --- nayar_h72_sync/__init__.py 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/__init__.py 2014-07-02 12:39:12 +0000
> @@ -19,8 +19,4 @@
> #
> ##############################################################################
>
> -import h72_sync
> -import contract
> -import partner
> -import refund_products
> -import sale
> +import models
>
> === modified file 'nayar_h72_sync/__openerp__.py'
> --- nayar_h72_sync/__openerp__.py 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/__openerp__.py 2014-07-02 12:39:12 +0000
> @@ -28,9 +28,7 @@
> "website": "",
> "category": "Enterprise Specific Modules",
> "depends": ["base", "base_contact", "dos_contracts", "dos_refund_products"],
> - "init_xml": [],
> - "update_xml": ['h72_view.xml', 'partner_view.xml', 'sale_view.xml',
> + "data": ['views/h72_view.xml', 'views/partner_view.xml', 'views/sale_view.xml',
> 'security/ir.model.access.csv'],
> - "active": False,
> "installable": True
> }
>
> === added directory 'nayar_h72_sync/models'
> === added file 'nayar_h72_sync/models/__init__.py'
> --- nayar_h72_sync/models/__init__.py 1970-01-01 00:00:00 +0000
> +++ nayar_h72_sync/models/__init__.py 2014-07-02 12:39:12 +0000
> @@ -0,0 +1,26 @@
> +# -*- coding: utf-8 -*-
> +##############################################################################
> +#
> +# OpenERP, Open Source Management Solution
> +# Copyright (C) 2012-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 contract
> +from . import h72_sync
> +from . import partner
> +from . import refund_products
> +from . import sale
>
> === renamed file 'nayar_h72_sync/contract.py' => 'nayar_h72_sync/models/contract.py'
> --- nayar_h72_sync/contract.py 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/models/contract.py 2014-07-02 12:39:12 +0000
> @@ -19,21 +19,22 @@
> #
> ##############################################################################
>
> -from osv import osv
> -from osv import fields
> -
> -
> -class contract_annexe_h72(osv.osv):
> +from openerp.osv import orm, fields
> +
> +
> +class ContractAnnexeH72(orm.Model):
> _name = 'contract.annexe.h72'
> _description = 'Anexos que pasan a 72horas'
>
> _columns = {
> - 'annexe_id': fields.many2one('contract.annexe', 'Anexo', select=True, required=True),
> + 'annexe_id': fields.many2one('contract.annexe', 'Anexo', select=True,
> + required=True),
> 'phone': fields.char('Phone', size=20),
> 'num_cabins': fields.integer('Num. Cabins'),
> - 'partner_id': fields.many2one('res.partner', 'Partner', select=True, required=True),
> + 'partner_id': fields.many2one('res.partner', 'Partner', select=True,
> + required=True),
> 'customer_ref': fields.char('Customer Ref.', size=256),
> - 'annexe_date' : fields.date('Annexe Date', required=True),
> + 'annexe_date': fields.date('Annexe Date', required=True),
> 'profile_id': fields.many2one('h72.profile', 'Profile', select=True),
> 'partner_id_72horas': fields.integer('Partner 72horas'),
> 'operator': fields.char('Operador', size=64),
> @@ -44,23 +45,20 @@
> 'phone_from': fields.char('Phone', size=12),
> 'address': fields.char('Address', size=512),
> }
> -
> _default = {
> 'replacement': False,
> 'phone_from': False,
> }
>
> - def register(self, cr, uid, annexe_ids, replacement=False):
> - annexe_obj = self.pool.get('contract.annexe')
> + def register(self, cr, uid, annexe_ids, replacement=False, context=None):
> + annexe_obj = self.pool['contract.annexe']
> res = []
> -
> - for annexe in annexe_obj.browse(cr, uid, annexe_ids):
> + for annexe in annexe_obj.browse(cr, uid, annexe_ids, context=context):
> operator = False
> try:
> operator = annexe.product_id.default_code[4:].capitalize()
> except:
> pass
> -
> values = {
> 'annexe_id': annexe.id,
> 'phone': annexe.production_lot_id.telefono,
> @@ -72,23 +70,25 @@
> 'dirty': True,
> }
> if annexe.sale_order_id:
> + shipping = annexe.sale_order_id.partner_shipping_id
> values['profile_id'] = annexe.sale_order_id.profile_id.id
> - if annexe.sale_order_id.partner_shipping_id and annexe.sale_order_id.partner_shipping_id.partner_id_72horas and annexe.sale_order_id.partner_shipping_id.phones_to_72horas:
> - values['partner_id_72horas'] = annexe.sale_order_id.partner_shipping_id.partner_id_72horas
> + if (shipping and shipping.partner_id_72horas and
> + shipping.phones_to_72horas):
> + values['partner_id_72horas'] = shipping.partner_id_72horas
> else:
> - values['partner_id_72horas'] = annexe.sale_order_id.profile_id.partner_id_72horas
> + values['partner_id_72horas'] = (
> + annexe.sale_order_id.profile_id.partner_id_72horas)
> if annexe.product_2_id:
> values['track_type'] = annexe.product_2_id.name
> if replacement:
> values['replacement'] = True
> - values['phone_from'] = annexe.historical_ids[1].production_lot_id.telefono
> + values['phone_from'] = (
> + annexe.historical_ids[1].production_lot_id.telefono)
> if annexe.sale_order_id.address_to_72horas:
> - address = annexe.contract_id.customer_id.address and annexe.contract_id.customer_id.address[0]
> + address = (annexe.contract_id.customer_id.address and
Esto habría que cambiarlo directamente a customer_id
> + annexe.contract_id.customer_id.address[0])
> if address:
> - values['address'] = "%s (%s)" % (address.street, address.city)
> - res.append(self.create(cr, uid, values))
> -
> + values['address'] = ("%s (%s)" %
> + (address.street, address.city))
> + res.append(self.create(cr, uid, values, context=context))
> return res
> -
> -
> -contract_annexe_h72()
>
> === renamed file 'nayar_h72_sync/h72_sync.py' => 'nayar_h72_sync/models/h72_sync.py'
> --- nayar_h72_sync/h72_sync.py 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/models/h72_sync.py 2014-07-02 12:39:12 +0000
> @@ -22,14 +22,13 @@
> import datetime
> import platform
> import sys
> -from tools import config
> +from openerp.tools import config
> import traceback
> -
> import logging
> -from osv import osv
> -from osv import fields
> +from openerp.osv import orm, fields
> import time
>
> +
> def get_traceback(err_info):
> ty, val, tb = err_info
> ret = traceback.format_exception(ty, val, tb)
> @@ -37,21 +36,20 @@
> return "".join(ret)
>
>
> -class h72_profile(osv.osv):
> +class H72Profile(orm.Model):
> _name = 'h72.profile'
> _description = 'Perfiles 72horas'
> _columns = {
> 'profile_id': fields.integer('Id Perfil', required=True),
> 'name': fields.char('Nombre Perfil', size=255, required=True),
> - 'partner_id': fields.many2one('res.partner', 'Partner', select=True, required=True),
> + 'partner_id': fields.many2one('res.partner', 'Partner', select=True,
> + required=True),
> 'partner_id_72horas': fields.integer('Cliente 72horas', required=True),
> 'active': fields.boolean('Activo', required=True),
> }
>
> -h72_profile()
> -
> -
> -class h72_sync(osv.osv):
> +
> +class H72Sync(orm.Model):
> _name = 'h72.sync'
> _description = 'Sync 72horas'
>
> @@ -72,7 +70,7 @@
> elif annexe.track_type and "3bymesa" in annexe.track_type:
> model_id = 23
> return model_id
> -
> +
> def get_status(self, annexe):
> status_id = 4
> # Si es Magar lo guardamos como Desconectado
> @@ -80,18 +78,18 @@
> status_id = 999
> return status_id
>
> -
> def is_cp_annexe(self, annexe):
> # Miramos si el pedido es de un cliente particular
> - return (annexe.annexe_id.contract_id.customer_id.tipo_cliente == 'particular')
> -
> + return (annexe.annexe_id.contract_id.customer_id.tipo_cliente ==
> + 'particular')
>
> def get_cp_data(self, annexe):
> # Devuelve los datos del pedido de CP
> id_pedido = annexe.annexe_id.sale_order_id.order_id_72horas
> data = {}
> if id_pedido:
> - sql = "SELECT direccion, rae, codigo_mantenimiento FROM pedidos_cp WHERE id_pedido = %s"
> + sql = ("SELECT direccion, rae, codigo_mantenimiento "
Utiliza un browse o un read de ese id_pedido para obtener los datos y no te saltes el ORM para permisos y demás.
> + "FROM pedidos_cp WHERE id_pedido = %s")
> res = self.db_72horas.query(sql, id_pedido)
> if res:
> address, rae, ref = res[0]
> @@ -99,13 +97,13 @@
> data['ref'] = ref
> return data
>
> -
> def get_asc_data(self, annexe):
> # Devuelve los datos de una línea de pedido de ascensorista
> id_linea = annexe.annexe_id.stock_move_id.sale_line_id.line_id_72horas
> data = {}
> if id_linea:
> - sql = "SELECT direccion, referencia FROM pedidos_lineas l WHERE id_linea = %s"
> + sql = ("SELECT direccion, referencia "
> + "FROM pedidos_lineas l WHERE id_linea = %s")
Utiliza ORM, no SQL
> res = self.db_72horas.query(sql, id_linea)
> if res:
> address, ref = res[0]
> @@ -113,7 +111,6 @@
> data['ref'] = ref
> return data
>
> -
> def get_data_72horas(self, annexe):
> data = {}
> if self.is_cp_annexe(annexe):
> @@ -127,22 +124,19 @@
> }
> return data
>
> -
> - def update_phones(self, cr, uid):
> + def update_phones(self, cr, uid, context=None):
> self.logger.info("*** Alta de teléfonos GSM en 72horas ***")
> -
> - annexe_72horas_obj = self.pool.get('contract.annexe.h72')
> -
> + annexe_72horas_obj = self.pool['contract.annexe.h72']
> sql = ("INSERT INTO telefonos ("
> "n_telefono, fecha_alta, id_perfil, operador, tipo_enlace, "
> - "direccion, direccion_sintetica, codigo1, codigo2, proximo_test, id_cliente, id_modelo, "
> - "status, reprogramar, send_error, extension, ref_cliente, n_cabina) "
> + "direccion, direccion_sintetica, codigo1, codigo2, "
> + "proximo_test, id_cliente, id_modelo, status, reprogramar, "
> + "send_error, extension, ref_cliente, n_cabina) "
> "VALUES (" + ",".join(["%s"] * 18) + ")")
> -
> - for annexe_72horas in annexe_72horas_obj.search(cr, uid, [('dirty', '=', True)]):
> + for annexe_72horas in annexe_72horas_obj.search(
> + cr, uid, [('dirty', '=', True)]):
> annexe = annexe_72horas_obj.browse(cr, uid, annexe_72horas)
> error = None
> -
> try:
> if annexe.replacement:
> self.update_replacement(annexe)
> @@ -150,74 +144,82 @@
> if self.phone_exists(annexe.phone):
> error = "Ya existe"
> self.delete_phone(annexe.phone)
> -
> data_72horas = self.get_data_72horas(annexe)
> -
> - phone_72horas = (annexe.phone,)
> - phone_72horas += (str(annexe.annexe_date),)
> - phone_72horas += (annexe.profile_id.profile_id,)
> - phone_72horas += (annexe.operator,)
> - phone_72horas += (annexe.track_type,)
> - phone_72horas += (data_72horas['address'],)
> - phone_72horas += ("?",) # direccion_sintetica
> - phone_72horas += ("C",) # codigo1
> - phone_72horas += ("0000",) # codigo2
> - phone_72horas += (str(datetime.datetime.strptime(annexe.annexe_date, '%Y-%m-%d') + datetime.timedelta(days=15)),) # proximo_test
> - phone_72horas += (annexe.partner_id_72horas,) # id_cliente
> - phone_72horas += (self.get_model(annexe),) # id_modelo
> - phone_72horas += (self.get_status(annexe),) # id_status
> - #phone_72horas += (4,) # status
> - phone_72horas += ("Si",) # reprogramar
> - phone_72horas += ("",) # send_error
> - phone_72horas += ("",) # extension
> -
> + phone_72horas = "".join([
> + (annexe.phone,),
> + (str(annexe.annexe_date),),
> + (annexe.profile_id.profile_id,),
> + (annexe.operator,),
> + (annexe.track_type,),
> + (data_72horas['address'],),
> + ("?",), # direccion_sintetica
> + ("C",), # codigo1
> + ("0000",), # codigo2
> + (str(datetime.datetime.strptime(annexe.annexe_date,
> + '%Y-%m-%d') +
> + datetime.timedelta(days=15)),), # proximo_test
> + (annexe.partner_id_72horas,), # id_cliente
> + (self.get_model(annexe),), # id_modelo
> + (self.get_status(annexe),), # id_status
> + # phone_72horas += (4,) # status
> + ("Si",), # reprogramar
> + ("",), # send_error
> + ("",)]) # extension
> for num_cabin in xrange(annexe.num_cabins):
> if ":_:" in data_72horas['ref']:
> ref = data_72horas['ref'].split(":_:")[num_cabin]
> else:
> - ref = "?" if not annexe.customer_ref else annexe.customer_ref.encode('utf-8')
> - self.db_72horas.execute(sql, phone_72horas + (ref, num_cabin + 1))
> -
> + ref = ("?" if not annexe.customer_ref
> + else annexe.customer_ref.encode('utf-8'))
> + self.db_72horas.execute(sql, phone_72horas +
> + (ref, num_cabin + 1))
> self.update_order_line(annexe)
> -
> - annexe_72horas_obj.write(cr, uid, annexe_72horas, {'dirty': False, 'error': error})
> -
> - #Si hay error en la importación enviamos mail
> - if error:
> - self.email_to(cr, uid, "vanessa@xxxxxxxxxxx,narias@xxxxxxxxxxx", error, phone_72horas)
> - self.logger.info("%s: %s" % (annexe.phone, error if error else "Ok"))
> -
> + annexe_72horas_obj.write(cr, uid, annexe_72horas,
> + {'dirty': False, 'error': error},
> + context=context)
> + # Si hay error en la importación enviamos mail
> + if error:
> + self.email_to(
> + cr, uid, "vanessa@xxxxxxxxxxx,narias@xxxxxxxxxxx",
> + error, phone_72horas, context=context)
> + self.logger.info("%s: %s" % (annexe.phone, error or "Ok"))
> except Exception as ex:
> - annexe_72horas_obj.write(cr, uid, annexe_72horas, {'dirty': False, 'error': str(ex)})
> + annexe_72horas_obj.write(cr, uid, annexe_72horas,
> + {'dirty': False, 'error': str(ex)})
> self.logger.info("Error con %s:" % (annexe.phone,))
> self.logger.error(get_traceback(sys.exc_info()))
> - self.email_to(cr, uid, "vanessa@xxxxxxxxxxx", str(ex), annexe.phone)
> -
> + self.email_to(cr, uid, "vanessa@xxxxxxxxxxx", str(ex),
> + annexe.phone, context=context)
>
> def update_replacement(self, annexe):
> sql = ("UPDATE telefonos "
> "SET n_telefono = %s, operador = %s, tipo_enlace = %s "
> "WHERE n_telefono = %s")
> - data = (annexe.phone, annexe.operator, annexe.track_type, annexe.phone_from)
> + data = (annexe.phone, annexe.operator, annexe.track_type,
> + annexe.phone_from)
> return self.db_72horas.execute(sql, data)
>
> def update_order_line(self, annexe):
> id_linea = annexe.annexe_id.stock_move_id.sale_line_id.line_id_72horas
> if not self.is_cp_annexe(annexe) and id_linea:
> - sql = "UPDATE pedidos_lineas l SET l.n_telefono = %s , l.imei = %s, l.icc = %s WHERE id_linea = %s"
> - return self.db_72horas.execute(sql, (annexe.phone, annexe.annexe_id.production_lot_2_id.name, annexe.annexe_id.production_lot_id.name, id_linea))
> + sql = ("UPDATE pedidos_lineas l SET l.n_telefono = %s , "
> + "l.imei = %s, l.icc = %s WHERE id_linea = %s")
> + return self.db_72horas.execute(
> + sql, (annexe.phone, annexe.annexe_id.production_lot_2_id.name,
> + annexe.annexe_id.production_lot_id.name, id_linea))
> else:
> return 0
>
> - def update_profiles(self, cr, uid):
> + def update_profiles(self, cr, uid, context=None):
> self.logger.info("*** Traspaso de perfiles de 72horas a GSM ***")
> news = 0
> updates = 0
>
> - partner_72horas_obj = self.pool.get('res.partner.h72.partner')
> - address_obj = self.pool.get('res.partner.address')
> - profile_obj = self.pool.get('h72.profile')
> - profile_obj.write(cr, uid, profile_obj.search(cr, uid, []), {'active': False})
> + partner_72horas_obj = self.pool['res.partner.h72.partner']
> + address_obj = self.pool['res.partner.address']
> + profile_obj = self.pool['h72.profile']
> + profile_obj.write(cr, uid, profile_obj.search(cr, uid, []),
> + {'active': False}, context=context)
>
> sql = ("SELECT id_perfil, descripcion, id_cliente "
> "FROM perfiles "
> @@ -231,17 +233,26 @@
> raise Exception("No se han encontrado perfiles en 72horas")
>
> for profile_id, description, partner_id_72horas in profiles:
> - partner_ids = partner_72horas_obj.search(cr, uid, [('partner_id_72horas', '=', partner_id_72horas)])
> - partners = [p['partner_id'][0] for p in partner_72horas_obj.read(cr, uid, partner_ids, ['partner_id'])]
> - address_ids = address_obj.search(cr, uid, [('partner_id_72horas', '=', partner_id_72horas)])
> - partners.extend([a['partner_id'][0] for a in address_obj.read(cr, uid, address_ids, ['partner_id'])])
> + partner_ids = partner_72horas_obj.search(
> + cr, uid, [('partner_id_72horas', '=', partner_id_72horas)],
> + context=context)
> + partners = [p['partner_id'][0] for p in partner_72horas_obj.read(
> + cr, uid, partner_ids, ['partner_id'], context=context)]
> + address_ids = address_obj.search(
> + cr, uid, [('partner_id_72horas', '=', partner_id_72horas)],
> + context=context)
> + partners.extend([a['partner_id'][0] for a in address_obj.read(
> + cr, uid, address_ids, ['partner_id'])])
> for partner in set(partners):
> - p = profile_obj.search(cr, uid, [('profile_id', '=', profile_id),
> - ('partner_id_72horas', '=', partner_id_72horas),
> - ('partner_id', '=', partner),
> - ('active', '=', False)])
> + p = profile_obj.search(
> + cr, uid, [('profile_id', '=', profile_id),
> + ('partner_id_72horas', '=', partner_id_72horas),
> + ('partner_id', '=', partner),
> + ('active', '=', False)], context=context)
> if p:
> - profile_obj.write(cr, uid, p, {'name': description, 'active': True})
> + profile_obj.write(
> + cr, uid, p, {'name': description, 'active': True},
> + context=context)
> updates += 1
> else:
> data = {
> @@ -253,87 +264,79 @@
> }
> profile_obj.create(cr, uid, data)
> news += 1
> -
> self.logger.info("%s nuevos, %s actualizados" % (news, updates))
>
> - def update_annexes(self, cr, uid):
> + def update_annexes(self, cr, uid, context=context):
> self.logger.info("*** Actualización de anexos ***")
> -
> sql = ("SELECT n_telefono, COUNT(*) "
> "FROM telefonos "
> "GROUP BY n_telefono")
> -
> telefonos = self.db_72horas.query(sql)
> if not telefonos:
> raise Exception("No se han encontrado teléfonos en 72horas")
> telefonos = [(t.strip(), n) for t, n in telefonos]
> telefonos = dict(telefonos)
> -
> - annexe_obj = self.pool.get('contract.annexe')
> - annexe_ids = annexe_obj.search(cr, uid, [('active_annexe', '=', True)])
> - annexes = annexe_obj.read(cr, uid, annexe_ids, ['production_lot_id', 'num_cabins'])
> -
> - lot_obj = self.pool.get('stock.production.lot')
> + annexe_obj = self.pool['contract.annexe']
> + annexe_ids = annexe_obj.search(cr, uid, [('active_annexe', '=', True)],
> + context=context)
> + annexes = annexe_obj.read(cr, uid, annexe_ids,
> + ['production_lot_id', 'num_cabins'],
> + context=context)
> + lot_obj = self.pool['stock.production.lot']
> for annexe in annexes:
> - telefono = lot_obj.read(cr, uid, annexe['production_lot_id'][0], ['telefono'])['telefono']
> + telefono = lot_obj.read(cr, uid, annexe['production_lot_id'][0],
> + ['telefono'], context=context)['telefono']
> num_cabins = telefonos.get(telefono, 0)
> if num_cabins > 0 and annexe['num_cabins'] != num_cabins:
> - annexe_obj.write(cr, uid, [annexe['id']], {'num_cabins': num_cabins})
> + annexe_obj.write(cr, uid, [annexe['id']],
> + {'num_cabins': num_cabins}, context=context)
> self.logger.info("%s: %s cabinas" % (telefono, num_cabins))
>
> - def email_to(self, cr, uid, to, error, phone, check_node=True):
> + def email_to(self, cr, uid, to, error, phone, check_node=True,
> + context=None):
> """ Envia información de errores por correo electrónico. """
> -
> - smtp_obj = self.pool.get('email.smtpclient')
> - smtpserver_id = smtp_obj.search(cr, uid, [('type', '=', 'default'), ('state', '=', 'confirm'), ('active', '=', True)])
> + smtp_obj = self.pool['email.smtpclient']
> + smtpserver_id = smtp_obj.search(
> + cr, uid, [('type', '=', 'default'), ('state', '=', 'confirm'),
> + ('active', '=', True)], context=context)
> if smtpserver_id:
> smtpserver_id = smtpserver_id[0]
> else:
> logger = logging.getLogger('seur.logistica')
> logger.error('No SMTP Server has been defined!')
> -
> -
> - subject = "Error en la sincro con 72horas - " + time.strftime("%d/%m/%Y - %H:%M:%S", time.localtime())
> + subject = ("Error en la sincro con 72horas - " +
> + time.strftime("%d/%m/%Y - %H:%M:%S", time.localtime()))
> text = ""
> text += "%s - %s <br \>" % (error, phone)
> state = smtp_obj.send_email(cr, uid, smtpserver_id, to, subject, text)
> return state
>
> -
> -
> - def run_process(self, cr, uid, processes=[]):
> - if platform.node() != config.get('prod_host') or cr.dbname != config.get('prod_db'):
> + def run_process(self, cr, uid, processes=[], context=None):
> + if (platform.node() !=
> + config.get('prod_host') or cr.dbname != config.get('prod_db')):
> return False
> -
> self.logger = logging.getLogger('h72.sync')
> self.logger.info("*** Sincronización con 72horas ***")
> -
> - self.db_72horas = self.pool.get('mysql.connect')
> + self.db_72horas = self.pool['mysql.connect']
> self.db_72horas.open_connection(cr, uid)
> -
> # Dar de alta teléfonos nuevos en 72horas
> if 'update_phones' in processes:
> try:
> self.update_phones(cr, uid)
> except:
> self.logger.error(get_traceback(sys.exc_info()))
> -
> # Actualizar perfiles que se usarán en la preparación de pedidos
> if 'update_profiles' in processes:
> try:
> - self.update_profiles(cr, uid)
> + self.update_profiles(cr, uid, context=context)
> except:
> self.logger.error(get_traceback(sys.exc_info()))
> -
> # Actualizar información de anexos con los datos de 72horas
> if 'update_annexes' in processes:
> try:
> - self.update_annexes(cr, uid)
> + self.update_annexes(cr, uid, context=context)
> except:
> self.logger.error(get_traceback(sys.exc_info()))
> -
> self.db_72horas.close_connection()
> self.logger.info("*** Fin sincronización ***")
> return True
> -
> -h72_sync()
>
> === renamed file 'nayar_h72_sync/h72_sync.py.orig' => 'nayar_h72_sync/models/h72_sync.py.orig'
> === renamed file 'nayar_h72_sync/partner.py' => 'nayar_h72_sync/models/partner.py'
> --- nayar_h72_sync/partner.py 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/models/partner.py 2014-07-02 12:39:12 +0000
> @@ -19,27 +19,27 @@
> #
> ##############################################################################
>
> -from osv import osv
> -from osv import fields
> -
> -
> -class res_partner_h72_partner(osv.osv):
> +from openerp import orm, fields
> +
> +
> +class ResPartnerH72Partner(orm.Model):
> _name = 'res.partner.h72.partner'
> _description = 'Clientes 72horas'
> _columns = {
> - 'partner_id': fields.many2one('res.partner', 'Partner', select=True, required=True),
> + 'partner_id': fields.many2one('res.partner', 'Partner', select=True,
> + required=True),
> 'partner_id_72horas': fields.integer('Cliente 72horas', required=True),
> 'phones_to_72horas': fields.boolean('Alta Telefonos'),
> }
>
> -res_partner_h72_partner()
> -
> -
> -class res_partner(osv.osv):
> +
> +class ResPartner(orm.Model):
> _name = 'res.partner'
> _inherit = 'res.partner'
> _columns = {
> - 'res_partner_h72_partner_ids': fields.one2many('res.partner.h72.partner', 'partner_id', 'Cliente 72horas'),
> + 'res_partner_h72_partner_ids':
> + fields.one2many('res.partner.h72.partner', 'partner_id',
> + 'Cliente 72horas'),
> 'address_to_72horas': fields.boolean('Usar dirección'),
> }
> _defaults = {
> @@ -47,10 +47,8 @@
> 'address_to_72horas': False,
> }
>
> -res_partner()
> -
> -
> -class res_partner_address(osv.osv):
> +
> +class ResPartnerAddress(orm.Model):
> _inherit = 'res.partner.address'
> _columns = {
> 'partner_id_72horas': fields.integer('Cliente 72horas'),
> @@ -61,5 +59,3 @@
> 'phones_to_72horas': True,
> 'address_to_72horas': False,
> }
> -
> -res_partner_address()
>
> === renamed file 'nayar_h72_sync/refund_products.py' => 'nayar_h72_sync/models/refund_products.py'
> --- nayar_h72_sync/refund_products.py 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/models/refund_products.py 2014-07-02 12:39:12 +0000
> @@ -19,27 +19,28 @@
> #
> ##############################################################################
>
> -from osv import osv
> -from osv import fields
> -
> -
> -class refund_products(osv.osv):
> +from openerp import orm, fields
> +
> +
> +class RefundProducts(orm.Model):
> _inherit = 'refund.products'
>
> def button_done(self, cr, uid, ids, context=None):
> - annexe_obj = self.pool.get('contract.annexe')
> - annexe_72horas_obj = self.pool.get('contract.annexe.h72')
> - res = super(refund_products, self).button_done(cr, uid, ids, context=context)
> -
> - refund = self.browse(cr, uid, ids)
> + annexe_obj = self.pool['contract.annexe']
> + annexe_72horas_obj = self.pool['contract.annexe.h72']
> + res = super(RefundProducts, self).button_done(cr, uid, ids,
> + context=context)
> + refund = self.browse(cr, uid, ids, context=context)
> for r in refund:
> for p in r.refund_product_ids:
> - annexe_ids = annexe_obj.search(cr, uid, [('active_annexe', '=', True), ('closing_date', '=', False),
> - '|', ('pack_production_lot_id', '=', p.prodlot_id.id),
> - '|', ('production_lot_id', '=', p.prodlot_id.id),
> - ('production_lot_2_id', '=', p.prodlot_id.id)])
> - annexe_72horas_obj.register(cr, uid, annexe_ids, replacement=True)
> -
> + annexe_ids = annexe_obj.search(
> + cr, uid, [('active_annexe', '=', True),
> + ('closing_date', '=', False),
> + '|', ('pack_production_lot_id', '=',
> + p.prodlot_id.id),
> + '|', ('production_lot_id', '=',
> + p.prodlot_id.id),
> + ('production_lot_2_id', '=', p.prodlot_id.id)])
> + annexe_72horas_obj.register(cr, uid, annexe_ids,
> + replacement=True)
> return res
> -
> -refund_products()
>
> === renamed file 'nayar_h72_sync/sale.py' => 'nayar_h72_sync/models/sale.py'
> --- nayar_h72_sync/sale.py 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/models/sale.py 2014-07-02 12:39:12 +0000
> @@ -19,124 +19,156 @@
> #
> ##############################################################################
>
> -from osv import osv
> -from osv import fields
> -
> -
> -class sale_order(osv.osv):
> +from openerp import orm, fields
> +
> +
> +class SaleOrder(orm.Model):
> _inherit = 'sale.order'
> _columns = {
> - 'save_to_72horas': fields.boolean('Grabar en 72horas', readonly=True, states={'draft': [('readonly', False)]}),
> - 'profile_id': fields.many2one('h72.profile', 'Profile', readonly=True, states={'draft': [('readonly', False)]}, select=True),
> - 'address_to_72horas': fields.boolean('Usar dirección', readonly=True, states={'draft': [('readonly', False)]}),
> + 'save_to_72horas':
> + fields.boolean('Grabar en 72horas', readonly=True,
> + states={'draft': [('readonly', False)]}),
> + 'profile_id':
> + fields.many2one('h72.profile', 'Profile', readonly=True,
> + states={'draft': [('readonly', False)]},
> + select=True),
> + 'address_to_72horas':
> + fields.boolean('Usar dirección', readonly=True,
> + states={'draft': [('readonly', False)]}),
> 'order_id_72horas': fields.char('Pedido 72horas', size=64),
> }
>
> def action_ship_end(self, cr, uid, ids, context=None):
> - res = super(sale_order, self).action_ship_end(cr, uid, ids, context=context)
> - annexe_obj = self.pool.get('contract.annexe')
> - annexe_72horas_obj = self.pool.get('contract.annexe.h72')
> + res = super(SaleOrder, self).action_ship_end(cr, uid, ids,
> + context=context)
> + annexe_obj = self.pool['contract.annexe']
> + annexe_72horas_obj = self.pool['contract.annexe.h72']
> for order in self.browse(cr, uid, ids, context={}):
> if order.save_to_72horas and order.profile_id:
> - annexe_72horas_obj.register(cr, uid, annexe_obj.search(cr, uid, [('sale_order_id', '=', order.id)]))
> - return res
> -
> - def onchange_partner_id(self, cr, uid, ids, part):
> - res = super(sale_order, self).onchange_partner_id(cr, uid, ids, part)
> - profiles = False
> - if 'elevator_partner_id' in res['value'] and res['value']['elevator_partner_id']:
> - profile_obj = self.pool.get('h72.profile')
> - address_to_72horas = False
> - partner = self.pool.get('res.partner').browse(cr, uid, res['value']['elevator_partner_id'])
> -
> - if 'partner_shipping_id' in res['value'] and res['value']['partner_shipping_id']:
> - address = self.pool.get('res.partner.address').browse(cr, uid, res['value']['partner_shipping_id'])
> - profiles = profile_obj.search(cr, uid, [('partner_id', '=', partner.id),
> - ('partner_id_72horas', '=', address.partner_id_72horas),
> - ('active', '=', True)])
> - address_to_72horas = address.address_to_72horas
> -
> - if not profiles:
> - partner_ids_72horas = [p.partner_id_72horas for p in partner.res_partner_h72_partner_ids]
> - profiles = profile_obj.search(cr, uid, [('partner_id', '=', partner.id),
> - ('partner_id_72horas', 'in', partner_ids_72horas),
> - ('active', '=', True)])
> - address_to_72horas = partner.address_to_72horas
> -
> - if profiles:
> - if not 'domain' in res:
> - res['domain'] = {}
> - res['domain']['profile_id'] = [('partner_id', '=', partner.id)]
> - res['value']['save_to_72horas'] = True
> - res['value']['profile_id'] = profiles[0]
> - res['value']['address_to_72horas'] = address_to_72horas
> - else:
> - res['value']['save_to_72horas'] = False
> - res['value']['profile_id'] = False
> - res['value']['address_to_72horas'] = False
> -
> - return res
> -
> - def onchange_contract_id(self, cr, uid, ids, contract):
> - res = super(sale_order, self).onchange_contract_id(cr, uid, ids, contract)
> - profiles = False
> - if 'elevator_partner_id' in res['value'] and res['value']['elevator_partner_id']:
> - profile_obj = self.pool.get('h72.profile')
> - address_to_72horas = False
> - partner = self.pool.get('res.partner').browse(cr, uid, res['value']['elevator_partner_id'])
> -
> - if 'partner_shipping_id' in res['value'] and res['value']['partner_shipping_id']:
> - address = self.pool.get('res.partner.address').browse(cr, uid, res['value']['partner_shipping_id'])
> - profiles = profile_obj.search(cr, uid, [('partner_id', '=', partner.id),
> - ('partner_id_72horas', '=', address.partner_id_72horas),
> - ('active', '=', True)])
> - address_to_72horas = address.address_to_72horas
> -
> - if not profiles:
> - partner_ids_72horas = [p.partner_id_72horas for p in partner.res_partner_h72_partner_ids]
> - profiles = profile_obj.search(cr, uid, [('partner_id', '=', partner.id),
> - ('partner_id_72horas', 'in', partner_ids_72horas),
> - ('active', '=', True)])
> - address_to_72horas = partner.address_to_72horas
> -
> - if profiles:
> - if not 'domain' in res:
> - res['domain'] = {}
> - res['domain']['profile_id'] = [('partner_id', '=', partner.id)]
> - res['value']['save_to_72horas'] = True
> - res['value']['profile_id'] = profiles[0]
> - res['value']['address_to_72horas'] = address_to_72horas
> - else:
> - res['value']['save_to_72horas'] = False
> - res['value']['profile_id'] = False
> - res['value']['address_to_72horas'] = False
> -
> - return res
> -
> - def onchange_partner_shipping_id(self, cr, uid, ids, partner_shipping_id):
> - res = super(sale_order, self).onchange_partner_shipping_id(cr, uid, ids, partner_shipping_id)
> + annexe_72horas_obj.register(cr, uid, annexe_obj.search(
> + cr, uid, [('sale_order_id', '=', order.id)],
> + context=context), context=context)
> + return res
> +
> + def onchange_partner_id(self, cr, uid, ids, part, context=None):
> + res = super(SaleOrder, self).onchange_partner_id(cr, uid, ids, part,
> + context=context)
> + profiles = False
> + if ('elevator_partner_id' in res['value'] and
> + res['value']['elevator_partner_id']):
> + profile_obj = self.pool['h72.profile']
> + address_to_72horas = False
> + partner = self.pool['res.partner'].browse(
> + cr, uid, res['value']['elevator_partner_id'], context=context)
> + if ('partner_shipping_id' in res['value'] and
> + res['value']['partner_shipping_id']):
> + address = self.pool.get('res.partner.address').browse(
> + cr, uid, res['value']['partner_shipping_id'],
> + context=context)
> + profiles = profile_obj.search(
> + cr, uid, [('partner_id', '=', partner.id),
> + ('partner_id_72horas', '=',
> + address.partner_id_72horas),
> + ('active', '=', True)], context=context)
> + address_to_72horas = address.address_to_72horas
> + if not profiles:
> + partner_ids_72horas = [
> + p.partner_id_72horas
> + for p in partner.res_partner_h72_partner_ids]
> + profiles = profile_obj.search(
> + cr, uid, [('partner_id', '=', partner.id),
> + ('partner_id_72horas', 'in',
> + partner_ids_72horas),
> + ('active', '=', True)])
> + address_to_72horas = partner.address_to_72horas
> + if profiles:
> + if 'domain' not in res:
> + res['domain'] = {}
> + res['domain']['profile_id'] = [('partner_id', '=', partner.id)]
> + res['value']['save_to_72horas'] = True
> + res['value']['profile_id'] = profiles[0]
> + res['value']['address_to_72horas'] = address_to_72horas
> + else:
> + res['value']['save_to_72horas'] = False
> + res['value']['profile_id'] = False
> + res['value']['address_to_72horas'] = False
> + return res
> +
> + def onchange_contract_id(self, cr, uid, ids, contract, context=None):
> + res = super(SaleOrder, self).onchange_contract_id(
> + cr, uid, ids, contract, context=context)
> + profiles = False
> + if ('elevator_partner_id' in res['value'] and
> + res['value']['elevator_partner_id']):
> + profile_obj = self.pool['h72.profile']
> + address_to_72horas = False
> + partner = self.pool['res.partner'].browse(
> + cr, uid, res['value']['elevator_partner_id'], context=context)
> + if ('partner_shipping_id' in res['value'] and
> + res['value']['partner_shipping_id']):
> + address = self.pool['res.partner.address'].browse(
Sustituir por res.partner en lugar de res.partner.address
> + cr, uid, res['value']['partner_shipping_id'],
> + context=context)
> + profiles = profile_obj.search(
> + cr, uid, [('partner_id', '=', partner.id),
> + ('partner_id_72horas', '=',
> + address.partner_id_72horas),
> + ('active', '=', True)])
> + address_to_72horas = address.address_to_72horas
> + if not profiles:
> + partner_ids_72horas = [
> + p.partner_id_72horas
> + for p in partner.res_partner_h72_partner_ids]
> + profiles = profile_obj.search(
> + cr, uid, [('partner_id', '=', partner.id),
> + ('partner_id_72horas', 'in',
> + partner_ids_72horas),
> + ('active', '=', True)], context=context)
> + address_to_72horas = partner.address_to_72horas
> + if profiles:
> + if 'domain' not in res:
> + res['domain'] = {}
> + res['domain']['profile_id'] = [('partner_id', '=', partner.id)]
> + res['value']['save_to_72horas'] = True
> + res['value']['profile_id'] = profiles[0]
> + res['value']['address_to_72horas'] = address_to_72horas
> + else:
> + res['value']['save_to_72horas'] = False
> + res['value']['profile_id'] = False
> + res['value']['address_to_72horas'] = False
> + return res
> +
> + def onchange_partner_shipping_id(self, cr, uid, ids,
> + partner_shipping_id, context=None):
> + res = super(SaleOrder, self).onchange_partner_shipping_id(
> + cr, uid, ids, partner_shipping_id, context=context)
> profiles = False
> address_to_72horas = False
> -
> if partner_shipping_id:
> - profile_obj = self.pool.get('h72.profile')
> - address = self.pool.get('res.partner.address').browse(cr, uid, partner_shipping_id)
> - profiles = profile_obj.search(cr, uid, [('partner_id', '=', address.partner_id.id),
> - ('partner_id_72horas', '=', address.partner_id_72horas),
> - ('active', '=', True)])
> + profile_obj = self.pool['h72.profile']
> + address = self.pool.get('res.partner.address').browse(
Sustituir por res.partner
> + cr, uid, partner_shipping_id, context=context)
> + profiles = profile_obj.search(
> + cr, uid, [('partner_id', '=', address.partner_id.id),
> + ('partner_id_72horas', '=',
> + address.partner_id_72horas),
> + ('active', '=', True)], context=context)
> address_to_72horas = address.address_to_72horas
> -
> if not profiles:
> - partner_ids_72horas = [p.partner_id_72horas for p in address.partner_id.res_partner_h72_partner_ids]
> - profiles = profile_obj.search(cr, uid, [('partner_id', '=', address.partner_id.id),
> - ('partner_id_72horas', 'in', partner_ids_72horas),
> - ('active', '=', True)])
> + partner_ids_72horas = [
> + p.partner_id_72horas
> + for p in address.partner_id.res_partner_h72_partner_ids]
> + profiles = profile_obj.search(
> + cr, uid, [('partner_id', '=', address.partner_id.id),
> + ('partner_id_72horas', 'in',
> + partner_ids_72horas),
> + ('active', '=', True)])
> address_to_72horas = address.partner_id.address_to_72horas
> -
> if profiles:
> - if not 'domain' in res:
> + if 'domain' not in res:
> res['domain'] = {}
> - res['domain']['profile_id'] = [('partner_id', '=', address.partner_id.id)]
> + res['domain']['profile_id'] = [('partner_id', '=',
> + address.partner_id.id)]
> res['value']['save_to_72horas'] = True
> res['value']['profile_id'] = profiles[0]
> res['value']['address_to_72horas'] = address_to_72horas
> @@ -144,16 +176,11 @@
> res['value']['save_to_72horas'] = False
> res['value']['profile_id'] = False
> res['value']['address_to_72horas'] = False
> -
> return res
>
> -sale_order()
> -
> -
> -class sale_order_line(osv.osv):
> +
> +class SaleOrderLine(orm.Model):
> _inherit = 'sale.order.line'
> _columns = {
> 'line_id_72horas': fields.char('Línea 72horas', size=64),
> }
> -
> -sale_order_line()
>
> === added directory 'nayar_h72_sync/views'
> === renamed file 'nayar_h72_sync/h72_view.xml' => 'nayar_h72_sync/views/h72_view.xml'
> --- nayar_h72_sync/h72_view.xml 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/views/h72_view.xml 2014-07-02 12:39:12 +0000
> @@ -5,7 +5,6 @@
> <record id="view_h72_profile_search" model="ir.ui.view">
> <field name="name">view.h72.profile.search</field>
> <field name="model">h72.profile</field>
> - <field name="type">search</field>
> <field name="arch" type="xml">
> <search string="Search Profiles">
> <filter icon="terp-check" name="active_filter" string="Active" domain="[('active', '=', True)]" />
>
> === renamed file 'nayar_h72_sync/partner_view.xml' => 'nayar_h72_sync/views/partner_view.xml'
> --- nayar_h72_sync/partner_view.xml 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/views/partner_view.xml 2014-07-02 12:39:12 +0000
> @@ -7,7 +7,6 @@
> <field name="model">res.partner</field>
> <field name="inherit_id" ref="base.view_partner_form"/>
> <field name="priority">1</field>
> - <field name="type">form</field>
> <field name="arch" type="xml">
> <page string="Notes" position="after">
> <page string="72horas">
> @@ -26,7 +25,6 @@
> <field name="model">res.partner</field>
> <field name="inherit_id" ref="base_contact.view_partner_form_inherit"/>
> <field name="priority">1</field>
> - <field name="type">form</field>
> <field name="arch" type="xml">
> <field name="email" widget="email" position="after">
> <separator string="72horas" colspan="2" col="2" />
> @@ -43,7 +41,6 @@
> <field name="model">res.partner.address</field>
> <field name="inherit_id" ref="base.view_partner_address_form1" />
> <field name="priority">1</field>
> - <field name="type">form</field>
> <field name="arch" type="xml">
> <form string="Address">
> <group colspan="2" col="2">
> @@ -60,7 +57,6 @@
> <record id="view_partner_h72_partner_tree" model="ir.ui.view">
> <field name="name">view.partner.h72.partner.tree</field>
> <field name="model">res.partner.h72.partner</field>
> - <field name="type">tree</field>
> <field name="priority">1</field>
> <field name="arch" type="xml">
> <tree string="Clientes 72horas">
> @@ -75,7 +71,6 @@
> <field name="name">view.partner.h72.partner.form</field>
> <field name="model">res.partner.h72.partner</field>
> <field name="priority">1</field>
> - <field name="type">form</field>
> <field name="arch" type="xml">
> <form string="Cliente 72horas">
> <group colspan="2" col="2">
>
> === renamed file 'nayar_h72_sync/sale_view.xml' => 'nayar_h72_sync/views/sale_view.xml'
> --- nayar_h72_sync/sale_view.xml 2014-06-11 10:23:47 +0000
> +++ nayar_h72_sync/views/sale_view.xml 2014-07-02 12:39:12 +0000
> @@ -7,7 +7,6 @@
> <field name="model">sale.order</field>
> <field name="inherit_id" ref="sale.view_order_form"/>
> <field name="priority">1</field>
> - <field name="type">form</field>
> <field name="arch" type="xml">
> <page string="Sales Order" position="after">
> <page string="72horas">
>
--
https://code.launchpad.net/~mikelarregi/avanzosc/nayar_h72_sync/+merge/225314
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.
References