跳至內容
選單
此問題已被標幟
2 回覆
4377 瀏覽次數

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?

相關帖文 回覆 瀏覽次數 活動
1
6月 17
5052
1
9月 17
5452
3
10月 18
4479
1
11月 17
4008
1
8月 22
7996