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

Scenario.
Sales Team, Purchase Team, Manufacturing Team. (imagine each is a user)

i want, receipts to validated (allowed to validated) by only purchase guy, ideally rest should be able to view, but shouldn't be able to validate.
similarly
delivery orders (transfers) allowed to be validated by sales team.
internal transfers (should be allowed to validated by manufacturing team/user.


any ideas / psudo steps will help, thanks, haseeb.

Avatar
Discard
Best Answer

Hi Haseeb,

You can validate the button_validate method and check for user groups and raise a warning if the user not belongs to that group. For example for the purchase transfer Try this: 

def button_validate(self):
if self.picking_type_id.code == 'incoming':
if not self.env.user.has_group('purchase.group_purchase_user'):
raise ValidationError(_('You are not allowed to validate this picking/transfer'))

res = super(StockPicking, self).button_validate()
return res

For other transfer like sales and internal transfer use respective picking type code and user groups for checking the conditions and raise warning

Hope this will help you

Thank you

Avatar
Discard
Author

Hi Mehjabin.
1- thanks for guidance, really means a lot.
2- while trying doing that. below is my sample code from (models.py) and module is loaded but function is not getting called. unable to see any log msg in terminal. few more suggestions will help me go through.(thanks in advance)

from odoo import models, fields, api, loglevels

class rhein_validator(models.Model):
_name = 'rhein_validator.rhein_validator'
_description = 'rhein_validator.rhein_validator'
_inherit = 'stock.picking'

@api.multi
def button_validate(self):
loglevels.LOG_WARNING("=======MY METHOD RUNNING AS WELL========")
if self.picking_type_id.code == 'incoming':
if not self.env.user.has_group('purchase.group_purchase_user'):
raise ValidationError(_('You are not authorized to validate this picking'))
res = super(rhein_validator, self).button_validate()
return res

Hi,
In your class definition try as this by removing _name :
class rhein_validator(models.Model):
_inherit = 'stock.picking'
// Add function here

Author

final code, that worked, hopefully it might help someone in same trouble. cheers.
==============================

# -*- coding: utf-8 -*-

# from xml.dom import ValidationErr
from odoo import models, fields, api
from odoo import _
from odoo.exceptions import ValidationError

class rhein_validator(models.Model):
_inherit = 'stock.picking'
def button_validate(self):
# logging.WARNING('THIS IS A WARNING MESSAGE'
print ("THIS IS A TEST MSG")
if self.picking_type_id.code == 'incoming':
if not self.env.user.has_group('purchase.group_purchase_user'):
raise ValidationError(_('You are not authorized to validate this picking'))
res = super(rhein_validator, self).button_validate()
return res

Best Answer

You can override button_validate method of stock picking where you can check if user belongs to any of the above group and operation type. Based on that, you can raise warning or can call super method.

Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat 380015
    

Avatar
Discard
Related Posts Replies Views Activity
0
Nov 20
1548
4
Aug 18
9830
2
May 24
456
1
Nov 22
1515
1
Sep 22
1240