-
-
Notifications
You must be signed in to change notification settings - Fork 507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[9.0][MIG] l10n_es_partner #410
Conversation
* Permite validar las cuentas bancarias españolas. Para ello, se añade un | ||
campo de país a las cuentas bancarias de las empresas y se realizan | ||
validaciones cuando el país es España. | ||
* Añade el campo *Nombre comercial* a las empresas y permite buscar por él. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿Qué significa permite buscar por él? Es obvio que si añades un campo puedes buscar por él. Sin embargo he probado a buscar por el nombre comercial usando el buscado rápido y no lo permite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se permite buscar desde los campos many2one, por ejemplo, buscando un cliente para poner en el pedido de venta.
Configuración > Técnico > Parámetros > Parámetros del sistema | ||
Seleccionar la clave l10n_es_partner.name_pattern | ||
Definir el patron utilizando las etiquetas *%(name)s* para nombre y | ||
*%(comercial_name)s* para nombre comercial. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿Esto no choca con https://github.com/OCA/partner-contact/tree/9.0/partner_firstname?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No debería chocar, ya que se añade a lo que devuelva el super.
<!-- © 2016 Carlos Dauden <carlos.dauden@tecnativa.com> | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl-3). --> | ||
<odoo> | ||
<data noupdate="1"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Podría ser <odoo noupdate="1">
, aunque no es bloqueante.
return | ||
# Preparar el archivo resultante | ||
output = codecs.open(dest_path, mode='w', encoding='utf-8') | ||
output.write("<?xml version='1.0' encoding='UTF-8'?>\n") | ||
output.write("<openerp>\n") | ||
output.write(" <data>\n") | ||
output.write("<odoo>\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me sentiría más confiado de usar lxml
o csv
para esto, por el tema de escapar datos y tal, aparte de que el código quedaría bastante más limpio. Supongo que sería una buena idea para el roadmap si no lo hacemos ahora.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Con CSV tendríamos que escapar más datos todavía, y lxml es muy poco pythonista y apuesto a que sería incluso más código, así que prefiero seguir haciéndolo así.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿El CSV no lo escapa automáticamente LibreOffice? Hasta donde he probado es así... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pero es que aquí no hay LibreOffice entre medias. Se procesa directamente por Odoo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah cierto, de todas formas está el módulo csv
, que te hace todo él solito.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sí, pero ya te digo, en esto no merece la pena volverlo a cambiar. Lo dejamos así.
@@ -68,56 +71,67 @@ def gen_bank_data_xml(src_path, dest_path): | |||
try: | |||
reader = XlsDictReader(src_path) | |||
except IOError: | |||
_logger.info("Archivo REGBANESP_CONESTAB_A.XLS no encontrado.") | |||
_logger.error("Archivo '%s' no encontrado." % src_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creo que es bueno poner los logs en inglés, más que nada por si algún extranjero tiene que instalar este módulo en la base de datos de un cliente, para que pueda darle mantenimiento.
escape(unicode(int(row['CODPOSTAL']))[:-3].zfill(2)) or False)) | ||
output.write(indent * 2 + '<field name="country" ref="base.es"/>\n') | ||
output.write(indent + '</record>\n') | ||
output.write("</odoo>\n") | ||
output.close() | ||
_logger.info("data_banks.xml generado correctamente.") | ||
|
||
|
||
if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Igual estoy preguntando una perogrullada, pero ¿por qué íbamos a querer ejecutar un script directamente? ¿No hay un wizard en Odoo ya que lo hace? ¿Y no debería guardarse en un ir.attachment en el filestore en lugar de donde el código del módulo? las carpetas de código pueden no ser escribibles por el usuario odoo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esto está puesto así para poder ejecutar el script directamente para obtener el xml archivado que se incluye como salvaguarda en caso de que no funcione la conexión a Internet.
|
||
@api.multi | ||
@api.depends('name', 'comercial') | ||
def name_get(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿No es más sencillo hacer del display_name
un campo calculado (que, de hecho, puede estar almacenado)? Con esto puede que incluso nos ahorrásemos sobrecargar name_search
...
|
||
|
||
class ResBank(models.Model): | ||
_inherit = 'res.bank' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿No es res.partner.bank
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, estos campos se añaden al banco, no a la cuenta bancaria del cliente.
return "%1d%1d" % (dc1, dc2) | ||
|
||
@api.model | ||
def check_bank_account(self, account): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿Esto no debería ser un constraint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, se activa en un onchange. El nombre es herencia, pero bueno, tampoco veo uno mejor.
for i in account: | ||
if i.isdigit(): | ||
number += i | ||
if len(number) != 20: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Este chequeo debería omitirse si la cuenta no es española.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Esa comprobación ya está en el método que lo llama (el onchange).
while iban_str: | ||
res.append(iban_str[:4]) | ||
iban_str = iban_str[4:] | ||
return ' '.join(res) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
¿No sirve la función que incluye Odoo?
b1dc166
to
5782757
Compare
@yajo listo para revisar otra vez, con los comentarios correspondientes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Un último esfuerzo 😉
@@ -14,23 +15,24 @@ class ResPartnerBank(models.Model): | |||
acc_country_id = fields.Many2one( | |||
comodel_name='res.country', related='partner_id.country_id', | |||
string='Bank country', readonly=True, | |||
help='If the country of the bank is Spain, it validates the bank ' | |||
help='If the country ofº the bank is Spain, it validates the bank ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se te ha colado un º
@@ -24,17 +24,23 @@ def create(self, vals): | |||
# Write a more complete version of the journal name for Spanish | |||
# bank and cash journals | |||
bank = self.env['res.bank'].browse(vals['bank_id']) | |||
vals['name'] = "{} {}".format(bank.name, vals['bank_acc_number']) | |||
vals['name'] = u"{} {}".format(bank.name, vals['bank_acc_number']) | |||
return super(AccountJournal, self).create(vals) | |||
|
|||
@api.multi | |||
@api.onchange('bank_acc_country_id', 'bank_acc_number') | |||
def onchange_bank_acc_number_l10n_es_partner(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En api nueva los onchange deben ser privados.
factor = (1, 2, 4, 8, 5, 10, 9, 7, 3, 6) | ||
# Cálculo CRC | ||
nCRC = 0 | ||
for n in range(10): | ||
nCRC += int(texto[n]) * factor[n] | ||
# Reducción del CRC a un dígi9to | ||
# Reducción del CRC a un dígiito |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dígito"
|
||
@api.multi | ||
@api.onchange('bank_acc_country_id', 'bank_acc_number') | ||
def onchange_bank_acc_number_l10n_es_partner(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Este método debería ser privado también.
|
||
@api.multi | ||
@api.onchange('acc_country_id', 'acc_number') | ||
def onchange_acc_number_l10n_es_partner(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
En api nueva, los onchange deberían ser privados.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No tiene por qué. De hecho, yo casi prefiero que no lo sean para evitar los avisos de los IDEs que estás invocando a un método privado y demás.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La api nueva llama al método onchange()
, que se encarga de llamar a los otros, por eso se suelen quedar privados, aparte de que son las guidelines. No sé qué IDE gastas, pero el mío lleva flake8 integrado y nunca le he visto quejarse por eso 😆 . Bueno, de todas formas supongo que tampoco es obligatorio 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
El aviso la da PyCharm como un warning, no como un error, y es debido a como no se utiliza herencia Python, si no el _inherit del ORM. Haciendo una búsqueda en el código de Odoo, hay ocurrencias de ambas formas, pero en las guidelines sí que habla de _onchange
, así que lo cambio.
nCRC = 0 | ||
for n in range(10): | ||
nCRC += int(texto[n]) * factor[n] | ||
# Reducción del CRC a un dígiito |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"dígito"
acc_country_id = fields.Many2one( | ||
comodel_name='res.country', related='partner_id.country_id', | ||
string='Bank country', readonly=True, | ||
help='If the country ofº the bank is Spain, it validates the bank ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Se te ha colado un º
…onfigurable pattern
5782757
to
03ea949
Compare
@yajo, últimos cambios hechos |
03ea949
to
ba2b3b5
Compare
* Better search on partner * Review fixes * More tests
ba2b3b5
to
988a906
Compare
cc @Tecnativa