Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to create a new row in a table ?

By
Salma
on 3/9/16, 9:03 AM 417 views

Hello ! please can someone tell me how to create a new row in a table and fill it with the computed fields

class ProductImpo(models.Model):

      _name = 'product.impo'

      id = fields.Integer(string="ID", compute='_compute_id',Store=True)

      Serial_No = fields.Char(string="N° de série", compute='_compute_serial_no')

      @api.multi

      def _compute_id(self):

            i=0

            for record in self:

                       i=i+1

                      record.id=i

       @api.multi

      def _compute_serial_no(self):

               i=-1

               for record in self:

                        i=i+1

                       record.Serial_No=result.Stock_Vehicule[i].Serial_No

Should I use :

product_impo = self.env['product.impo']

product_impo.sudo().write({'id':self.id,  'Serial_No': self.Serial_No  })
If yes so where I must put it ??
PS: The table product_impo in PostgreSQL is empty that's why when I display the tree view I obtain it empty so how to create a new row in the table ?

 

0
Salma
On 3/10/16, 2:21 AM

Yes I have created a treeview : 

<record id="product_impo_tree_view" model="ir.ui.view">

<field name="name">product.impo.tree</field>

<field name="model">product.impo</field>

<field name="arch" type="xml">

<tree string="Disponibilité">

<field name="id"/>

<field name="VIN"/>

<field name="Serial_No"/>

</tree>

</field>

</record>
So it must be like this : 

class ProductImpo(models.Model):

_name = 'product.impo'

VIN = fields.Char(string="VIN", compute='_compute_vin')

Serial_No = fields.Char(string="N° de série", compute='_compute_vin')

@api.multi

def _compute_vin(self):

i=0

while i < taille:

self.VIN=result.Stock_Vehicule[i].VIN

self.Serial_No=result.Stock_Vehicule[i].Serial_No

impo = self.env['product.impo']

impo.sudo().create({'VIN': self.VIN, 'Serial_No': self.Serial_No})

i=i+1
Is that true ?


Did you create a view for the object "product.impo"?. If u have created, there is no need to write a function like you mentioned.

CatsandDogs
on 3/10/16, 3:43 AM

Yes I have created a tree view : product.impo.tree product.impo So just I need to do that ? : class ProductImpo(models.Model): _name = 'product.impo' VIN = fields.Char(string="VIN", compute='_compute_vin') Serial_No = fields.Char(string="N° de série", compute='_compute_vin') @api.multi def _compute_vin(self): i=0 while i

Salma
on 3/10/16, 4:07 AM

I will modifiy the previous answer

Salma
on 3/10/16, 4:08 AM
0
CatsandDogs
On 3/10/16, 1:13 AM

Use,

product_impo.sudo().create({'id':self.id,  'Serial_No': self.Serial_No  })

Note:

Don't use field name as 'id' because following fields are reserved in odoo.

id, create_date, create_uid. write_date, write_uid

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/9/16, 9:03 AM
Seen: 417 times
Last updated: 3/10/16, 2:21 AM