تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
4775 أدوات العرض

Hello, please help. I wanted to filter the drop down list of many2one field base in the current user. My objective is, inside the sales order form, i've added a field called salesperson_code which is a many2one field where the source is a customize table I have created:

class SalesPersonCode(models.Model):
_name = 'sale.person.code'
_rec_name = 'salesperson_code'

salesperson = fields.Many2one('res.users', string='Salesman')
salesperson_code = fields.Char(string='Code')
Added field in sale.order table:

class SalesSampleCode(models.Model):
_inherit = 'sale.order'
    salesperson_code = fields.Many2one('sale.person.code', string='Salesman Code')

XML code:

<xpath expr="//field[@name='payment_term_id']" position="after">
<field name="salesperson_code" options="{'no_create': True, 'no_create_edit':True}"/>
</xpath>

Now I only want the many2one drop down, to list the salesman code that is assigned to a particular salesman, so my filter should be domain = [( 'salesperson' , '=', user.id )]. What is the right way to implement this.?

I was able to make it work using onchange but what I really want is, if he/she create or edit the form, it should be the right salesman code be given to the drop down list of the many2one field. Any help will be high appreciated. Thank you.

الصورة الرمزية
إهمال
أفضل إجابة

Hi,

I suggest you to use ir.rule, record rules are conditions that records must satisfy for an operation (create, read, write or delete) to be allowed. 

See the example in the below code : 

<record id="salesperson_groups_rule" model="ir.rule">
<field
name="name">Sales person: Access own sales person only</field>
<field
name="model_id" ref="model_sale_person_code"/>
<field
name="domain_force">[('salesperson', '=', user.id)]
</field>
</record>

Best regards!

الصورة الرمزية
إهمال
الكاتب

Best solution. Thank you very much brother Sylvain. God bless.

You're welcome! God bless you!

أفضل إجابة

Right answer

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
أغسطس 25
1629
3
يوليو 24
4481
3
نوفمبر 20
4236
1
نوفمبر 18
5752
5
فبراير 18
4836