This question has been flagged
5 Replies
3317 Views
What am i doing wrongly please? Each time i clicked Confirm Sale Button i get this below error.
My objective is to pass the sale_license value to stock.picking model when sale is confirmed.
I will sincerely appreciate your guide.


########### Error Message #########
res = Super(SaleOrder, self).action_confirm() NameError: global name 'Super' is not defined

######### 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'
sale_license = fields.Many2one('sale.license', string='License', required=True)
 
class Picking(models.Model):
_inherit = 'stock.picking'
sale_license = fields.Many2one('sale.license', string='License', readonly=True)

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



Avatar
Discard
Best Answer

If you call SUPER, you are calling an identical method from the model/class you are inheriting.

In your code, you are inheriting stock.picking

You need to write your code like this:

res = Super(Picking, self).action_confirm()

This will call the action_confirm method of stock.picking.

If you want to run the sale.order action_confirm, your code needs to be in the SaleOrder class and look like this:

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

"Picking" and "SaleOrder" are the names of YOUR classes.


Avatar
Discard
Best Answer

Hello Sputy,

Just use small letter in super keyword call. you used Super (S is capital)

So instead of res = Super(SaleOrder, self).action_confirm() 
kindly use  res = super(SaleOrder, self).action_confirm()

And one more thing you are writing your values ( rec.picking_ids) directly in this will raise an error of single tone because multiple records will be there if Sale order have multiple picking.so kindly iterate your rec.picking_ids in for loop and then write your value.

Hope this will definitely help you !

Thanks,

Dipak

Avatar
Discard
Author

Hi Dipak and other helpers,

Thanks for the guide so far.

How can I iterate rec.picking_ids in for loop to write values.

Am still learning please.

Author

Hello Dipak,

I got this error below after changing Super to super

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

TypeError: super(type, obj): obj must be an instance or subtype of type

First of all put this 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!

Author Best Answer

Hi Dipak and other helpers,

Thanks for the guide so far.

How can I iterate rec.picking_ids in for loop to write values.

Am still learning please.

Avatar
Discard