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

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
4766
1
9월 17
5114
3
10월 18
4203
1
11월 17
3770
1
8월 22
7616