Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Artificial Intelligence
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Property Management
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Python code from odoo16 does not work at odoo 17.

Subscriure's

Get notified when there's activity on this post

This question has been flagged
v17
1 Respondre
1886 Vistes
Avatar
MT Tech, Htet Aung Shane

I have a module to hide the buttons and tab and this custom code works at odoo16, but not at odoo17

from odoo import fields, models, api, _from lxml import etree


class HideViewNodes(models.Model): _name = 'hide.view.nodes' _description = 'Hide View Nodes'

access_rights_management_id = fields.Many2one('access.rights.management', 'Access Management') model_id = fields.Many2one('ir.model', string='Model', index=True, required=True, ondelete='cascade') model_name = fields.Char(string='Model Name', related='model_id.model', readonly=True, store=True)

btn_store_model_nodes_ids = fields.Many2many('store.model.nodes', 'btn_hide_view_nodes_store_model_nodes_rel', 'hide_id', 'store_id', string='Hide Button', domain="[('node_option','=','button')]") page_store_model_nodes_ids = fields.Many2many('store.model.nodes', 'page_hide_view_nodes_store_model_nodes_rel', 'hide_id', 'store_id', string='Hide Tab/Page', domain="[('node_option','=','page')]")

def _store_btn_data(self, btn, smart_button=False, smart_button_string=False): # string_value is used in case of kanban view button store, string_value = 'string_value' in self._context.keys() and self._context['string_value'] or False

store_model_button_obj = self.env['store.model.nodes'] name = btn.get('string') or string_value if smart_button: name = smart_button_string store_model_button_obj.create({ 'model_id': self.model_id.id, 'node_option': 'button', 'attribute_name': btn.get('name'), 'attribute_string': name, 'button_type': btn.get('type'), 'is_smart_button': smart_button, })

def _get_smart_btn_string(self, btn_list, type=False): store_model_button_obj = self.env['store.model.nodes']

def _get_span_text(span_list): name = '' for sp in span_list: if sp.text: name = name + ' ' + sp.text name = name.strip() return name

for btn in btn_list: name = '' field_list = btn.findall('field') if field_list: name = field_list[0].get('string') else: span_list = btn.findall('span') if span_list: name = _get_span_text(span_list) else: div_list = btn.findall('div') if div_list: span_list = div_list[0].findall('span') if span_list: name = _get_span_text(span_list) if not name: try: name = btn.get('string') except: pass if name and (type == 'object' or type == 'action'): domain = [('button_type', '=', btn.get('type')), ('attribute_string', '=', name), ('model_id', '=', self.model_id.id), ('node_option', '=', 'button')] if type == 'object': domain += [('attribute_name', '=', btn.get('name'))] if type == 'action': domain += [('attribute_name', '=', btn.get('name'))] smart_button_id = store_model_button_obj.search(domain) if not smart_button_id: self._store_btn_data(btn, smart_button=True, smart_button_string=name) else: smart_button_id[0].is_smart_button = True

@api.onchange('model_id') def _get_button(self): if self.model_id and self.model_name: store_model_nodes_obj = self.env['store.model.nodes'] view_obj = self.env['ir.ui.view'] view_list = ['form', 'tree', 'kanban'] for view in view_list: for views in view_obj.search( [('model', '=', self.model_name), ('type', '=', view), ('inherit_id', '=', False)]): res = self.env[self.model_name].sudo().get_view(view_id=views.id, view_type=view) print("REs is arch ======",res['arch'])

doc = etree.XML(res['arch']) # print(doc)

object_button = doc.xpath("//button[@type='object']") for btn in object_button: string_value = btn.get('string') print("object button",string_value) if btn.get('name') and string_value: domain = [('button_type', '=', btn.get('type')), ('attribute_string', '=', string_value), ('attribute_name', '=', btn.get('name')), ('model_id', '=', self.model_id.id), ('node_option', '=', 'button')] # print(domain) if not store_model_nodes_obj.search(domain): self.with_context(string_value=string_value)._store_btn_data(btn)

action_button = doc.xpath("//button[@type='action']") for btn in action_button: string_value = btn.get('string') if view == 'kanban' and not string_value: try: string_value = btn.text if not btn.text.startswith('\n') else False except: pass if btn.get('name') and string_value: domain = [('button_type', '=', btn.get('type')), ('attribute_string', '=', string_value), ('attribute_name', '=', btn.get('name')), ('model_id', '=', self.model_id.id), ('node_option', '=', 'button')] if not store_model_nodes_obj.search(domain): self.with_context(string_value=string_value)._store_btn_data(btn)

## Tab Extraction page_list = doc.xpath("//page") if page_list: for page in page_list: if page.get('string'): domain = [('attribute_string', '=', page.get('string')), ('model_id', '=', self.model_id.id), ('node_option', '=', 'page')] if page.get('name'): domain += [('attribute_name', '=', page.get('name'))] store_model_nodes_id = store_model_nodes_obj.search(domain, limit=1) if not store_model_nodes_id: store_model_nodes_obj.create({ 'model_id': self.model_id.id, 'attribute_name': page.get('name'), 'attribute_string': page.get('string'), 'node_option': 'page', })

0
Avatar
Descartar
Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer

Hi,

In Odoo 17, many changes have occurred compared to Odoo 16. There are changes in functions, decorators, field attributes, and in XML templates, 'attrs' and 'states' are no longer used. Due to these significant changes, instead of sharing your code, you could also share the errors encountered while migrating from V17 to V16. This may help in resolving your query.


Hope it helps

0
Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Ya es posible hacer Upgrade de v17 a v17.1 ?
v17
Avatar
Avatar
1
d’oct. 25
2393
How to add a new Many2one field in res.config.settings? Solved
v17
Avatar
Avatar
Avatar
Avatar
4
d’oct. 25
5371
Add field to ALL models in Odoo
v17
Avatar
Avatar
Avatar
2
de set. 25
3758
How to disable Email notification - You have been assigned to Solved
v17
Avatar
Avatar
Avatar
3
d’abr. 26
9905
Selection Field Options Disappear from Database (PostgreSQL enum) on Module Upgrade
v17
Avatar
0
d’ag. 25
2489
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now