Skip to Content
Menu
This question has been flagged
2 Replies
6855 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 ?

 

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

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 ?


Avatar
Discard

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.

Author

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

Author

I will modifiy the previous answer

Related Posts Replies Views Activity
1
Aug 24
26617
2
May 16
3115
0
May 20
2003
0
Apr 19
2424
0
Aug 18
2409