avanzosc team mailing list archive
-
avanzosc team
-
Mailing list archive
-
Message #00469
Re: [Merge] lp:~mikelarregi/avanzosc/72horas into lp:~avanzosc-security-team/avanzosc/72horas
Review: Needs Fixing code review
Comentarios inline.
Diff comments:
> === modified file 'dos_account_invoice_report/__init__.py'
> --- dos_account_invoice_report/__init__.py 2014-06-11 10:23:47 +0000
> +++ dos_account_invoice_report/__init__.py 2014-06-13 12:10:28 +0000
> @@ -1,5 +1,5 @@
> ##############################################################################
> -#
> +#
> # OpenERP, Open Source Management Solution
> # Copyright (C) 2004-2012 DOS (<http://www.dos-sl.es>).
> #
> @@ -14,11 +14,10 @@
> # 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/>.
> +# along with this program. If not, see <http://www.gnu.org/licenses/>
> #
> ##############################################################################
>
> -import report
> +from . import report
>
> # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> -
>
> === modified file 'dos_account_invoice_report/__openerp__.py'
> --- dos_account_invoice_report/__openerp__.py 2014-06-11 10:23:47 +0000
> +++ dos_account_invoice_report/__openerp__.py 2014-06-13 12:10:28 +0000
> @@ -19,20 +19,19 @@
> ##############################################################################
>
> {
> - "name" : "DOS Account Invoice Report",
> - "version" : "1.1",
> - "author" : "DOS",
> - "category" : "Enterprise Specific Modules",
> - "description":"""Module to print account invoice with custom format.
> - """,
> - "depends" : ["account"],
> - "init_xml" : [],
> - "demo_xml" : [],
> - "update_xml" : [
> - 'account_invoice_report.xml',
> - ],
> - "website": 'http://www.dos-sl.es',
> - "active": False,
> - "installable": True,
> + "name": "DOS Account Invoice Report",
> + "version": "1.1",
> + "author": "DOS",
> + "category": "Enterprise Specific Modules",
> + "description": """Module to print account invoice with custom format.
> + """,
> + "depends": ["account"],
> + "demo": [],
> + "data": [
> + 'views/account_invoice_report.xml',
> + ],
> + "website": 'http://www.dos-sl.es',
> + "active": False,
active ya no es una clave válida (ahora es auto_install, que no hace la misma función tampoco). Mejor quitarla
> + "installable": True,
> }
> # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
>
> === modified file 'dos_account_invoice_report/report/__init__.py'
> --- dos_account_invoice_report/report/__init__.py 2014-06-11 10:23:47 +0000
> +++ dos_account_invoice_report/report/__init__.py 2014-06-13 12:10:28 +0000
> @@ -1,5 +1,5 @@
> ##############################################################################
> -#
> +#
> # OpenERP, Open Source Management Solution
> # Copyright (C) 2004-2012 DOS (<http://www.dos-sl.es>).
> #
> @@ -14,11 +14,9 @@
> # 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/>.
> +# along with this program. If not, see <http://www.gnu.org/licenses/>.
> #
> ##############################################################################
>
> -import account_invoice
> -
> +from . import account_invoice
> # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
> -
>
> === modified file 'dos_account_invoice_report/report/account_invoice.py'
> --- dos_account_invoice_report/report/account_invoice.py 2014-06-11 10:23:47 +0000
> +++ dos_account_invoice_report/report/account_invoice.py 2014-06-13 12:10:28 +0000
> @@ -22,15 +22,17 @@
> import time
> from datetime import datetime
> from dateutil.relativedelta import relativedelta
> -from report import report_sxw
> -from osv import osv
> -from tools.bank import format_acc_number
> -from tools.translate import _
> -import pooler
> -
> -class account_invoice_custom(report_sxw.rml_parse):
> +from openerp.report import report_sxw
> +from openerp.osv import orm
> +from openerp.tools.bank import format_acc_number
> +from openerp.tools.translate import _
> +from . import pooler
El pooler no está en el módulo, sino en el espacio de nombres openerp. Entonces sería from openerp import pooler, pero no creo que haga falta utilizarlo para nada
> +
> +
> +class AccountInvoiceCustom(report_sxw.rml_parse):
> def __init__(self, cr, uid, name, context):
> - super(account_invoice_custom, self).__init__(cr, uid, name, context=context)
> + super(AccountInvoiceCustom,
> + self).__init__(cr, uid, name, context=context)
> self.localcontext.update({
> 'time': time,
> 'get_left_text': self.get_left_text,
> @@ -56,92 +58,85 @@
> 'get_lines_per_page': self.get_lines_per_page,
> })
> self.context = context
> - user = self.pool.get('res.users').browse(cr, uid, uid)
> + user = self.pool['res.users'].browse(cr, uid, uid)
> self.company = user.company_id
> -
> - def get_invoice_date (self, invoice):
> +
> + def get_invoice_date(self, invoice):
> invoice_date = ""
> -
> if str(invoice.date_invoice) != '':
> invoice_date = datetime.strptime(invoice.date_invoice, '%Y-%m-%d')
> invoice_date = invoice_date.strftime('%d/%m/%Y')
> -
> return invoice_date
> -
> +
> def get_invoice_refund(self, invoice):
> if invoice.type == "out_refund" or invoice.type == "in_refund":
> number = '-'
> str_date = '-'
> if len(invoice.origin_invoices_ids) > 0:
> - number =len(invoice.origin_invoices_ids) > 0 and invoice.origin_invoices_ids[0].number or '-'
> + number = (len(invoice.origin_invoices_ids) > 0 and
(len(invoice.origin_invoices_ids) > 0 puede ser simplemente invoice.origin_invoices_ids, ya que eso se evalúa como True si tiene elementos.
> + invoice.origin_invoices_ids[0].number or '-')
> if str(invoice.origin_invoices_ids[0].date_invoice) != '':
> - invoice_date = datetime.strptime(invoice.origin_invoices_ids[0].date_invoice, '%Y-%m-%d')
> - str_date = invoice_date.strftime('%d-%m-%Y')
> -
> + date_inv = invoice.origin_invoices_ids[0].date_invoice
> + invoice_date = datetime.strptime(date_inv, '%Y-%m-%d')
> + str_date = invoice_date.strftime('%d-%m-%Y')
> return number + ' (' + str_date + ')'
> else:
> return None
> -
> +
> def get_left_text(self, invoice):
> -
> text = ""
> -
> company = invoice.company_id or self.company or None
> -
> if company and company.partner_id:
> -
> partner = company.partner_id
> -
> # Nombre empresa
> - #text += partner.name or ""
> + # text += partner.name or ""
> # CIF
> - #text += partner.vat and (" - " + partner.vat) or ""
> + # text += partner.vat and (" - " + partner.vat) or ""
> # Tomo
> - text += partner.es_tomo and ("" + _("RM Tomo") + " " + partner.es_tomo) or ""
> + text += partner.es_tomo and ("" + _("RM Tomo") + " " +
> + partner.es_tomo) or ""
> # Libro
> - text += partner.es_libro and (" " + _("Libro") + " " + partner.es_libro) or ""
> + text += partner.es_libro and (" " + _("Libro") + " " +
> + partner.es_libro) or ""
> # Folio
> - text += partner.es_folio and (" " + _("Folio") + " " + partner.es_folio) or ""
> + text += partner.es_folio and (" " + _("Folio") + " " +
> + partner.es_folio) or ""
> # Hoja
> - text += partner.es_hoja and (" " + _("Hoja") + " " + partner.es_hoja) or ""
> + text += partner.es_hoja and (" " + _("Hoja") +
> + " " + partner.es_hoja) or ""
> # Inscripcion
> - text += partner.es_registro_mercantil and (" " + _("Inscripción") + " " + partner.es_registro_mercantil) or ""
> + reg_merc = partner.es_registro_mercantil
> + text += partner.es_registro_mercantil and (" " + _("Inscripción") +
> + " " + reg_merc) or ""
> # Final
> - text += "."
> + text += "."
>
> return text
>
> def get_partner_name(self, invoice):
> -
> text = ""
> company = invoice.company_id or self.company or None
> -
> if company and company.partner_id:
> -
> partner = company.partner_id
> -
> # Nombre empresa
> text += partner.name or ""
> # CIF
> text += partner.vat and (" - " + partner.vat) or ""
> return text
> -
> -
> +
> def get_footer_text(self, invoice):
> -
> text = ""
> -
> company = invoice.company_id or self.company or None
> -
> if company and company.partner_id:
> -
> + partner_obj = self.pool.get('res.partner')
Utiliza self.pool[] en lugar de lo otro
> + addr_obj = self.pool.get('res.partner.address')
Este objeto ya no existe. Todo son res.partner. Tendrás que modificar el código para adecuarlo a este nuevo modelo de datos.
> partner = company.partner_id
> - addr_ids = self.pool.get('res.partner').address_get(self.cr, self.uid, [partner.id], ['default'])
> + addr_ids = partner_obj.address_get(self.cr, self.uid,
> + [partner.id], ['default'])
> addr_id = addr_ids['default']
> - addr = self.pool.get('res.partner.address').browse(self.cr, self.uid, addr_id)
> -
> + addr = addr_obj.browse(self.cr, self.uid, addr_id)
Propaga el context.
> # Nombre empresa
> - #text += partner and partner.name or ""
> + # text += partner and partner.name or ""
> # Calle empresa
> text += addr and addr.street and ("" + addr.street + ".") or ""
> # Codigo Postal empresa
> @@ -149,351 +144,362 @@
> # Ciudad
> text += addr and addr.city and (" " + addr.city) or ""
> # Telefono
> - text += addr and addr.phone and (" - " + _("Tel.") + " " + addr.phone) or ""
> + text += addr and addr.phone and (" - " + _("Tel.") +
> + " " + addr.phone) or ""
> # Fax
> - text += addr and addr.fax and (" - " + _("Fax.") + " " + addr.fax) or ""
> + text += addr and addr.fax and (" - " +
> + _("Fax.") + " " + addr.fax) or ""
> # Email
> - text += addr and addr.email and (" - " + _("E-Mail") + " " + addr.email) or ""
> -
> + text += addr and addr.email and (" - " + _("E-Mail") +
> + " " + addr.email) or ""
> return text
> -
> - def get_company_address (self, invoice):
> -
> +
> + def get_company_address(self, invoice):
> res = []
> -
> company = invoice.company_id or self.company or None
> -
> if company and company.partner_id:
> -
> partner = company.partner_id
> - addr_ids = self.pool.get('res.partner').address_get(self.cr, self.uid, [partner.id], ['default'])
> + partner_obj = self.pool.get('res.partner')
self.pool[]
> + addr_obj = self.pool.get('res.partner.address')
No existe ya
> + addr_ids = partner_obj.address_get(self.cr, self.uid,
> + [partner.id], ['default'])
> addr_id = addr_ids['default']
> - addr = self.pool.get('res.partner.address').browse(self.cr, self.uid, addr_id)
> -
> + addr = addr_obj.browse(self.cr, self.uid, addr_id)
propaga el context
> res.append(partner and partner.name or "")
> res.append((addr and addr.street) or '')
> - res.append((addr and addr.zip or '') + " - " + (addr and addr.city or ''))
> - res.append((addr and addr.state_id and addr.state_id.name or '') + " (" + (addr and addr.country_id and addr.country_id.name or '') + ")")
> + res.append((addr and addr.zip or '') + " - " +
> + (addr and addr.city or ''))
> + res.append((addr and addr.state_id and addr.state_id.name or '') +
> + " (" + (addr and addr.country_id and
> + addr.country_id.name or '') + ")")
> res.append(partner and partner.vat or '')
> -
> else:
> -
> - res.append(" ")
> - res.append(" ")
> - res.append(" ")
> - res.append(" ")
> - res.append(" ")
> -
> + res.append(" ")
Mejor hacer un bucle
for i in range(5):
res.append(" ")
> + res.append(" ")
> + res.append(" ")
> + res.append(" ")
> + res.append(" ")
> return res
> -
> - def get_customer_address (self, invoice):
> -
> +
> + def get_customer_address(self, invoice):
> res = []
> -
> partner = invoice.partner_id
> - addr_ids = self.pool.get('res.partner').address_get(self.cr, self.uid, [partner.id], ['default'])
> + partner_obj = self.pool.get('res.partner')
self.pool[]
> + addr_obj = self.pool.get('res.partner.address')
Cambiar modelo de direcciones
> + addr_ids = partner_obj.address_get(self.cr, self.uid,
> + [partner.id], ['default'])
> addr_id = addr_ids['default']
> - addr = self.pool.get('res.partner.address').browse(self.cr, self.uid, addr_id)
> -
> + addr = addr_obj.browse(self.cr, self.uid, addr_id)
> res.append((addr and addr.street) or '')
> - res.append((addr and addr.zip or '') + " - " + (addr and addr.city or ''))
> - res.append((addr and addr.state_id and addr.state_id.name or '') + " (" + (addr and addr.country_id and addr.country_id.name or '') + ")")
> + res.append((addr and addr.zip or '') + " - " +
> + (addr and addr.city or ''))
> + res.append((addr and addr.state_id and addr.state_id.name or '') +
> + " (" + (addr and addr.country_id and
> + addr.country_id.name or '') + ")")
> + return res
>
> - return res
> -
> - def get_elevator_address (self, invoice):
> -
> + def get_elevator_address(self, invoice):
> res = []
> -
> if invoice.elevator_partner_id:
> -
> partner = invoice.elevator_partner_id
> - addr_ids = self.pool.get('res.partner').address_get(self.cr, self.uid, [partner.id], ['default'])
> + partner_obj = self.pool.get('res.partner')
self.pool
> + addr_obj = self.pool.get('res.partner.address')
Modelo eliminado
> + addr_ids = partner_obj.address_get(self.cr, self.uid,
> + [partner.id], ['default'])
> addr_id = addr_ids['default']
> - addr = self.pool.get('res.partner.address').browse(self.cr, self.uid, addr_id)
> -
> + addr = addr_obj.browse(self.cr, self.uid, addr_id)
propaga context
> res.append(partner and partner.name or "")
> res.append((addr and addr.street) or '')
> - res.append((addr and addr.zip or '') + " - " + (addr and addr.city or ''))
> - res.append((addr and addr.state_id and addr.state_id.name or '') + " (" + (addr and addr.country_id and addr.country_id.name or '') + ")")
> + res.append((addr and addr.zip or '') + " - " +
> + (addr and addr.city or ''))
> + res.append((addr and addr.state_id and addr.state_id.name or '') +
> + " (" + (addr and addr.country_id and
> + addr.country_id.name or '') + ")")
> res.append(partner and partner.vat or '')
> -
> elif invoice.partner_id:
> -
> partner = invoice.partner_id
> addr = invoice.address_invoice_id
> -
> res.append(partner and partner.name or "")
> res.append((addr and addr.street) or '')
> - res.append((addr and addr.zip or '') + " - " + (addr and addr.city or ''))
> - res.append((addr and addr.state_id and addr.state_id.name or '') + " (" + (addr and addr.country_id and addr.country_id.name or '') + ")")
> + res.append((addr and addr.zip or '') + " - " +
> + (addr and addr.city or ''))
> + res.append((addr and addr.state_id and addr.state_id.name or '') +
> + " (" + (addr and addr.country_id and
> + addr.country_id.name or '') + ")")
> res.append(partner and partner.vat or '')
> -
> else:
> -
> - res.append(" ")
> - res.append(" ")
> - res.append(" ")
> - res.append(" ")
> - res.append(" ")
> -
> + res.append(" ")
Pon bucle
> + res.append(" ")
> + res.append(" ")
> + res.append(" ")
> + res.append(" ")
> return res
> -
> -
> +
> def get_payment_type(self, invoice):
> -
> return invoice.payment_type and invoice.payment_type.name.upper() or ''
> -
> -
> +
> def get_payment_term(self, invoice):
> -
> if invoice.date_due:
> date_due = datetime.strptime(invoice.date_due, '%Y-%m-%d')
> str_date = date_due.strftime('%d/%m/%Y')
> else:
> date_invoice = datetime.strptime(invoice.date_invoice, '%Y-%m-%d')
> - str_date = date_invoice.strftime('%d/%m/%Y')
> -
> + str_date = date_invoice.strftime('%d/%m/%Y')
> return str_date
>
> -
> def get_account_number(self, invoice):
> -
> bank_text = ""
> -
> - if invoice.payment_type and invoice.payment_type.code in ('TRANSF', 'T/T', 'TRANSFERENCIA_CSB', 'CNF'):
> -
> - if invoice.type in ("in_invoice", "out_invoice"):
> -
> - # Cuenta bancaria de la empresa
> - if self.company.partner_id:
> - partner_id = self.company.partner_id.id
> -
> - pool = pooler.get_pool(self.cr.dbname)
> - bank_obj = pool.get('res.partner.bank')
> - bank_ids = bank_obj.search(self.cr, self.uid, [('partner_id','=', partner_id)], limit=1, order='default_bank desc')
> -
> - for bank in bank_obj.browse(self.cr, self.uid, bank_ids):
> - bank_text = format_acc_number(bank.iban or bank.acc_number or "")
> -
> - else: # ("out_refund", "in_refund")
> -
> - # Cuenta bancaria del cliente
> - if invoice.partner_bank_id:
> - bank_text = format_acc_number(invoice.partner_bank_id.iban or invoice.partner_bank_id.acc_number or "", masked=True)
> -
> - elif invoice.payment_type and invoice.payment_type.code in ('RECIBO', 'RECIBO_CSB', 'pain.008.001.02'):
> - if invoice.type in ("in_invoice", "out_invoice"):
> - # Cuenta bancaria del cliente
> - if invoice.partner_bank_id:
> - bank_text = format_acc_number(invoice.partner_bank_id.iban or invoice.partner_bank_id.acc_number or "", masked=True)
> - else: # ("out_refund", "in_refund")
> -
> - # Cuenta bancaria de la empresa
> - if self.company.partner_id:
> - partner_id = self.company.partner_id.id
> -
> - pool = pooler.get_pool(self.cr.dbname)
> - bank_obj = pool.get('res.partner.bank')
> - bank_ids = bank_obj.search(self.cr, self.uid, [('partner_id','=', partner_id)], limit=1, order='default_bank desc')
> -
> - for bank in bank_obj.browse(self.cr, self.uid, bank_ids):
> - bank_text = format_acc_number(bank.iban or bank.acc_number or "")
> -
> + pay_type('TRANSF', 'T/T', 'TRANSFERENCIA_CSB', 'CNF')
> + if invoice.payment_type and invoice.payment_type.code in pay_type:
> + if invoice.type in ("in_invoice", "out_invoice"):
> + # Cuenta bancaria de la empresa
> + if self.company.partner_id:
> + partner_id = self.company.partner_id.id
> + pool = pooler.get_pool(self.cr.dbname)
> + bank_obj = pool.get('res.partner.bank')
> + bank_ids = bank_obj.search(self.cr, self.uid,
> + [('partner_id', '=',
> + partner_id)],
> + limit=1,
> + order='default_bank desc')
> + for bank in bank_obj.browse(self.cr, self.uid, bank_ids):
> + bank_text = format_acc_number(bank.iban or
> + bank.acc_number or "")
> + else: # ("out_refund", "in_refund")
> + # Cuenta bancaria del cliente
> + if invoice.partner_bank_id:
> + acc_number = invoice.partner_bank_id.acc_number
> + bank_text = format_acc_number(invoice.partner_bank_id.iban
> + or acc_number or "",
> + masked=True)
> + elif (invoice.payment_type and
> + invoice.payment_type.code in
> + ('RECIBO', 'RECIBO_CSB', 'pain.008.001.02')):
> + if invoice.type in ("in_invoice", "out_invoice"):
> + # Cuenta bancaria del cliente
> + if invoice.partner_bank_id:
> + acc_number = invoice.partner_bank_id.acc_number
> + bank_text = format_acc_number(invoice.partner_bank_id.iban
> + or acc_number or "",
> + masked=True)
> + else: # ("out_refund", "in_refund")
> + # Cuenta bancaria de la empresa
> + if self.company.partner_id:
> + partner_id = self.company.partner_id.id
> + pool = pooler.get_pool(self.cr.dbname)
> + bank_obj = pool.get('res.partner.bank')
> + bank_ids = bank_obj.search(self.cr, self.uid,
> + [('partner_id', '=',
> + partner_id)], limit=1,
> + order='default_bank desc')
> + for bank in bank_obj.browse(self.cr, self.uid, bank_ids):
> + bank_text = format_acc_number(bank.iban or
> + bank.acc_number or "")
> return bank_text
>
> -
> def get_invoice_lines(self, invoice):
> product_obj = self.pool.get('product.product')
> -
> res = []
> -
> contracts = {}
> links = {}
> shippings = {}
> others = {}
> -
> max_lines_first, max_lines = self.get_lines_per_page()
> -
> sign = 1.0
> if invoice.type == "out_refund" or invoice.type == "in_refund":
> sign = -1.0
> -
> count = 0
> -
> for l in invoice.invoice_line:
> # Lineas de teléfono
> - if l.contract_id and l.product_id and product_obj._is_sim(l.product_id.categ_id):
> + if (l.contract_id and l.product_id and
> + product_obj._is_sim(l.product_id.categ_id)):
> if l.contract_id.id in contracts:
> - contracts[l.contract_id.id]['uds'] = contracts[l.contract_id.id]['uds'] + int(l.quantity or 0)
> - contracts[l.contract_id.id]['price'] = contracts[l.contract_id.id]['price'] + (l.price_subtotal or 0)
> + contracts_uds = contracts[l.contract_id.id]['uds']
> + contracts_price = contracts[l.contract_id.id]['price']
> + contracts[l.contract_id.id]['uds'] = (contracts_uds +
> + int(l.quantity or 0))
> + contracts[l.contract_id.id]['price'] = (contracts_price +
> + (l.price_subtotal
> + or 0))
> else:
> - contracts[l.contract_id.id] = {'uds': int(l.quantity or 0),
> - 'price': l.price_subtotal or 0,
> - 'ref': l.contract_id.ref or "",
> - 'type': l.contract_id and l.contract_id.contract_type_id and l.contract_id.contract_type_id.name or " - "}
> -
> + uds = int(l.quantity or 0)
> + price = l.price_subtotal or 0
> + ref = l.contract_id.ref or ""
> + type = (l.contract_id and l.contract_id.contract_type_id
> + and l.contract_id.contract_type_id.name or " - ")
> + contracts[l.contract_id.id] = {'uds': uds,
> + 'price': price,
> + 'ref': ref,
> + 'type': type,
> + }
> # Gastos de envío
> - elif l.product_id and product_obj._is_shipping_cost(l.product_id.categ_id):
> - if l.product_id.id in shippings and shippings[l.product_id.id]['price'] == (l.price_unit or 0) and shippings[l.product_id.id]['dto'] == (l.discount or 0):
> - shippings[l.product_id.id]['uds'] = shippings[l.product_id.id]['uds'] + int(l.quantity or 0)
> - shippings[l.product_id.id]['import'] = shippings[l.product_id.id]['import'] + (l.price_subtotal or 0)
> + elif (l.product_id and
> + product_obj._is_shipping_cost(l.product_id.categ_id)):
> + if (l.product_id.id in shippings and
> + shippings[l.product_id.id]['price'] == (l.price_unit or 0)
> + and shippings[l.product_id.id]['dto'] == (l.discount
> + or 0)):
> + shippings[l.product_id.id]['uds'] += int(l.quantity or 0)
> + shippings[l.product_id.id]['import'] += (l.price_subtotal
> + or 0)
> else:
> - shippings[l.product_id.id] = {'concept': l.product_id and l.product_id.name or " ",
> - 'uds': int(l.quantity or 0),
> + shippings[l.product_id.id] = {'concept': (l.product_id and
> + l.product_id.name
> + or " "),
> + 'uds': int(l.quantity or 0),
> 'price': l.price_unit or 0,
> - 'dto': l.discount or 0,
> - 'import': l.price_subtotal or 0}
> -
> + 'dto': l.discount or 0,
> + 'import': (l.price_subtotal
> + or 0)}
> # Enlaces, repuestos u otros tipos de producto
> elif l.product_id:
> - if (l.product_id.id,l.price_unit,l.discount) in links:
> - links[(l.product_id.id,l.price_unit,l.discount)]['uds'] = links[(l.product_id.id,l.price_unit,l.discount)]['uds'] + int(l.quantity or 0)
> - links[(l.product_id.id,l.price_unit,l.discount)]['import'] = links[(l.product_id.id,l.price_unit,l.discount)]['import'] + (l.price_subtotal or 0)
> + if (l.product_id.id, l.price_unit, l.discount) in links:
> + links[(l.product_id.id, l.price_unit,
> + l.discount)]['uds'] += int(l.quantity or 0)
> + links[(l.product_id.id, l.price_unit,
> + l.discount)]['import'] += (l.price_subtotal or 0)
> else:
> - links[(l.product_id.id,l.price_unit,l.discount)] = {
> - 'uds': int(l.quantity or 0),
> + links[(l.product_id.id, l.price_unit, l.discount)] = {
> + 'uds': int(l.quantity or 0),
> 'price': l.price_unit or 0,
> - 'dto': l.discount or 0,
> + 'dto': l.discount or 0,
> 'import': l.price_subtotal or 0,
> 'concept': l.product_id and l.product_id.name or " ",
> }
> -
> # Resto de líneas (texto libre)
> else:
> others[l.id] = {'concept': l.name or " ",
> - 'uds': int(l.quantity or 0),
> + 'uds': int(l.quantity or 0),
> 'price': l.price_unit or 0,
> - 'dto': l.discount or 0,
> - 'import': l.price_subtotal or 0}
> -
> -
> + 'dto': l.discount or 0,
> + 'import': l.price_subtotal or 0}
> # Diccionario final
> # -------------------------------------------
> -
> - # Lineas de teléfono
> + # Lineas de teléfono
> for contract_id in contracts:
> line = {}
> -
> - uds = contracts[contract_id]['uds'] > 1 and str(contracts[contract_id]['uds']) + _(" Líneas Móvil") or str(contracts[contract_id]['uds']) + _(" Línea Móvil")
> -
> - concept = _("Contrato ") + contracts[contract_id]['ref'] + " - " + uds + " (" + contracts[contract_id]['type'] + ")"
> -
> + uds = (contracts[contract_id]['uds'] > 1 and
> + str(contracts[contract_id]['uds']) + _(" Líneas Móvil") or
> + str(contracts[contract_id]['uds']) + _(" Línea Móvil"))
> + concept = (_("Contrato ") + contracts[contract_id]['ref'] + " - " +
> + uds + " (" + contracts[contract_id]['type'] + ")")
> line["concept"] = concept
> line["uds"] = 1
> line["price"] = contracts[contract_id]['price'] * sign or 0
> line["dto"] = 0
> - line["import"] = contracts[contract_id]['price'] * sign or 0
> - line["header"] = (count == 0) or (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> - line["pagebreak"] = (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> -
> + line["import"] = contracts[contract_id]['price'] * sign or 0
> + line["header"] = ((count == 0) or (count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> + line["pagebreak"] = ((count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> res.append(line)
> -
> count += 1
> -
> - # Enlaces
> + # Enlaces
> for link_id in links:
> line = {}
> -
> line["concept"] = links[link_id]['concept']
> line["uds"] = links[link_id]['uds']
> line["price"] = links[link_id]['price'] * sign or 0
> line["dto"] = links[link_id]['dto']
> line["import"] = links[link_id]['import'] * sign or 0
> - line["header"] = (count == 0) or (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> - line["pagebreak"] = (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> -
> + line["header"] = ((count == 0) or (count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> + line["pagebreak"] = ((count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> res.append(line)
> -
> count += 1
> -
> # Gastos de envío
> for shipping_id in shippings:
> line = {}
> -
> line["concept"] = shippings[shipping_id]['concept']
> line["uds"] = shippings[shipping_id]['uds']
> line["price"] = shippings[shipping_id]['price'] * sign or 0
> line["dto"] = shippings[shipping_id]['dto']
> line["import"] = shippings[shipping_id]['import'] * sign or 0
> - line["header"] = (count == 0) or (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> - line["pagebreak"] = (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> -
> + line["header"] = ((count == 0) or (count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> + line["pagebreak"] = ((count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> res.append(line)
> -
> - count += 1
> -
> + count += 1
> # Resto
> for other_id in others:
> line = {}
> -
> line["concept"] = others[other_id]['concept']
> line["uds"] = others[other_id]['uds']
> line["price"] = others[other_id]['price'] * sign or 0
> line["dto"] = others[other_id]['dto']
> line["import"] = others[other_id]['import'] * sign or 0
> - line["header"] = (count == 0) or (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> - line["pagebreak"] = (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0)
> -
> + line["header"] = ((count == 0) or (count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> + line["pagebreak"] = ((count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0))
> res.append(line)
> -
> - count += 1
> -
> + count += 1
> return res
> -
> - def get_phone_lines (self, invoice):
> -
> +
> + def get_phone_lines(self, invoice):
> product_obj = self.pool.get('product.product')
> -
> res = []
> -
> sign = 1.0
> if invoice.type == "out_refund" or invoice.type == "in_refund":
> sign = -1.0
> -
> count = 0
> max_lines = 36
> -
> # Teléfonos
> for l in invoice.invoice_line:
> - if l.contract_annexe_id and l.product_id and product_obj._is_sim(l.product_id.categ_id):
> + if (l.contract_annexe_id and l.product_id and
> + product_obj._is_sim(l.product_id.categ_id)):
> line = {}
> -
> link_model = ""
> str_annexe_date = ""
> str_start_date = ""
> str_end_date = ""
> num_cabins = l.num_cabins or 0
> price_month = 0
> -
> - # El campo modelo de enlace, se rellena únicamente cuando el contrato es de tipo integral
> - if l.contract_id and l.contract_id.contract_type_id and l.contract_id.contract_type_id.ref == 'Integral':
> - link = l.contract_annexe_id.production_lot_2_id and l.contract_annexe_id.production_lot_2_id.product_id.name or ''
> + # El campo modelo de enlace, se rellena únicamente
> + # cuando el contrato es de tipo integral
> + if (l.contract_id and l.contract_id.contract_type_id and
> + l.contract_id.contract_type_id.ref == 'Integral'):
> + lot_2_id = l.contract_annexe_id.production_lot_2_id
> + link = (lot_2_id and lot_2_id.product_id.name or '')
> link_model = link.replace('Enlace ', '')
> - link_model = len(link_model) > 10 and link_model[0:10] or link_model
> -
> + link_model = (len(link_model) > 10 and link_model[0:10] or
> + link_model)
> if str(l.contract_annexe_id.annexe_date) != '':
> - annexe_date = datetime.strptime(l.contract_annexe_id.annexe_date, '%Y-%m-%d')
> + str_annexe_date = l.contract_annexe_id.annexe_date
> + annexe_date = datetime.strptime(str_annexe_date,
> + '%Y-%m-%d')
> str_annexe_date = annexe_date.strftime('%d/%m/%Y')
> -
> if str(l.start_date) != '':
> start_date = datetime.strptime(l.start_date, '%Y-%m-%d')
> str_start_date = start_date.strftime('%d/%m/%Y')
> -
> if str(l.end_date) != '':
> end_date = datetime.strptime(l.end_date, '%Y-%m-%d')
> str_end_date = end_date.strftime('%d/%m/%Y')
> -
> - price_cabins = num_cabins > 1 and ((num_cabins - 1) * (l.contract_annexe_id.extra_cabin_price or 0)) or 0
> - price_month = (l.contract_annexe_id.fixed_price or 0) + price_cabins
> - price_month = price_month - (price_month * (l.contract_annexe_id.differential_price or 0) / 100.0)
> -
> + price_cabins = (num_cabins > 1
> + and ((num_cabins - 1)
> + * (l.contract_annexe_id.extra_cabin_price
> + or 0)) or 0)
> + price_month = ((l.contract_annexe_id.fixed_price or 0) +
> + price_cabins)
> + price_month = (price_month -
> + (price_month *
> + (l.contract_annexe_id.differential_price or 0)
> + / 100.0))
> ref = l.contract_annexe_id.customer_ref or l.customer_ref or ''
> ref = len(ref) > 12 and ref[:11] + '...' or ref
> -
> -
> -
> - line['phone'] = l.contract_annexe_id.production_lot_id and l.contract_annexe_id.production_lot_id.telefono or ''
> + phone = (l.contract_annexe_id.production_lot_id and
> + l.contract_annexe_id.production_lot_id.telefono or '')
> + line['phone'] = phone
> line["link"] = link_model
> line["start_contract"] = str_annexe_date
> line["num_cabins"] = num_cabins
> @@ -502,185 +508,154 @@
> line["months"] = l.months or 0
> line["price_month"] = price_month * sign or 0
> line["ref"] = ref
> - line["total"] = l.price_subtotal * sign or 0 #(l.months or 0) * price_month
> -
> + line["total"] = l.price_subtotal * sign or 0
> + # (l.months or 0) * price_month
> res.append(line)
> -
> # Ordenamos array por telefono
> - res = sorted(res, key=lambda k: k['phone'])
> -
> + res = sorted(res, key=lambda k: k['phone'])
> # Añadimos cabeceras
> result = []
> -
> for line in res:
> - line["header"] = (count%max_lines == 0) and 1 or 0
> + line["header"] = (count % max_lines == 0) and 1 or 0
> line["count"] = count
> result.append(line)
> - count += 1
> -
> + count += 1
> return result
> -
> -
> - def get_phone_lines_totals (self, invoice):
> -
> +
> + def get_phone_lines_totals(self, invoice):
> product_obj = self.pool.get('product.product')
> -
> totals = {}
> -
> sign = 1.0
> if invoice.type == "out_refund" or invoice.type == "in_refund":
> sign = -1.0
> -
> phone = link = num_cabins = months = total = 0
> -
> # Teléfonos
> for l in invoice.invoice_line:
> - if l.contract_annexe_id and l.product_id and product_obj._is_sim(l.product_id.categ_id):
> + if (l.contract_annexe_id and l.product_id and
> + product_obj._is_sim(l.product_id.categ_id)):
> phone += 1
> # Solo sumamos enlaces que pertenzca a un contrato Integral
> - link += l.contract_id and l.contract_id.contract_type_id and (l.contract_id.contract_type_id.ref == 'Integral') and l.contract_annexe_id.production_lot_2_id and 1 or 0
> + link += (l.contract_id and l.contract_id.contract_type_id and
> + (l.contract_id.contract_type_id.ref == 'Integral') and
> + l.contract_annexe_id.production_lot_2_id and 1 or 0)
> num_cabins += l.num_cabins or 0
> months += l.months or 0
> total += l.price_subtotal or 0
> -
> totals['phone'] = phone
> totals["link"] = link
> totals["num_cabins"] = num_cabins
> totals["months"] = months
> totals["total"] = total * sign or 0
> -
> return [totals]
> -
> -
> +
> def get_picking_info_line(self, line):
> -
> if line and line.stock_move_id and line.stock_move_id.picking_id:
> -
> picking = line.stock_move_id.picking_id
> -
> picking_date = datetime.strptime(picking.date[0:10], '%Y-%m-%d')
> str_picking_date = picking_date.strftime('%d/%m/%Y')
> - picking_info = _("Albarán") + " " + picking.name + " (" + str_picking_date + ")"
> + picking_info = _("Albarán") + " " + picking.name + " "
> + "(" + str_picking_date + ")"
Indentación incorrecta y no significa lo mismo. Va a dar error de compilación, ya que no hay ningún paréntesis que envuelva la expresión. Mejor rearmarla utilizando constructor de cadenas "%s %s (%s)"...
> return picking_info
> else:
> return ""
> -
> +
> def get_picking_info(self, invoice):
> -
> sql = "SELECT p.name, p.date "
> - sql += "FROM picking_invoice_rel r "
> - sql += "INNER JOIN stock_picking p ON p.id = r.picking_id "
> - sql += "INNER JOIN account_invoice i ON i.id = r.invoice_id "
> - sql += "WHERE r.invoice_id=" + str(invoice.id)+ " and p.date <= i.date_invoice "
> - sql += "ORDER BY p.date desc "
> -
> + "FROM picking_invoice_rel r "
Indentación incorrecta
> + "INNER JOIN stock_picking p ON p.id = r.picking_id "
> + "INNER JOIN account_invoice i ON i.id = r.invoice_id "
> + "WHERE r.invoice_id=" + str(invoice.id) + " and "
> + "p.date <= i.date_invoice "
> + "ORDER BY p.date desc "
> self.cr.execute(sql)
> results = self.cr.fetchall()
> -
> if results and len(results) > 0:
> for p in results:
> picking_date = datetime.strptime(p[1][0:10], '%Y-%m-%d')
> str_picking_date = picking_date.strftime('%d/%m/%Y')
> - picking_info = _("Albarán") + " " + p[0] + " (" + str_picking_date + ")"
> + picking_info = (_("Albarán") + " " +
Rearmarla con el constructor de cadenas
> + p[0] + " (" + str_picking_date + ")")
> return picking_info
> else:
> return ""
> -
> -
> - def get_rest_lines (self, invoice):
> -
> +
> + def get_rest_lines(self, invoice):
> product_obj = self.pool.get('product.product')
> space = " "
> -
> res = []
> -
> sign = 1.0
> if invoice.type == "out_refund" or invoice.type == "in_refund":
> sign = -1.0
> -
> count = 0
> max_lines = 35
> -
> # Enlaces y gastos de envio
> sql = "SELECT l.id "
> - sql += "FROM account_invoice_line l "
> - sql += "INNER JOIN stock_move m ON l.stock_move_id=m.id "
> - sql += "INNER JOIN stock_picking a ON m.picking_id=a.id "
> - sql += "INNER JOIN product_product p ON l.product_id=p.id "
> - sql += "INNER JOIN product_template t ON p.product_tmpl_id=t.id "
> - sql += "WHERE l.invoice_id = " + str(invoice.id) + " AND t.categ_id != 2 "
> - sql += "ORDER BY a.date, a.name, t.categ_id, l.product_id "
> -
> + "FROM account_invoice_line l "
Indentación incorrecta
> + "INNER JOIN stock_move m ON l.stock_move_id=m.id "
> + "INNER JOIN stock_picking a ON m.picking_id=a.id "
> + "INNER JOIN product_product p ON l.product_id=p.id "
> + "INNER JOIN product_template t ON p.product_tmpl_id=t.id "
> + "WHERE l.invoice_id = " + str(invoice.id) + " AND t.categ_id != 2 "
> + "ORDER BY a.date, a.name, t.categ_id, l.product_id "
> self.cr.execute(sql)
> results = self.cr.fetchall()
> lines_ids = [x[0] for x in results]
> -
> ant_picking_info = ""
> -
> - for l in self.pool.get('account.invoice.line').browse(self.cr, self.uid, lines_ids, context=None):
> -
> + inv_obj = self.pool.get('account.invoice.line')
self.pool[]
> + for l in inv_obj.browse(self.cr, self.uid, lines_ids, context=None):
Será context=context, no context=None.
> picking_info = self.get_picking_info_line(l)
> -
> # Linea de albarán
> if picking_info != ant_picking_info:
> line = {}
> -
> line["concept"] = picking_info
> line["uds"] = 0
> line["price"] = 0
> line["dto"] = 0
> line["import"] = 0
> - line["header"] = (count%max_lines == 0) and 1 or 0
> + line["header"] = (count % max_lines == 0) and 1 or 0
> line["picking"] = 1
> line["count"] = count
> -
> res.append(line)
> -
> ant_picking_info = picking_info
> count += 1
> -
> # Lineas de enlaces o gastos de envio
> line = {}
> -
> concept = l.product_id and l.product_id.name or " "
> -
> - if l.product_id and product_obj._is_link(l.product_id.categ_id) and l.contract_annexe_id.production_lot_2_id:
> - ref = l.contract_annexe_id.customer_ref or l.customer_ref or '-'
> - concept += " IMEI: " + (l.contract_annexe_id.production_lot_2_id.imei or '-') + ', REF.: ' + ref
> - concept = len(concept) > 62 and concept[0:61] + '...' or concept
> -
> + if (l.product_id and product_obj._is_link(l.product_id.categ_id)
> + and l.contract_annexe_id.production_lot_2_id):
> + ref = (l.contract_annexe_id.customer_ref or
> + l.customer_ref or '-')
> + concept += (" IMEI: " +
> + (l.contract_annexe_id.production_lot_2_id.imei
> + or '-') + ', REF.: ' + ref)
> + concept = (len(concept) > 62 and concept[0:61] +
> + '...' or concept)
> line["concept"] = space + concept
> line["uds"] = int(l.quantity or 0)
> line["price"] = l.price_unit * sign or 0
> line["dto"] = l.discount or 0
> line["import"] = l.price_subtotal * sign or 0
> - line["header"] = (count%max_lines == 0) and 1 or 0
> + line["header"] = (count % max_lines == 0) and 1 or 0
> line["count"] = count
> line["picking"] = 0
> -
> res.append(line)
> -
> count += 1
> + return res
>
> - return res
> -
> - def get_rest_lines_total (self, invoice):
> -
> + def get_rest_lines_total(self, invoice):
> product_obj = self.pool.get('product.product')
self.pool[]
> total = 0
> -
> sign = 1.0
> if invoice.type == "out_refund" or invoice.type == "in_refund":
> sign = -1.0
> -
> for l in invoice.invoice_line:
> - if l.stock_move_id and l.stock_move_id.picking_id and l.product_id and not product_obj._is_sim(l.product_id.categ_id):
> + if (l.stock_move_id and l.stock_move_id.picking_id and l.product_id
> + and not product_obj._is_sim(l.product_id.categ_id)):
> total += l.price_subtotal or 0
> -
> return total * sign or 0
>
> def get_company_logo(self, company):
> - return company.logo
> + return company.logo
>
> def company_address_visible(self):
> return False
> @@ -692,7 +667,7 @@
> return (26, 44)
>
>
> -class account_invoice_preprinted(account_invoice_custom):
> +class AccountInvoicePreprinted(AccountInvoiceCustom):
> def get_company_logo(self, company):
> return None
>
> @@ -703,7 +678,8 @@
> return (22, 40)
>
>
> -class account_invoice_nayar(account_invoice_custom):
> +class AccountInvoiceNayar(AccountInvoiceCustom):
> +
> def get_company_logo(self, company):
> return None
>
> @@ -712,11 +688,9 @@
>
> def get_invoice_lines(self, invoice):
> max_lines_first, max_lines = self.get_lines_per_page()
> -
> sign = 1.0
> if invoice.type == "out_refund" or invoice.type == "in_refund":
> sign = -1.0
> -
> res = []
> count = 0
> for l in invoice.invoice_line:
> @@ -726,21 +700,26 @@
> 'price': (l.price_unit or 0) * sign,
> 'dto': l.discount or 0,
> 'import': (l.price_subtotal or 0) * sign,
> - 'header': (count == 0) or (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0),
> - 'pagebreak': (count == max_lines_first) or ((count%max_lines == max_lines_first) and 1 or 0),
> + 'header': ((count == 0) or (count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0)),
> + 'pagebreak': ((count == max_lines_first) or
> + ((count % max_lines == max_lines_first)
> + and 1 or 0)),
> }
> -
> res.append(line)
> -
> count += 1
> -
> return res
> -
> -
> -report_sxw.report_sxw('report.account.invoice.custom', 'account.invoice', 'addons/dos_account_invoice_report/report/account_invoice.rml', parser=account_invoice_custom)
> -
> -report_sxw.report_sxw('report.account.invoice.preprinted', 'account.invoice', 'addons/dos_account_invoice_report/report/account_invoice.rml', parser=account_invoice_preprinted)
> -
> -report_sxw.report_sxw('report.account.invoice.nayar', 'account.invoice', 'addons/dos_account_invoice_report/report/account_invoice.rml', parser=account_invoice_nayar)
> -
> +
> +report_sxw.report_sxw('report.account.invoice.custom', 'account.invoice',
> + 'addons/dos_account_invoice_report'
> + '/report/account_invoice.rml',
> + parser=AccountInvoiceCustom)
> +report_sxw.report_sxw('report.account.invoice.preprinted', 'account.invoice',
> + 'addons/dos_account_invoice_report/'
> + 'report/account_invoice.rml',
> + parser=AccountInvoicePreprinted)
> +report_sxw.report_sxw('report.account.invoice.nayar', 'account.invoice',
> + 'addons/dos_account_invoice_report/'
> + 'report/account_invoice.rml', parser=AccountInvoiceNayar)
> # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
>
> === added directory 'dos_account_invoice_report/views'
> === renamed file 'dos_account_invoice_report/account_invoice_report.xml' => 'dos_account_invoice_report/views/account_invoice_report.xml'
> --- dos_account_invoice_report/account_invoice_report.xml 2014-06-11 10:23:47 +0000
> +++ dos_account_invoice_report/views/account_invoice_report.xml 2014-06-13 12:10:28 +0000
> @@ -36,13 +36,12 @@
>
> <record id="view_invoice_report_inherit_account" model="ir.ui.view">
> <field name="name">stock.invoice.report.form</field>
> - <field name="type">form</field>
> <field name="model">account.invoice</field>
> <field name="inherit_id" ref="account.invoice_form"/>
> <field name="arch" type="xml">
> - <xpath expr="/form/notebook/page[@string='Invoice']/group/group/button[@string='Print Invoice']" position="replace">
> - <button name="%(account_invoice_custom_report)d" string="Print Invoice" type="action" icon="gtk-print" states="open,paid,proforma,sale,proforma2"/>
> - </xpath>
> + <button name="270" position="attributes">
En vez del número (ID), que es una referencia que depende de la BD, pon <button string="Print Invoice" ...> y también lo sabe relacionar.
> + <attribute name='states'>open,paid,proforma,sale,proforma2</attribute>
> + </button>
> </field>
> </record>
>
>
--
https://code.launchpad.net/~mikelarregi/avanzosc/72horas/+merge/223059
Your team Avanzosc_security is subscribed to branch lp:~avanzosc-security-team/avanzosc/72horas.