multi department
							parent
							
								
									faf7a867de
								
							
						
					
					
						commit
						f6ff573d3a
					
				| 
						 | 
				
			
			@ -58,18 +58,6 @@
 | 
			
		|||
    <related>
 | 
			
		||||
        <field name="addresses"/>
 | 
			
		||||
        <field name="documents"/>
 | 
			
		||||
        <!--<field name="rotations" nolabel="1">-->
 | 
			
		||||
        <!--<list>-->
 | 
			
		||||
        <!--<field name="level_id" domain="[['type','=',parent.type]]"/>-->
 | 
			
		||||
        <!--<field name="from_company_id"/>-->
 | 
			
		||||
        <!--<field name="to_company_id"/>-->
 | 
			
		||||
        <!--<field name="hire_date"/>-->
 | 
			
		||||
        <!--<field name="resign_date"/>-->
 | 
			
		||||
        <!--<field name="max_cycle"/>-->
 | 
			
		||||
        <!--<field name="wage"/>-->
 | 
			
		||||
        <!--<field name="note"/>-->
 | 
			
		||||
        <!--</list>-->
 | 
			
		||||
        <!--</field>-->
 | 
			
		||||
        <field name="hd_case_staffs" readonly="1" attrs='{"invisible":[["type","=","nurse"]]}'>
 | 
			
		||||
            <list colors='{"#cfc":[["state","=","completed"]],"#f9e37d":[["state","=","in_progress"]],"#bcbbb9":[["state","=","cancelled"]],"#ACD1E9":[["state","=","waiting_payment"]],"#70DB93":[["state","=","paid"]]}'>
 | 
			
		||||
                <field name="hd_case_id"/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -80,8 +80,11 @@ class Patient(Model):
 | 
			
		|||
 | 
			
		||||
    def _get_department_names(self,ids,context={}):
 | 
			
		||||
        res={}
 | 
			
		||||
        user_id=get_active_user()
 | 
			
		||||
        set_active_user(1)
 | 
			
		||||
        for obj in self.browse(ids):
 | 
			
		||||
            res[obj.id]=','.join([dpt.name for dpt in obj.departments])
 | 
			
		||||
        set_active_user(user_id)
 | 
			
		||||
        return res
 | 
			
		||||
 | 
			
		||||
    _fields={
 | 
			
		||||
| 
						 | 
				
			
			@ -192,13 +195,19 @@ class Patient(Model):
 | 
			
		|||
    def _get_departments(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
        if res:
 | 
			
		||||
            return [res['department_id']]
 | 
			
		||||
            if res.get("department_ids"):
 | 
			
		||||
                return res['department_ids']
 | 
			
		||||
            else:
 | 
			
		||||
                return [res['department_id']]
 | 
			
		||||
        return get_model("clinic.department").search([])
 | 
			
		||||
 | 
			
		||||
    def _get_department(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
        if res:
 | 
			
		||||
            return res['department_id']
 | 
			
		||||
            if res.get("department_ids"):
 | 
			
		||||
                return res['department_ids'][0]
 | 
			
		||||
            else:
 | 
			
		||||
                return res['department_id']
 | 
			
		||||
 | 
			
		||||
    def _get_branch(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
| 
						 | 
				
			
			@ -207,9 +216,16 @@ class Patient(Model):
 | 
			
		|||
 | 
			
		||||
    def _get_default_location(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
        code=''
 | 
			
		||||
        if res:
 | 
			
		||||
            dpt=get_model("clinic.department").browse(res['department_id'])
 | 
			
		||||
            return dpt.code
 | 
			
		||||
            dpt_ids=[]
 | 
			
		||||
            if res.get("department_ids"):
 | 
			
		||||
                dpt_ids=res['department_ids']
 | 
			
		||||
            else:
 | 
			
		||||
                dpt_ids=res['department_id']
 | 
			
		||||
            dpts=get_model("clinic.department").browse(dpt_ids)
 | 
			
		||||
            code=','.join([dpt.code for dpt in dpts])
 | 
			
		||||
        return code
 | 
			
		||||
 | 
			
		||||
    _defaults={
 | 
			
		||||
        #"number": _get_number,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,7 +33,10 @@ class ReportCycleItem(Model):
 | 
			
		|||
            if not branch_id:
 | 
			
		||||
                branch_id=res['branch_id']
 | 
			
		||||
            if not department_id:
 | 
			
		||||
                department_id=res['department_id']
 | 
			
		||||
                if res.get("department_ids"):
 | 
			
		||||
                    department_id=res['department_ids'][0]
 | 
			
		||||
                else:
 | 
			
		||||
                    department_id=res['department_id']
 | 
			
		||||
        res={
 | 
			
		||||
            'date': date,
 | 
			
		||||
            'date_from': date_from,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -33,12 +33,15 @@ class ReportDiscontinuePatient(Model):
 | 
			
		|||
        department_id=defaults.get('department_id',None)
 | 
			
		||||
        if department_id:
 | 
			
		||||
            department_id=int(department_id)
 | 
			
		||||
        select_apt=get_model('select.company').get_select()
 | 
			
		||||
        if select_apt:
 | 
			
		||||
        select_dpt=get_model('select.company').get_select()
 | 
			
		||||
        if select_dpt:
 | 
			
		||||
            if not branch_id:
 | 
			
		||||
                branch_id=select_apt['branch_id']
 | 
			
		||||
                branch_id=select_dpt['branch_id']
 | 
			
		||||
            if not department_id:
 | 
			
		||||
                department_id=select_apt['department_id']
 | 
			
		||||
                if select_dpt.get('department_ids'):
 | 
			
		||||
                    department_id=select_dpt['department_ids'][0]
 | 
			
		||||
                else:
 | 
			
		||||
                    department_id=select_dpt['department_id']
 | 
			
		||||
        res={
 | 
			
		||||
            'date': date,
 | 
			
		||||
            'date_from': date_from,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -38,7 +38,10 @@ class ReportHDCaseSummary(Model):
 | 
			
		|||
    def _get_department(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
        if res:
 | 
			
		||||
            return res['department_id']
 | 
			
		||||
            if res.get("department_ids"):
 | 
			
		||||
                return res['department_ids'][0]
 | 
			
		||||
            else:
 | 
			
		||||
                return res['department_id']
 | 
			
		||||
 | 
			
		||||
    _defaults={
 | 
			
		||||
        'date': lambda *a: time.strftime("%Y-%m-%d"),        
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,6 +41,9 @@ class ReportMedicalSummary(Model):
 | 
			
		|||
            branch_id=int(branch_id or "0")
 | 
			
		||||
        department_id=defaults.get('department_id',None)
 | 
			
		||||
        if not department_id:
 | 
			
		||||
            if select_dpt.get('department_ids'):
 | 
			
		||||
                department_id=select_dpt['department_ids'][0]
 | 
			
		||||
            else:
 | 
			
		||||
                department_id=select_dpt['department_id']
 | 
			
		||||
        else:
 | 
			
		||||
            department_id=int(department_id or "0") 
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,12 +32,15 @@ class ReportRecentPatient(Model):
 | 
			
		|||
        department_id=defaults.get('department_id',None)
 | 
			
		||||
        if department_id:
 | 
			
		||||
            department_id=int(department_id)
 | 
			
		||||
        select_apt=get_model('select.company').get_select()
 | 
			
		||||
        if select_apt:
 | 
			
		||||
        select_dpt=get_model('select.company').get_select()
 | 
			
		||||
        if select_dpt:
 | 
			
		||||
            if not branch_id:
 | 
			
		||||
                branch_id=select_apt['branch_id']
 | 
			
		||||
                branch_id=select_dpt['branch_id']
 | 
			
		||||
            if not department_id:
 | 
			
		||||
                department_id=select_apt['department_id']
 | 
			
		||||
                if select_dpt.get('department_ids'):
 | 
			
		||||
                    department_id=select_dpt['department_ids'][0]
 | 
			
		||||
                else:
 | 
			
		||||
                    department_id=select_dpt['department_id']
 | 
			
		||||
        res={
 | 
			
		||||
            'date': date,
 | 
			
		||||
            'date_from': date_from,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -175,7 +175,15 @@ class SelectCompany(Model):
 | 
			
		|||
        user=get_model("base.user").browse(user_id)
 | 
			
		||||
        dpt=user.department_id
 | 
			
		||||
        if not dpt:
 | 
			
		||||
            return {}
 | 
			
		||||
            dpts=user.department_profile_id.departments
 | 
			
		||||
            if dpts:
 | 
			
		||||
                res={
 | 
			
		||||
                    'department_ids': [dpt.id for dpt in dpts],
 | 
			
		||||
                    'branch_id': dpts[0].branch_id.id, #XXX
 | 
			
		||||
                }
 | 
			
		||||
                return res
 | 
			
		||||
            else:
 | 
			
		||||
                return {}
 | 
			
		||||
        department_id=dpt.id
 | 
			
		||||
        branch_id=dpt.branch_id.id
 | 
			
		||||
        return {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,8 +102,11 @@ class Staff(Model):
 | 
			
		|||
 | 
			
		||||
    def _get_department_names(self,ids,context={}):
 | 
			
		||||
        res={}
 | 
			
		||||
        user_id=get_active_user()
 | 
			
		||||
        set_active_user(1)
 | 
			
		||||
        for obj in self.browse(ids):
 | 
			
		||||
            res[obj.id]=','.join([dpt.name for dpt in obj.departments])
 | 
			
		||||
        set_active_user(user_id)
 | 
			
		||||
        return res
 | 
			
		||||
 | 
			
		||||
    _fields={
 | 
			
		||||
| 
						 | 
				
			
			@ -189,14 +192,32 @@ class Staff(Model):
 | 
			
		|||
    def _get_departments(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
        if res:
 | 
			
		||||
            return [res['department_id']]
 | 
			
		||||
            if res.get("department_ids"):
 | 
			
		||||
                return res['department_ids']
 | 
			
		||||
            else:
 | 
			
		||||
                return [res['department_id']]
 | 
			
		||||
        return get_model("clinic.department").search([])
 | 
			
		||||
 | 
			
		||||
    def _get_default_location(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
        code=''
 | 
			
		||||
        if res:
 | 
			
		||||
            dpt=get_model("clinic.department").browse(res['department_id'])
 | 
			
		||||
            return dpt.code
 | 
			
		||||
            dpt_ids=[]
 | 
			
		||||
            if res.get("department_ids"):
 | 
			
		||||
                dpt_ids=res['department_ids']
 | 
			
		||||
            else:
 | 
			
		||||
                dpt_ids=res['department_id']
 | 
			
		||||
            dpts=get_model("clinic.department").browse(dpt_ids)
 | 
			
		||||
            code=','.join([dpt.code for dpt in dpts])
 | 
			
		||||
        return code
 | 
			
		||||
 | 
			
		||||
    def _get_department(self,context={}):
 | 
			
		||||
        res=get_model('select.company').get_select()
 | 
			
		||||
        if res:
 | 
			
		||||
            if res.get("department_ids"):
 | 
			
		||||
                return res['department_ids'][0]
 | 
			
		||||
            else:
 | 
			
		||||
                return res['department_id']
 | 
			
		||||
 | 
			
		||||
    _defaults={
 | 
			
		||||
        'active': True,
 | 
			
		||||
| 
						 | 
				
			
			@ -207,6 +228,7 @@ class Staff(Model):
 | 
			
		|||
        "company_id": lambda *a: get_active_company(),
 | 
			
		||||
        'branch_id': _get_branch,
 | 
			
		||||
        'departments': _get_departments,
 | 
			
		||||
        'department_id': _get_department,
 | 
			
		||||
        'location': _get_default_location,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,6 +31,7 @@ class StaffRotation(Model):
 | 
			
		|||
        'company_id': fields.Many2One("company","Company"),
 | 
			
		||||
        'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'),
 | 
			
		||||
        'staff_name': fields.Char("Staff Name", function="_get_all",function_multi=True,store=True), #XXX
 | 
			
		||||
        'department_id': fields.Many2One("clinic.department", "Department"), #XXX
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    _defaults={
 | 
			
		||||
| 
						 | 
				
			
			@ -57,14 +58,12 @@ class StaffRotation(Model):
 | 
			
		|||
    def create(self,vals,**kw):
 | 
			
		||||
        id=super().create(vals,**kw)
 | 
			
		||||
        self.function_store([id])
 | 
			
		||||
        #XXX
 | 
			
		||||
        get_model("clinic.staff").function_store([vals['staff_id']])
 | 
			
		||||
        return id
 | 
			
		||||
 | 
			
		||||
    def write(self,ids,vals,**kw):
 | 
			
		||||
        super().write(ids,vals,**kw)
 | 
			
		||||
        self.function_store(ids)
 | 
			
		||||
        #XXX
 | 
			
		||||
        staff_ids=[]
 | 
			
		||||
        for obj in self.browse(ids):
 | 
			
		||||
            staff_ids.append(obj.staff_id.id)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -50,7 +50,10 @@ class VisitBoard(Model):
 | 
			
		|||
            if not branch_id:
 | 
			
		||||
                branch_id=res['branch_id']
 | 
			
		||||
            if not department_id:
 | 
			
		||||
                department_id=res['department_id']
 | 
			
		||||
                if res.get('department_ids'):
 | 
			
		||||
                    department_id=res['department_ids'][0]
 | 
			
		||||
                else:
 | 
			
		||||
                    department_id=res['department_id']
 | 
			
		||||
        res={
 | 
			
		||||
            'date': date,
 | 
			
		||||
            'date_from': date_from,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue