Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7938497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:49:44+00:00 2026-06-03T22:49:44+00:00

I have created on2many field in class A and other field nombre (integer): ‘Inventaire’

  • 0

I have created on2many field in class A and other field nombre (integer):

'Inventaire' : fields.one2many('class.b','id_classb'),

'nombre' : fields.integer('Nombre'),

In class b :

'id_classb' : fields.many2one('class.a', 'ID_classA'),

'ql' : fields.integer('QL'),

I want to create a function in class a that create records for object b according to the value of nombre field. for example if nombre =3 I should create 3 object of class b

here is my function:

 def save_b(self, cr, uid, ids, field_name, arg, context):
  a= self.browse(cr, uid, id)
  nbr=a.nombre
  num=22
  for i in range(nbr):
       num+=1
       self.create(cr, uid, [(0, 0,{'ql':num})])

I get these errors :
TypeError:range()integer expected ,got NoneType
ValueError: dictionary update sequence element #0 has length 3; 2 is required

can someone help me to improve my function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T22:49:46+00:00Added an answer on June 3, 2026 at 10:49 pm

    You have following errors:

    1. Your create call values should be a dictionary with field names as keys, not a list with tuples. The notation you are using is for writing/updating one2many fields.

    2. You are not creating ‘class b’ records, but creating ‘class a’ records instead (using self instead of a self.pool.get call)

    So you should write

    def save_b(self, cr, uid, ids, field_name, arg, context):
        b_obj = self.pool.get('class.b') # Fixes (#2)
        for record in self.browse(cr, uid, ids, context=context):
            num = 22
            for i in range(record.nombre):
                num += 1
                new_id = b_obj.create(cr, uid, {
                    'ql': num,
                    'id_classb': record.id
                }, context=context) # Fixes (#1)
    

    Or as an alternative:

    def save_b(self, cr, uid, ids, field_name, arg, context):
        for record in self.browse(cr, uid, ids, context=context):
            sub_lines = []
            num = 22
            for i in range(record.nombre):
                num += 1
                sub_lines.append( (0,0,{'q1': num}) )
                # Notice how we don't pass id_classb value here,
                # it is implicit when we write one2many field
            record.write({'Inventaire': sub_lines}, context=context)
    

    Remark: In class b your link to class a is in column named ‘id_classb’? The openerp-etiquette expects you to name them ‘classa_id’ or something similar.

    Also, creating column names with capitals is frowned upon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have created simple Ajax enabled contact forms before that have around 12 fields -
I have created a SeedData class, and populated it with the values that I
I have created a CustomValidator control public class MyValidator :CustomValidator, IScriptControl {} and also
I have created a reusable class that fades in a loading message and indicator
I have created a smalldatetime field. I am using a dbml file to access
I have created a C# class file by using a XSD-file as an input.
I have created an on the fly search field in Java Swing. I have
I have created custom listview in that have list of textview & list of
I have created a bar chart which is a improvement of bar graph on
I have created a console application in C# and there is main method (static)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.