Skip to Content
Menu
This question has been flagged
1 Reply
2470 Views

Hi

I have two modules

when i create new department and link it with user in AdministrativeUnits module

then , i create a record in bids_screen module it returns the current user
but i need to return the departments associated with the current user who is creating the record in dep field

this default=lambda self:self.env.user.employee_ids.department_id worked for me once to return department but if i have 5 departments but only 3 associated with user 'Ahmed' 
when ahmed create record need only the 3 departments to be shown in dropdown list in dep field


need hint

thanks :)


first one iam creating in many fields but those in my main question


class bids_screen(models.Model):
_name = 'bid.bids_screen'

user = fields.Many2one('res.users', string='Related User',
default=lambda self: self.env.user)

dep = fields.Many2one('bid.administrative_units', string='Administrative unit',default=lambda self:self.env.user.employee_ids.department_id
)

XML:-

<record id="bids_screen_form" model="ir.ui.view">
<
field name="bids screen form"></field>
<
field name="model">bid.bids_screen</field>
<
field name="arch" type="xml">
<
form string="Bids Screen">
 
               <sheet>
                  <field name="user"/>
                     <field name="dep"/>
            </sheet>
</
form>
</
field>
</
record>


second module:-



class AdministrativeUnits(models.Model):
_name = 'bid.administrative_units'
_inherit = 'hr.department'
_rec_name = 'name'

     user = fields.Many2one('res.users', string='Related Users')

Xml:-

<record id="administrative_units_screen_tree" model="ir.ui.view">
<field name="Administrative Units Screen"></field>
<field name="model">bid.administrative_units</field>
<field name="arch" type="xml">
<tree string="Administrative Units Screen">

<field name="name"/>
<field name="manager_id"/>
<field name="parent_id"/>
<field name="user"/>


</tree>
</field>
</record>



Avatar
Discard
Author

system doesn't allow me to edit

last xml not tree, teh same but form view

thanks

Related Posts Replies Views Activity
1
Dec 24
22
1
Nov 24
52
2
Jul 24
13934
2
Mar 24
574
0
Feb 24
1201