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

I inherit the model stock.move and add serial_no in move lines.That field is readonly

class StockMove(models.Model):

    _inherit = "stock.move" 

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

  • I use the onchange function to pass value from product

function

@api.onchange('product_id')

def on_change_product(self):

        self.serial_no = self.product_id.serial_no

I override the create function to write that value

create function

    @api.model

    def create(self, vals):

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

        product_records = product_obj.search([])

        for record in product_records:

         self.serial_no = record.serial_no

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

        return res

notes

When i save the record then there is an error occured like this

raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: stock.move()

How to solve this issue ?


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

Hi Acha aslam,

You can save the values in the readonly field by supering the create function. You can refer this Link


@api.model
def create(self, vals):
        vals['test'] = "assign value here"
         res = super(SaleOrderCustom, self).create(vals)
         return res
@api.multi
def write(self, vals):
         vals['test'] = "assign value here"
         res = super(SaleOrderCustom, self).write(vals)
         return res
อวตาร
ละทิ้ง
ผู้เขียน

Thanks Niyas, Can you explain how to solve my issue?

My onchange function working corroctly.But my create does not get the correct answer.

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

product_records = product_obj.search([])

for record in product_records:

vals['serial_no'] = record.serial_no

print vals['serial_no']

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

return res

this code i used in create.can you check and what is wrong in my code?

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มิ.ย. 17
4528
1
ก.ย. 17
4920
3
ต.ค. 18
4064
1
พ.ย. 17
3606
1
ส.ค. 22
7421