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
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
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.
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
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.
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!
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.
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Nov 24
|
18021 | ||
|
1
Sep 23
|
1208 | ||
|
3
May 23
|
4095 | ||
|
7
Apr 23
|
47101 | ||
Barcode scanner from mobile
Solved
|
|
1
Dec 22
|
6438 |