Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

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

Subscribe

Get notified when there's activity on this post

This question has been flagged
developmentrecieptcustomizeodoo18
2 Replies
509 Views
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
Discard
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
Discard
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
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Chatter in Odoo 18 Solved
development chatter odoo18
Avatar
Avatar
1
Oct 25
7259
Delete Fields From POS receipt
development pos reciept
Avatar
Avatar
Avatar
2
Oct 22
3948
Customizing Payroll Features in Odoo 17 Community Edition
development payroll customize odoo17CE
Avatar
0
Aug 24
5
How to increment stock in product page Odoo 18
development stock product odooonline odoo18
Avatar
Avatar
Avatar
2
Mar 25
1710
Custom Addons Odoo 17
development server addons customize odoo17
Avatar
Avatar
1
Jun 24
2339
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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