merge staff

conv_bal
watcha.h@almacom.co.th 2015-06-29 11:39:12 +07:00
parent 442f4e4e08
commit 391721bb19
4 changed files with 75 additions and 1 deletions

View File

@ -0,0 +1,8 @@
<record model="action">
<field name="view_cls">form_view</field>
<field name="model">clinic.setting</field>
<field name="active_id">1</field>
<field name="view_xml">clinic_merge_staff</field>
<field name="menu">clinic_menu</field>
</record>

View File

@ -52,12 +52,13 @@
<item string="RD Shop Expense" action="clinic_report_shop"/>
</item>
<item string="Settings" perm="clinic_settings">
<item string="Clinic Settings" action="clinic_setting"/>
<item string="Merge Staff" action="clinic_merge_staff"/>
<item string="Titles" action="clinic_name_title" perm="clinic_name_title"/>
<item string="Branches" action="clinic_branch" perm="clinic_branch"/>
<item string="Departments" action="clinic_department"/>
<item string="Department Products" action="clinic_department_product"/>
<item string="Hospitals" action="clinic_hospital"/>
<item string="Nationalities" action="clinic_nation"/>
<item string="Clinic Settings" action="clinic_setting"/>
</item>
</menu>

View File

@ -0,0 +1,11 @@
<form model="clinic.setting" title="Merge Staff">
<separator string="1. Merge All Duplicate Staff"/>
<button string="Merge All" method="merge_staff" size="large" type="primary" icon="arrow-right"/>
<separator string="2. Merge Staff"/>
<field name="staff_from_id"/>
<field name="staff_to_id"/>
<newline/>
<button string="Merge" method="merge_staff_from" size="large" type="default" icon="arrow-right"/>
<foot replace="1">
</foot>
</form>

View File

@ -63,6 +63,8 @@ class ClinicSetting(Model):
'helper_categ_id': fields.Many2One("clinic.staff.categ","Helper Category"),
'base_salary_day': fields.Float("Base Salary Day"),
'next_date': fields.DateTime("Next Gen"),
'staff_from_id': fields.Many2One("clinic.staff","Staff From"),
'staff_to_id': fields.Many2One("clinic.staff","Staff To"),
}
_defaults={
@ -264,6 +266,58 @@ class ClinicSetting(Model):
print("z"*50)
print("Done!")
def merge_staff_from(self,ids,context={}):
user_id=get_active_user()
if user_id !=1:
print("Only admin!!")
return
obj=self.browse(1)
if not obj.staff_from_id:
raise Exception("Please Enter Staff From")
if not obj.staff_to_id:
raise Exception("Please Enter Staff To")
if obj.staff_from_id.type != obj.staff_to_id.type:
raise Exception("Staff Type not the same!")
db=get_connection()
# update FROM to TO
if obj.staff_from_id.type=='nurse':
for rec in get_model("clinic.cycle.item.line").search_browse([['nurse_id','=',obj.staff_from_id.id]]):
rec.write({
'nurse_id': obj.staff_to_id.id,
})
dom=[
['type','=','nurse'],
['staff_id','=',obj.staff_from_id.id],
]
for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
lcost.write({
'staff_id': obj.staff_to_id.id,
})
elif obj.staff_from_id.type=='doctor':
for rec in get_model("clinic.hd.case.staff").search_browse([['staff_id','=',obj.staff_from_id.id]]):
rec.write({
'staff_id': obj.staff_to_id.id,
})
hdcase=rec.hd_case_id
vs=hdcase.visit_id
db.execute("update clinic_visit set doctor_id=%s where id=%s",obj.staff_to_id.id,vs.id)
pt=hdcase.patient_id
db.execute("update clinic_patient set doctor_id=%s where id=%s",obj.staff_to_id.id,pt.id)
citem=hdcase.cycle_item_id
dom=[
['type','=','doctor'],
['staff_id','=',obj.staff_from_id.id],
['labor_cost_id.cycle_item_id','=',citem.id],
]
for lcost in get_model("clinic.labor.cost.line").search_browse(dom):
lcost.write({
'staff_id': obj.staff_to_id.id,
})
#del_staff=obj.staff_from_id.name
# delete staff
get_model('clinic.staff').delete([obj.staff_from_id.id])
print("Done!")
def del_duplicate_staff(self,ids,context={}):
user_id=get_active_user()
if user_id !=1: