Skip to Content
Menu
This question has been flagged
2 Replies
3008 Views

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 ?


Avatar
Discard
Best Answer

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
Avatar
Discard
Author

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 Replies Views Activity
1
Jun 17
3757
1
Sep 17
4278
3
Oct 18
3206
1
Nov 17
2960
1
Aug 22
6317