跳至内容
菜单
此问题已终结
2 回复
2944 查看

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.

形象
丢弃
最佳答案

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

形象
丢弃
编写者

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

编写者

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

最佳答案

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
    

形象
丢弃
相关帖文 回复 查看 活动
0
11月 20
2296
4
8月 18
15826
2
5月 24
1749
1
11月 22
2593
1
9月 22
1986