110 lines
4.9 KiB
Python
110 lines
4.9 KiB
Python
# Part of Beyond. Collina Systems proprietary module.
|
|
import logging
|
|
|
|
from odoo import api, models
|
|
|
|
from odoo.addons.beyond_base.tools.arranque import ejecutar_en_arranque
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
# El nombre de la compañía es «Beyond» (28-ago-2026, por instrucción del
|
|
# director). Revierte la decisión del 24-ago, que la llamaba «Look Capital»
|
|
# distinguiendo la razón social del nombre de la instancia: la distinción es
|
|
# correcta, pero el nombre de la compañía es lo que Odoo pinta en la barra
|
|
# superior y bajo el título del Panel General, y el criterio del cliente es
|
|
# que en pantalla no aparezca ningún nombre que no sea Beyond.
|
|
#
|
|
# Si la razón social hace falta algún día —en un ticket, en un documento
|
|
# fiscal— será un campo aparte con su propio dueño, no este, que es el que
|
|
# se ve. Este archivo posee el nombre; el Panel General lo lee de aquí
|
|
# (res.company.name) y nunca lo escribe en duro.
|
|
NOMBRE_COMPANIA = 'Beyond'
|
|
|
|
# Odoo's sample contact details for the main company, written by
|
|
# base/data/res_users_demo.xml. They are not decoration: the POS receipt
|
|
# footer prints the company address, VAT, phone, e-mail and website
|
|
# (point_of_sale OrderReceipt), so a branch that has not been configured
|
|
# hands the customer a ticket pointing at 8000 Marina Blvd, Brisbane.
|
|
#
|
|
# Each field lists every spelling the sample value can have; `website` is
|
|
# stored normalised, so the value written by the core and the value Odoo
|
|
# saves are not the same string.
|
|
#
|
|
# NOT the company name: that one is owned above and always ends up as
|
|
# NOMBRE_COMPANIA. NOT country_id or state_id either — clearing those would
|
|
# change how taxes and addresses behave, which is a decision of its own.
|
|
DATOS_DE_MUESTRA = {
|
|
'street': {'8000 Marina Blvd, Suite 300'},
|
|
'street2': {'Suite 300'},
|
|
'city': {'Brisbane'},
|
|
'zip': {'94005'},
|
|
'phone': {'+1 555-555-5556'},
|
|
'email': {'info@yourcompany.com'},
|
|
'website': {'www.example.com', 'http://www.example.com',
|
|
'https://www.example.com'},
|
|
}
|
|
|
|
|
|
class ResCompany(models.Model):
|
|
_inherit = 'res.company'
|
|
|
|
@api.model
|
|
def _beyond_arranque_nombre(self):
|
|
"""Entrada desde la carga de módulos (data/branding.xml). Va envuelta: una
|
|
tarea de arranque degrada, nunca tumba el servidor."""
|
|
return ejecutar_en_arranque(
|
|
self.env, 'Nombre de la compañía matriz', self._beyond_asegurar_nombre)
|
|
|
|
@api.model
|
|
def _beyond_asegurar_nombre(self):
|
|
"""Fija el nombre de la compañía matriz.
|
|
|
|
Por función y no por <record>: base.main_company está marcado
|
|
noupdate en ir.model.data, y el core SALTA EN SILENCIO todo <record>
|
|
sobre un xmlid noupdate cuando el módulo se ACTUALIZA — que es lo que
|
|
hace cada arranque en producción. El <record> que estuvo aquí hasta
|
|
hoy solo se aplicó en instalaciones limpias; en cualquier base que
|
|
haya nacido antes, el nombre quedó como estuviera y nadie se enteró.
|
|
Mismo mecanismo y misma razón que data/pricelist_feature.xml (ADR-009).
|
|
|
|
Idempotente y silenciosa: solo escribe si el nombre difiere. Corre en
|
|
cada arranque y un write incondicional dejaría rastro en write_date y
|
|
en el seguimiento del registro en cada despliegue, sin motivo.
|
|
"""
|
|
compania = self.env.ref('base.main_company').sudo()
|
|
if compania.name != NOMBRE_COMPANIA:
|
|
compania.write({'name': NOMBRE_COMPANIA})
|
|
self._beyond_limpiar_datos_de_muestra(compania)
|
|
return True
|
|
|
|
@api.model
|
|
def _beyond_limpiar_datos_de_muestra(self, compania):
|
|
"""Clear the sample contact details Odoo ships, and only those.
|
|
|
|
The POS receipt footer prints the company address and contact block,
|
|
so an unconfigured deployment gives customers a ticket with Odoo's
|
|
demo address on it. Empty is the honest state: the footer simply
|
|
omits every field it does not have.
|
|
|
|
The comparison is exact and per field. A value that is not literally
|
|
one of Odoo's sample strings is real data somebody typed and is never
|
|
touched — including a real address that happens to be in Brisbane.
|
|
Idempotent: once cleared there is nothing left to match, so later
|
|
boots write nothing.
|
|
|
|
Deliberately narrow: this does not try to detect "looks like sample
|
|
data". Guessing would eventually delete a real address, and there is
|
|
no undo for that.
|
|
"""
|
|
borrar = {campo: False
|
|
for campo, muestras in DATOS_DE_MUESTRA.items()
|
|
if (compania[campo] or '') in muestras}
|
|
if borrar:
|
|
_logger.warning(
|
|
'Beyond · %s tenía datos de contacto de muestra de Odoo (%s). '
|
|
'Se vacían: el pie del ticket del punto de venta los imprime. '
|
|
'Captura los reales en Ajustes cuando los tengas.',
|
|
compania.name, ', '.join(sorted(borrar)))
|
|
compania.write(borrar)
|
|
return borrar
|