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

Count Rows of one2many field - numbering positions

Subscribe

Get notified when there's activity on this post

This question has been flagged
4 Replies
11917 Views
Avatar
birduser

I try to implement numbering positions in invoices. I got a field "position" in the one2many field and it looks like this

<field name="invoice_line" widget="one2many_list" context="{'type': type,'order_id':active_id}">
      <field name="position"/>
(..)

My class

class account_invoice_line(osv.osv):
    _inherit = 'account.invoice.line'
    _columns = {
        'position': fields.char('Position'),
    }

    def position_number(self, cr, uid, context=None):
        return ACTUAL ROW NUMBER

    _defaults = {
        'position': lambda obj, cr, uid, context: obj.position_number(cr, uid, context),
    }

account_invoice_line()

I have no Idea how to get the actual row number or how to count the rows. I found this, but it's not working :-/

def _default_sequence(self, cr, uid, context=None):
        if context is None:
            context = {}
        max_sequence = 0
        if context.get('order_id'):
            sale_order_line_ids = self.search(cr, uid, [('order_id', '=', context['order_id'])])
            if sale_order_line_ids:
                max_sequence = max([line['position'] for line in self.read(cr, uid, sale_order_line_ids, ['position'])])
        return max_sequence + 1

    _defaults = {
        'sequence': lambda obj, cr, uid, context: obj._default_sequence(cr, uid, context),
    }

Can anybody help me?

0
Avatar
Discard
Avatar
Hardikgiri Goswami
Best Answer

I have do it using on_change attribute of order_line. I have made changes in xml like this.

<field name="order_line" on_change="update_seq(order_line)">

and the python side in sale.order added following method.

def update_seq(self, cr, uid, ids, order_line, context=None):
        new_order_line = []
        counter = 1
        for line in order_line:
            if line[0] in [1,4]:
                line[0] = 1
            if type(line[2]) == type({}):
                line[2].update({'seq':counter})
            else:
                line[2] = {'seq':counter}
            counter = counter + 1
            new_order_line.append(line)
        return {'value': {'order_line': new_order_line} }

Just try it. and post here if any problem occurs.

3
Avatar
Discard
birduser
Author

Okay, I tried it, but I have the problem, that the onchange function won't be executed. So I have a field: <field name="position" on_change="position_number(cr, uid, context)"/> and a function "def position_number(self, cr, uid, context=None): print("bla")" but the function will not be executed. Why?

Hardikgiri Goswami

Because, from the XML part you can not pass cr, uid and context. These are the default parameter that OpenERP core will be pass automatically. That's is the only reason the method is not going to execute.

Avatar
Kevin Kong
Best Answer

I just have an app to slove this problem. search rowno in app store.

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
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