콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
7494 화면

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 ?

 

아바타
취소
베스트 답변

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

아바타
취소
작성자 베스트 답변

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.

작성자

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

작성자

I will modifiy the previous answer

관련 게시물 답글 화면 활동
1
8월 24
30190
2
5월 16
3582
0
5월 20
2494
0
4월 19
2851
0
8월 18
2859