Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
4552 มุมมอง

i added the serial_no field stock.moves

model

class StockMove(models.Model):

    _inherit = "stock.move" 

   serial_no = fields.Char(string="Serial#", readonly=True)

I use onchange function to pass values from product to movelines

onchange

@api.onchange('product_id')

    def on_change_product(self):

           self.serial_no = self.product_id.serial_no

Then i used the create method to save these values
create 

@api.model

    def create(self, vals):

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

        product_records = product_obj.search([])

        for record in product_records:

            vals['serial_no'] = record.serial_no

        res = super(StockMove, self).create(vals)

        return res

notes

the serial no field is not saved.How to save the field?
please help to find what is wrong in my code?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Dear acha aslam

You can make it computed field like this:

@api.depends('product_id')

    def _get_serial_no(self):

           self.serial_no = self.product_id.serial_no


   serial_no = fields.Char(compute=_get_serial_no ,string="Serial#", store=True)


Then you can remove the onchange function ...


I hope I helped you ...




อวตาร
ละทิ้ง

also remove the create method

ผู้เขียน

Thanks ayman

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มิ.ย. 17
3891
0
เม.ย. 20
4063
1
มี.ค. 18
11156
1
ก.ย. 17
4967
3
พ.ค. 17
11021