select branch

conv_bal
watcha.h@almacom.co.th 2015-03-25 12:22:10 +07:00
parent a69df4f939
commit 0404d848d6
4 changed files with 36 additions and 3 deletions

View File

@ -1,5 +1,7 @@
<inherit model="select.company" inherit="select_company"> <inherit model="select.company" inherit="select_company">
<field name="company" position="after"> <field name="company" position="after">
<field name="department" selection="get_departments"/> <field name="branch" selection="get_branch" attrs='{"invisible":[["show_branch","=",false]]}'/>
<field name="department" selection="get_departments" attrs='{"invisible":[["show_branch","=",true]]}'/>
<field name="show_branch" invisible="1"/>
</field> </field>
</inherit> </inherit>

View File

@ -1,7 +1,9 @@
<inherit model="base.user" inherit="user_form"> <inherit model="base.user" inherit="user_form">
<field name="pin_code" position="after"> <field name="pin_code" position="after">
<separator string="Clinic"/>
<field name="department_profile_id"/> <field name="department_profile_id"/>
<field name="branch_id"/>
<field name="old_profile_id"/> <field name="old_profile_id"/>
<field name="branch_id"/>
<field name="select_branch"/>
</field> </field>
</inherit> </inherit>

View File

@ -7,6 +7,7 @@ class User(Model):
'department_id': fields.Many2One("clinic.department","Current Department"), 'department_id': fields.Many2One("clinic.department","Current Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"), 'branch_id': fields.Many2One("clinic.branch","Branch"),
'old_profile_id': fields.Many2One('profile', "Old Profile"), 'old_profile_id': fields.Many2One('profile', "Old Profile"),
'select_branch': fields.Boolean("Can Change Branch"),
} }
User.register() User.register()

View File

@ -5,6 +5,8 @@ class SelectCompany(Model):
_inherit="select.company" _inherit="select.company"
_fields={ _fields={
"department": fields.Selection([],"Department"), "department": fields.Selection([],"Department"),
"branch": fields.Selection([],"Branch"),
"show_branch": fields.Boolean("Show Branch"),
} }
def _get_department(self,context={}): def _get_department(self,context={}):
@ -13,10 +15,30 @@ class SelectCompany(Model):
dpt_name=user.department_id.name or "" dpt_name=user.department_id.name or ""
return dpt_name return dpt_name
def _get_branch(self,context={}):
user_id=get_active_user()
user=get_model("base.user").browse(user_id)
branch_name=user.branch_id.name or ""
return branch_name
def _get_show_branch(self,context={}):
user_id=get_active_user()
user=get_model("base.user").browse(user_id)
return user.select_branch or False
_defaults={ _defaults={
'department': _get_department, 'department': _get_department,
'branch': _get_branch,
'show_branch': _get_show_branch,
} }
def get_branch(self,context={}):
user_id=get_active_user()
set_active_user(1)
res=get_model("clinic.branch").search_read([],["name"])
set_active_user(user_id)
return [(r["name"],r["name"]) for r in res]
def get_departments(self,context={}): def get_departments(self,context={}):
user_id=get_active_user() user_id=get_active_user()
set_active_user(1) set_active_user(1)
@ -144,7 +166,13 @@ class SelectCompany(Model):
user=get_model('base.user').browse(user_id) user=get_model('base.user').browse(user_id)
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
department_name='' department_name=''
if obj.department: if obj.branch:
for branch in get_model("clinic.branch").search_browse([["name","=",obj.branch]]):
user=get_model("base.user").browse(user_id)
user.write({
'branch_id': branch.id,
})
elif obj.department:
department_name=obj.department department_name=obj.department
# set to main profile of that user # set to main profile of that user
for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]): for dpt in get_model("clinic.department").search_browse([["name","=",obj.department]]):