conv_bal
watcha.h@almacom.co.th 2014-12-21 17:11:22 +07:00
parent 3c4cdfa5ee
commit dbe2a6d0fd
10 changed files with 175 additions and 147 deletions

View File

@ -2,8 +2,8 @@
<field name="payment_terms" position="after">
<newline/>
<separator string="Clinic"/>
<field name="account_fee_id" />
<field name="account_mdc_id" />
<field name="account_service_id" />
<field name="account_fee_id" attrs='{"required":[["type","=","org"]]}'/>
<field name="account_mdc_id" attrs='{"required":[["type","=","org"]]}'/>
<field name="account_service_id" attrs='{"required":[["type","=","org"]]}'/>
</field>
</inherit>

View File

@ -3,7 +3,7 @@
<field name="state"/>
<button string="Options" dropdown="1">
<item string="New Dialyzer" method="new_dialyzer" states="draft,waiting_treatment"/>
<item string="To Draft" method="to_draft" states="completed,cancelled"/>
<item string="To Draft" method="to_draft" states="paid,waiting_payment,completed,cancelled"/>
</button>
</head>
<group form_layout="stacked" attrs='{"readonly":[["state","=","completed"]]}'>
@ -64,11 +64,13 @@
</field>
</group>
<group span="8" form_layout="stacked">
<!--
<field name="invoice_policy" onchange="onchange_policy"/>
<newline/>
<group attrs='{"invisible":[["invoice_policy","in",["","fee"]]]}'>
<field name="invoice_option"/>
</group>
-->
</group>
<group span="4" columns="1">
<field name="total_amount"/>
@ -115,9 +117,10 @@
<foot>
<button string="Start" type="success" icon="arrow-right" method="do_treatment" states="draft,waiting_treatment"/>
<button string="Done" type="success" icon="ok" method="done" states="in_progress"/>
<button string="Discontinue" type="danger" icon="remove" action="clinic_hd_case_distcont" states="in_progress"/>
<button string="Claim Expenses" type="default" icon="arrow-right" states="completed" method="request_fee" attrs='{"invisible": [["req_fee","=",1]]}'/>
<button string="Pay" type="success" icon="ok" method="pay" states="completed" attrs='{"invisible": [["req_fee","=",1]]}'/>
<button string="Discard" type="danger" icon="remove" action="clinic_hd_case_distcont" states="in_progress"/>
<button string="Claim Expense" type="default" icon="arrow-right" states="completed" method="request_fee" attrs='{"invisible":[["req_fee","=",1]]}'/>
<button string="Pay" type="success" icon="ok" method="pay" states="completed" attrs='{"invisible":[["req_fee","=",0]]}'/>
</foot>
<related>
<field name="invoices" click_action="view_invoice">

View File

@ -2,8 +2,6 @@
<field name="hd_case_id" invisible="1"/>
<field name="pay_amount" onchange="onchange_amount"/>
<newline/>
<field name="fee" readonly="1"/>
<newline/>
<field name="to_pay" readonly="1"/>
<newline/>
<group attrs='{"invisible":[["pay_amount","=",0]]}'>

View File

@ -2,6 +2,8 @@
<field name="file" span="3" required="1"/>
<field name="type_id" span="3"/>
<!--<field name="date" span="3" mode="month" onchange="onchange_date"/>-->
<newline/>
<button string='Match' type="success" size="small" icon="ok" method="match_invoice"/>
<group span="6" columns="1">
<button string='Match' span="2" type="success" size="small" icon="ok" method="match_invoice"/>
<button string='Make A Payment' span="2" type="default" size="small" icon="arrow-right" method="match_invoice"/>
</group>
</form>

View File

@ -1,12 +1,8 @@
<inherit model="settings" inherit="fin_settings">
<field name="retained_earnings_account_id" position="after">
<field name="rounding_account_id" position="after">
<separator string="Clinic"/>
<field name="ar_sc_id"/>
<field name="ap_sc_id"/>
<field name="ar_uc_id"/>
<field name="ap_uc_id"/>
<field name="ap_nurse_id"/>
<field name="ap_doctor_id"/>
<field name="hospital_code"/>
<field name="cash_account_id" domain="[['type','!=','view']]"/>
<field name="income_account_id" domain="[['type','!=','view']]"/>
<!--<field name="ap_doctor_id"/>-->
</field>
</inherit>

View File

@ -3,13 +3,10 @@ from netforce.model import Model, fields
class Settings(Model):
_inherit="settings"
_fields={
"ap_uc_id": fields.Many2One("account.account","Account Payment UC"),
"ap_sc_id": fields.Many2One("account.account","Account Payment Social Security"),
"ar_uc_id": fields.Many2One("account.account","Account Recieve UC"),
"ar_sc_id": fields.Many2One("account.account","Account Recieve Social Security"),
"cash_account_id": fields.Many2One("account.account","Cash Account"),
"income_account_id": fields.Many2One("account.account","Income Account"),
"ap_nurse_id": fields.Many2One("account.account","Account Payment Nurse"),
"ap_doctor_id": fields.Many2One("account.account","Account Payment Doctor"),
'hospital_code': fields.Char("Hospital Code", multi_company=True),
}
Settings.register()

View File

@ -97,7 +97,6 @@ class HDCase(Model):
"rmb_amount": fields.Float("Reimbursable",function="_get_all",readonly=True,function_multi=True),
"due_amount": fields.Float("Due Amount",function="_get_all",readonly=True,function_multi=True),
'fee_partner_id': fields.Many2One("partner","Contact Fee"),
'fee_paid': fields.Boolean("Fee Paid"),
'note': fields.Text("Note"),
'complication': fields.Text("Complication"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
@ -149,7 +148,6 @@ class HDCase(Model):
'hd_mode': 'chronic',
'hct': 0,
'hct_msg': "สามารถเบิกค่ายาสูงสุดไม่เกิน 1,125บาท ต่อ สัปดาห์",
'fee_paid': False,
'invoice_option': 'fee',
'invoice_policy': 'fee',
'req_fee': 0,
@ -226,6 +224,7 @@ class HDCase(Model):
price=line['price'] or 0.0
line['amount']=qty*price
data=self.update_amount(context)
#bug show button
return data
def onchange_product(self,context={}):
@ -265,15 +264,18 @@ class HDCase(Model):
rmb_amt+=amt
else:
due_amt+=amt
print("xx ", rmb_amt, due_amt)
data['rmb_amount']=rmb_amt
data['due_amount']=due_amt
data['total_amount']=due_amt+rmb_amt
data['req_fee']=0
if due_amt:
data['req_fee']=1
return data
def make_payment(self,ids,context={}):
obj=self.browse(ids)[0]
if not obj.total:
if not obj.total_amount:
return
remaining_amt=0.0
for line in obj.lines:
@ -282,34 +284,35 @@ class HDCase(Model):
remaining_amt-=line.amount or 0.0
partner=obj.patient_id.partner_id
if not partner:
raise Exception("No contact on this patient")
company_id=get_active_company()
account_receivable_id=partner.account_receivable_id
if not account_receivable_id:
st=get_model('settings').browse(1)
account_receivable_id=st.account_receivable_id
if not account_receivable_id:
raise Exception("Not found account recieveable in account setting")
account_id=account_receivable_id.id
if not account_id:
raise Exception("No Account for payment")
raise Exception("Not partner")
st=get_model('settings').browse(1)
cash_account_id=st.cash_account_id.id
income_account_id=st.income_account_id.id
if not cash_account_id:
raise Exception("No Cash Account")
if not income_account_id:
raise Exception("No Income Account")
pay_amount=obj.pay_amount
if context.get("amount",0):
pay_amount=context['amount'] or 0.0
company_id=get_active_company()
vals={
"partner_id": partner.id,
"company_id": company_id,
"type": "in",
"pay_type": "direct",
'date': time.strftime("%Y-%m-%d"),
"account_id": account_id,
"account_id": cash_account_id,
'related_id': "clinic.hd.case,%s"%obj.id,
'ref': obj.number,
'direct_lines': [],
}
vals['direct_lines'].append(('create',{
'description': 'Payment; %s'%obj.number,
'account_id': account_id,
'account_id': income_account_id,
'qty': 1,
'unit_price': pay_amount,
'amount': pay_amount,
@ -351,14 +354,55 @@ class HDCase(Model):
if obj.invoices:
for inv in obj.invoices:
inv.void()
due_date=obj.date[0:10] # XXX
due_date=obj.date[1:10] # XXX
# cash, credit
make_invoice=context.get('make_invoice',True)
is_credit=context.get('is_credit') or False
context['type']='out'
context['inv_type']='invoice'
fee_lines=[]
mdc_lines=[]
if obj.lines:
lines1=[] #yes
lines2=[] #no
for line in obj.lines:
if line.state!='draft':
continue
if line.reimbursable=='yes':
lines1.append(('create',{
"product_id": line.product_id.id,
"description": line.description,
'product_categ_code': line.product_categ_id.code,
"qty": line.qty,
"uom_id": line.uom_id.id,
"unit_price": line.price,
"amount": line.amount,
#'account_id': account_id,
}))
else:
vals={
"product_id": line.product_id.id,
'product_categ_code': line.product_categ_id.code,
"description": line.description,
"qty": line.qty,
"uom_id": line.uom_id.id,
"unit_price": line.price,
"amount": line.amount,
}
prod=line.product_id
sale_account=prod.sale_account_id
if not sale_account:
raise Exception("Not found sale account in product (%s) %s"%(prod.code,prod.name))
vals['account_id']=sale_account.id
lines2.append(('create',vals))
patient=obj.patient_id
if lines1:
ptype=patient.type_id
partner=ptype.contact_id
if not partner:
raise Exception("No contact for patient type %s"%obj.ptype.name)
account_mdc_id=partner.account_mdc_id.id
account_fee_id=partner.account_fee_id.id
account_service_id=partner.account_service_id.id
vals={
"type": "out",
"inv_type": "invoice",
@ -371,85 +415,52 @@ class HDCase(Model):
"lines": [],
"company_id": company_id,
}
partner=obj.patient_id.partner_id
if not partner:
raise Exception("No contact for patient %s"%obj.patient_id.name)
vals["partner_id"]=partner.id
for line in obj.lines:
if line.product_id:
account_id=line.product_id.sale_account_id.id or account_receivable_id
for mode,line1 in lines1:
categ_code=line1['product_categ_code']
if categ_code=='EPO':
line1['account_id']=account_mdc_id
elif categ_code=='FEE':
line1['account_id']=account_fee_id
elif categ_code=='SRV':
line1['account_id']=account_service_id
else:
account_id=account_receivable_id
inv_line={
"product_id": line.product_id.id,
"description": line.description,
"qty": line.qty,
"uom_id": line.uom_id.id,
"unit_price": line.price,
"amount": line.amount,
'account_id': account_id,
}
line1['account_id']=account_receivable_id
del line1['product_categ_code']
vals['lines']=lines1
get_model("account.invoice").create(vals,context)
if obj.invoice_policy=='fee':
if line.type=='fee':
fee_lines.append(inv_line)
else:
vals['lines'].append(('create',inv_line))
elif obj.invoice_policy=='fee_mdc':
if line.type=='fee':
fee_lines.append(inv_line)
elif line.type=='medicine':
mdc_lines.append(inv_line)
else:
vals['lines'].append(('create',inv_line))
else:
vals['lines'].append(('create',inv_line))
if lines2 and is_credit:
partner=patient.partner_id
if not partner:
raise Exception("No contact for this patient %s"%obj.partner.name)
vals={
"type": "out",
"inv_type": "invoice",
"tax_type": "tax_in",
'due_date': due_date,
"ref": obj.number,
"related_id": "clinic.hd.case,%s"%obj.id,
"currency_id": currency_id,
"company_id": company_id,
"lines": [],
"company_id": company_id,
'partner_id':partner.id,
}
for mode,line2 in lines2:
categ_code=line2['product_categ_code']
if not line2.get("account_id"):
line2['account_id']=account_receivable_id
del line2['product_categ_code'] #XXX
vals['lines']=lines2
get_model("account.invoice").create(vals,context) # create alway
if obj.amount and make_invoice: ## not pay yet
get_model("account.invoice").create(vals,context)
# check if type of product is stockable then create picking
obj.make_pickings()
vals={
"type": "out",
"inv_type": "invoice",
"tax_type": "tax_in",
'due_date': due_date,
"ref": obj.number,
"related_id": "clinic.hd.case,%s"%obj.id,
"currency_id": currency_id,
"company_id": company_id,
"lines": [],
"company_id": company_id,
}
if obj.invoice_option=='fee_mdc_plus':
fee_lines+=mdc_lines
mdc_lines=[]
contact=obj.patient_id.type_id.contact_id
account_id=contact.account_receivable_id.id or account_receivable_id
if not account_id:
raise Exception("Not found account receive")
if mdc_lines:
inv_vals=vals.copy()
inv_vals["partner_id"]=obj.fee_partner_id.id
for mdc_line in mdc_lines:
mdc_line['account_id']=account_id
inv_vals['lines'].append(('create',mdc_line))
get_model("account.invoice").create(inv_vals,context)
if fee_lines and not obj.fee_paid:
inv_vals=vals.copy()
inv_vals["partner_id"]=obj.fee_partner_id.id
for fee_line in fee_lines:
fee_line['account_id']=account_id
inv_vals['lines'].append(('create',fee_line))
get_model("account.invoice").create(inv_vals,context)
obj.write({
'fee_paid': True,
obj.make_pickings()
# prevent douplicate create invoice & picking
for line in obj.lines:
line.write({
'state': 'done',
})
def make_pickings(self,ids,context={}):
@ -486,6 +497,9 @@ class HDCase(Model):
for line in obj.lines:
if line.state!='draft':
continue
prod=line.product_id
if prod.type != 'stock':
@ -590,8 +604,6 @@ class HDCase(Model):
return True
def do_expense(self,ids,context={}):
return
#TODO
for obj in self.browse(ids):
# clear old expense
for exp in obj.expenes:
@ -600,17 +612,20 @@ class HDCase(Model):
fee=0.0
mdc=0.0
srv=0.0
other=0.0
for line in obj.lines:
amt=line.amount or 0.0
ltype=line.type
if ltype=='fee':
if line.reimbursable=='no':
amt=0
categ=line.product_categ_id
if categ.code=='FEE':
fee+=amt
elif ltype=='medicine':
elif categ.code=='EPO':
mdc+=amt
elif ltype=='service':
elif categ.code=='SRV':
srv+=amt
elif ltype=='others':
pass
else:
other+=amt
exp_lines.append(('create',{
'date': obj.date,
'patient_id': obj.patient_id.id,
@ -676,10 +691,16 @@ class HDCase(Model):
def undo(self,ids,context={}):
obj=self.browse(ids)[0]
for line in obj.lines:
line.write({
'state': 'draft',
})
for inv in obj.invoices:
inv.write({
'state': 'draft',
})
inv.move_id.to_draft()
inv.move_id.delete()
inv.delete()
for pick in obj.pickings:
pick.write({
@ -698,7 +719,6 @@ class HDCase(Model):
state=context.get("state","in_progress") #force state
obj.write({
'state': state,
'fee_paid': False,
})
return {
@ -924,9 +944,16 @@ class HDCase(Model):
def write(self,ids,vals,**kw):
obj=self.browse(ids)[0]
vals['req_fee']=0
if 'lines' in vals.keys():
for mode, line_ids, line_vals in vals['lines']:
if line_vals['reimbursable']=='no':
vals['req_fee']=1 # to show button pay
else:
for line in obj.lines:
if line.reimbursable=='no':
vals['req_fee']=1
super().write(ids,vals,**kw)
if not obj.amount:
vals['req_fee']=1 # to show button pay
def approve(self,ids,context={}):
obj=self.browse(ids)[0]

View File

@ -13,11 +13,13 @@ class Hdcaseline(Model):
"type": fields.Selection([("fee","Fee"),('medicine','Medicine'),('service','Service'),("others","Others")],"Type",required=True),
"product_categ_id": fields.Many2One("product.categ","Category",domain=[['expense','=',True]]),
'reimbursable': fields.Selection([['yes','Yes'],['no','No']],"Reimbursable"),
'state': fields.Selection([['draft','Draft'],['done','Done']],"State"),
}
_defaults={
'type': 'others',
'reimbursable': 'no',
'state': 'draft',
}
Hdcaseline.register()

View File

@ -7,7 +7,6 @@ class HDCasePayment(Model):
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
"pay_amount": fields.Float("Due Amount"),
"fee": fields.Float("Fee"),
"to_pay": fields.Float("To Pay"),
"complete": fields.Boolean("Mark as full payment for Cash"),
}
@ -21,22 +20,16 @@ class HDCasePayment(Model):
def _get_pay_amount(self,context={}):
hd_case_id=context.get("refer_id")
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
return hd_case.amount
def _get_fee(self,context={}):
hd_case_id=context.get("refer_id")
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
return hd_case.fee_amount
return hd_case.due_amount
def _get_topay(self,context={}):
hd_case_id=context.get("refer_id")
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
return hd_case.amount
return hd_case.due_amount
_defaults={
'hd_case_id': _get_hd_case_id,
'pay_amount': _get_pay_amount,
'fee': _get_fee,
'to_pay': _get_topay,
'complete': True,
}
@ -45,17 +38,21 @@ class HDCasePayment(Model):
obj=self.browse(ids)[0]
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
context['amount']=obj.pay_amount or 0.0
context['make_invoice']=False
context['is_credit']=False
hd_case.make_invoices(context=context) #XXX
hd_case.post_invoices()
if obj.pay_amount:
hd_case.make_payment(context=context)
if obj.complete:
hd_case.create_cycle_item()
if obj.pay_amount==obj.to_pay:
if obj.pay_amount==hd_case.total_amount: #XXX
vals={
'state': 'paid',
}
else:
vals={
'state': 'waiting_payment',
}
hd_case.write(vals)
hd_case.do_expense()
obj.write({
@ -73,7 +70,8 @@ class HDCasePayment(Model):
def credit(self,ids,context):
obj=self.browse(ids)[0]
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
hd_case.make_invoices()
context['is_credit']=True
hd_case.make_invoices(context=context)
hd_case.post_invoices()
hd_case.create_cycle_item()
if obj.pay_amount==obj.to_pay:
@ -95,7 +93,6 @@ class HDCasePayment(Model):
data=context['data']
pay_amount=data['pay_amount'] or 0.0
data['pay_amount']=pay_amount
data['to_pay']=pay_amount
return data
HDCasePayment.register()

View File

@ -1,3 +1,9 @@
categ_id
product_id
ca
create button reset at setting
- backup master data
- patient
- staff/nurse/doctor
- account
- journal
- product
---