Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
2151 มุมมอง

I have this little function

@api.constrains('product_qty')
def _product_qty(self):
for r in self:
if r.product_qty > 30000:
raise UserError('You cannot Manufacture more than 30 thousand Kilos')

I am inheriting mrp.production and working with the product_qty field..
How can I make this function apply to only certain specific users? certain users cannot manufacture more than 30 thousand kilos, and others can.
Odoo 10 community, thank you.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

You need to specify which all users need and the restriction and check that as well.

If you have added that configuration in the res.partner model, then you can check it with self.env.user.partner_id(returns the current logged in user’s partner) has that option. 

If you are using user groups, then you can check with self.env.user.has_group(module_name.external_id)

If you are enabling that in settings, you can use

self.env['ir.config_parameter'].sudo().get_param('module_name.field_name') and check if the current user’s partner_id is present in that.

อวตาร
ละทิ้ง
ผู้เขียน

Thanks man!

คำตอบที่ดีที่สุด

Hi,

You can create a user group from the code and then modify the function as follows:

if self.env.user.has_group('module.restrict_production') and r.product_qty > 30000:

Here in the if condition an extra check is added to check whether the user is part of this group, then only if user is part of this group, the validation will be done.


Thanks

อวตาร
ละทิ้ง
ผู้เขียน

In the group do I have to give it full access to make it work? something like this: <field name="implied_ids" eval="[(4,ref('base.group_user'))]"/> or is it not necessary?

once you created a user group, just add necessary users to this group from the user interface

ผู้เขียน

Thanks!

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ย. 15
5566
2
ก.ย. 22
3822
2
เม.ย. 21
4868
0
มี.ค. 19
2610
1
มี.ค. 17
7495