Community mailing list archives

community@mail.odoo.com

Re: ProgrammingError: can't adapt type 'NewId'

by
Md. Tanzilul Hasan Khan
- 03/07/2016 04:07:23

Can you please try -

'models.NewId.id' and see if that resolves the issue.

-Tanzil

On Feb 29, 2016 2:08 PM, "Jos De Graeve" <jos.degraeve@apertoso.be> wrote:
Hi Peter,

What happens, is that your onchangeQuantity() method is called with a pseudo recordset.  This means that odoo creates an in-memory representation of your data, without it actually being stored in the database.  This is because onchange can be called for records that the user is inputting in the form, but these are not yet saved.  The user might actually change his mind, and click "discard" instead of saving his data in the database.

With this pseudo recordset, you can modify recordset fields, and the updated fields will be updated in the UI, and will be saved on when the users saves his input. If i recall correctly, the onchange is also triggered on a write() to the model.

You might want to call your bom_Calc() method from the write() method instead of from an onchange method, if this matches your requirements.

Regards,
Jos



Jos De Graeve - Apertoso business ICT


Guido Gezellelaan 16 - B-9800 Deinze - Belgium
 
mail/im/skype: Jos.DeGraeve@apertoso.be - apertoso

2016-02-29 7:07 GMT+01:00 Peter Mudoko <petypi@gmail.com>:

Guys this errors frustrating me: This is my code:


Bom_Extend(models.Model):

    _name = 'mrp.bom'

    _inherit = 'mrp.bom'

    @api.onchange('quantity','x_batch')

    def onchangeQuantity(self):

   for rec in self:

       rec.x_batch=rec.quantity/rec.product_qty

self.bom_Calc()

    @api.multi

    def bom_Calc(self):

   if isinstance(self.id, models.NewId):

   self.env.cr.execute("update mrp_bom_line set x_quantityrequired=%s from mrp_bom_line x join mrp_bom s on x.bom_id=s.id where s.id=%s" , (2350,self.id))

   '''if bom_obj_ids:

for record in bom_obj_ids:

   bom_line = bom_obj.browse(record.id)

               bom_line.x_quantityrequired=bom_line.product_qty

               bom_line.x_shortage=bom_line.x_quantityrequired-bom_line.x_qoh

                       vals={'x_testing':self.id}

                       return {'value':vals}'''

I have tried even commented part same error. ANY HELP PLEASE......

Laballieds,

Nairobi:gate 256, Nairobi.

P.O.Box - 45855 -00100, Nairobi.

Tel:+254 721449067

Email petypi@gmail.com

Mobile: +254 721449067

Website www.softlinkoptions.com

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe


_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe