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

Below is Error Message i got on clicking Confirm Sale button

File "/home/Desktop/odoo-10.0/custom_addons/pharmacy/pharmacy.py", line 22, in action_confirm
    res = super(SaleOrder, self).action_confirm()
TypeError: super(type, obj): obj must be an instance or subtype of type


My code below
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools.translate import _

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    patient = fields.Many2one('one.clinic.patient', string='Patient')
    doctor = fields.Many2one('one.clinic.doctor', string='Doctor')


class Picking(models.Model):
    _inherit = 'stock.picking'

    patient = fields.Many2one('one.clinic.patient', string='Patient', readonly=False)
    doctor = fields.Many2one('one.clinic.doctor', string='Doctor', readonly=False)

    @api.multi
    def action_confirm(self):
        res = super(SaleOrder, self).action_confirm()
        for rec in self:
            rec.picking_ids.write({'patient': rec.patient, 'doctor': rec.doctor})
        return res

  


            
Avatar
Discard
Best Answer

First of all put method in above object (sale.order) class. Cause that is method which will be called when you click on Confirm button of Sale order. So the error you raised will be resolve.

About your query : How can I iterate rec.picking_ids in for loop to write values.

Solution > try below code

@api.multi

def action_confirm(self):

    res = super(SaleOrder, self).action_confirm()

    for rec in self:

        for pick_rec in rec.picking_ids:

            pick_rec.write({

                                        'sale_license': rec.sale_license

            })

    return res

Thanks!

Avatar
Discard
Author

Hi Dipak,

I got these errors after trying your solution

Traceback (most recent call last):

File "/home/Desktop/odoo-10.0/odoo/http.py", line 642, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/home/Desktop/odoo-10.0/odoo/http.py", line 684, in dispatch

result = self._call_function(**self.params)

File "/home/Desktop/odoo-10.0/odoo/http.py", line 334, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/home/Desktop/odoo-10.0/odoo/service/model.py", line 101, in wrapper

return f(dbname, *args, **kwargs)

File "/home/Desktop/odoo-10.0/odoo/http.py", line 327, in checked_call

result = self.endpoint(*a, **kw)

File "/home/Desktop/odoo-10.0/odoo/http.py", line 942, in __call__

return self.method(*args, **kw)

File "/home/Desktop/odoo-10.0/odoo/http.py", line 507, in response_wrap

response = f(*args, **kw)

File "/home/Desktop/odoo-10.0/addons/web/controllers/main.py", line 899, in call_button

action = self._call_kw(model, method, args, {})

File "/home/Desktop/odoo-10.0/addons/web/controllers/main.py", line 887, in _call_kw

return call_kw(request.env[model], method, args, kwargs)

File "/home/Desktop/odoo-10.0/odoo/api.py", line 689, in call_kw

return call_kw_multi(method, model, args, kwargs)

File "/home/Desktop/odoo-10.0/odoo/api.py", line 680, in call_kw_multi

result = method(recs, *args, **kwargs)

File "/home/Desktop/odoo-10.0/custom_addons/pharmacy/pharmacy.py", line 19, in action_confirm

'patient': rec.patient

File "/home/Desktop/odoo-10.0/addons/stock/models/stock_picking.py", line 423, in write

res = super(Picking, self).write(vals)

File "/home/Desktop/odoo-10.0/addons/mail/models/mail_thread.py", line 274, in write

result = super(MailThread, self).write(values)

File "/home/Desktop/odoo-10.0/odoo/models.py", line 3576, in write

self._write(old_vals)

File "/home/Desktop/odoo-10.0/odoo/models.py", line 3677, in _write

cr.execute(query, params + (sub_ids,))

File "/home/Desktop/odoo-10.0/odoo/sql_db.py", line 154, in wrapper

return f(self, *args, **kwargs)

File "/home/Desktop/odoo-10.0/odoo/sql_db.py", line 231, in execute

res = self._obj.execute(query, params)

ProgrammingError: can't adapt type 'one.clinic.patient'

Best Answer

Hello Sputy,

You have must write the def method inside the Saleorder class.I think this the problem.

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    patient = fields.Many2one('one.clinic.patient', string='Patient')
    doctor = fields.Many2one('one.clinic.doctor', string='Doctor')


    @api.multi
    def action_confirm(self):
        res = super(SaleOrder, self).action_confirm()
        for rec in self:
            rec.picking_ids.write({'patient': rec.patient, 'doctor': rec.doctor})
        return res




class Picking(models.Model):
    _inherit = 'stock.picking'

    patient = fields.Many2one('one.clinic.patient', string='Patient', readonly=False)
    doctor = fields.Many2one('one.clinic.doctor', string='Doctor', readonly=False)


Thank You.

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
18019
1
Sep 23
1203
3
May 23
4091
7
Apr 23
47092
1
Dec 22
6434