Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
3499 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä

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?

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
kesäk. 17
4174
1
syysk. 17
4700
3
lokak. 18
3662
1
marrask. 17
3362
1
elok. 22
6841