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
    • Validacions
    • 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ó
    • Gestió immobiliària
    • 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

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
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

How to invisible "Add a lines" button with conditions in order line odoo version18?

Subscriure's

Get notified when there's activity on this post

This question has been flagged
developmentrecieptcustomizeodoo18
2 Respostes
498 Vistes
Avatar
PhongsakornChe
I am in odoo18 and currently on the Receipt page. At the bottom section of this page, there is a tab called Operations which contains the product lines. I want to make this entire section read-only except for the hamburger icon (the “lot” action button) that allows adding lots to the products.



In hamburger button:


First, I used this code to make the entire section read-only, but it also disabled the hamburger icon, so I could not add lots at all:

<xpath expr="//field[@name='move_ids_without_package']" position="attributes">
    <attribute name="readonly">
        state == 'done' or approval_editable_has_po != 'edit_approved'
    </attribute>
    <attribute name="force_save">1</attribute>
</xpath>

Then, I changed the code by setting each individual column to read-only, leaving only the hamburger icon editable:

<xpath expr="//field[@name='move_ids_without_package']/list/field[@name='product_id']" position="attributes">
    <attribute name="readonly">parent.state == 'done' or parent.approval_editable_has_po != 'edit_approved'</attribute>
    <attribute name="force_save">1</attribute>
</xpath>

(…and similar XPaths for other columns)

The result is: all columns are read-only, so users cannot add new products — which is correct — and the hamburger icon still works, which is also what I want.

However, I also want to hide the “Add a line” button.

I tried:


<xpath expr="//field[@name='move_ids_without_package']/list" position="attributes">
    <attribute name="create">0</attribute>
</xpath>

This hides Add a line, but it disappears permanently.


Then I tried adding conditions:

<xpath expr="//field[@name='move_ids_without_package']/list" position="attributes">
    <attribute name="create">
        parent.state != 'done' or parent.approval_editable_has_po == 'edit_approved'
    </attribute>
</xpath>


But this does not work — look like the create attribute seems to accept only True/False/1/0 and ignores domain-like expressions.

My question is:

Is it possible to hide the “Add a line” button conditionally (based on state and approval fields) while still keeping the hamburger icon editable?

0
Avatar
Descartar
Avatar
Vashmitha V
Best Answer

Hello there,

Check this,

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_picking_form_inherit_restrict_new" model="ir.ui.view">
<field name="name">stock.picking.restrict.new</field>
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='move_ids_without_package']" position="attributes">
<attribute name="options">{'create':[('state','not in',['done','cancel'])]}</attribute>
</xpath>
</field>
</record>
</odoo>


Hope this helps you.

0
Avatar
Descartar
Avatar
Kunjan Patel
Best Answer
Hello PhongsakornChe
I hope you are doing well

Yes, but it requires JavaScript (Odoo 18)

XML alone cannot do this - create attribute only accepts True/False, not conditions.

Solution: JavaScript + XML
static/src/js/list_renderer.js
  /** @odoo-module **/
  import { patch } from "@web/core/utils/patch";
  import { ListRenderer } from "@web/views/list/list_renderer";

  patch(ListRenderer.prototype, {
      get canCreate() {
          const ctx = this.props.list.context;
          // Hide "Add a line" when state is done AND not edit_approved
          if (ctx.parent_state === 'done' && ctx.parent_approval !== 'edit_approved') {
              return false;
          }
          return super.canCreate;
      }
  });

views/stock_picking_view.xml (pass context)
  <xpath expr="//field[@name='move_line_ids']" position="attributes">
      <attribute name="context">{
          'parent_state': parent.state,
          'parent_approval': parent.approval_editable_has_po
      }</attribute>
  </xpath>

  __manifest__.py
  'assets': {
      'web.assets_backend': [
          'your_module/static/src/js/list_renderer.js',
      ],
  },

I hope this information helps you

Thanks & Regards
Kunjan Patel
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
Chatter in Odoo 18 Solved
development chatter odoo18
Avatar
Avatar
1
d’oct. 25
7247
Delete Fields From POS receipt
development pos reciept
Avatar
Avatar
Avatar
2
d’oct. 22
3948
Customizing Payroll Features in Odoo 17 Community Edition
development payroll customize odoo17CE
Avatar
0
d’ag. 24
5
How to increment stock in product page Odoo 18
development stock product odooonline odoo18
Avatar
Avatar
Avatar
2
de març 25
1708
Custom Addons Odoo 17
development server addons customize odoo17
Avatar
Avatar
1
de juny 24
2335
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 ภาษาไทย 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