conv_bal
watcha.h@almacom.co.th 2015-01-08 15:07:33 +07:00
parent e122227156
commit 7eff465fd1
5 changed files with 47 additions and 43 deletions

View File

@ -86,7 +86,8 @@
<button string="Confirm" type="success" method="schd_confirm"/> <button string="Confirm" type="success" method="schd_confirm"/>
</tab> </tab>
<tab string="Testing"> <tab string="Testing">
<button string="Run Script" type="default" method="run_script"/> <button string="Dummy" type="default" method="run_script"/>
<button string="Reset Import" icon="repeat" type="default" method="reset_last_import"/>
</tab> </tab>
</tabs> </tabs>
<foot> <foot>

View File

@ -345,7 +345,6 @@ class HDCase(Model):
currency_id=setting.currency_id.id currency_id=setting.currency_id.id
if not currency_id: if not currency_id:
raise Exception("Currency not found in account settings") raise Exception("Currency not found in account settings")
account_receivable_id=setting.account_receivable_id.id
company_id=get_active_company() company_id=get_active_company()
uom=get_model("uom").search_browse([['name','ilike','%Unit%']]) uom=get_model("uom").search_browse([['name','ilike','%Unit%']])
if not uom: if not uom:
@ -359,44 +358,40 @@ class HDCase(Model):
is_credit=context.get('is_credit') or False is_credit=context.get('is_credit') or False
context['type']='out' context['type']='out'
context['inv_type']='invoice' context['inv_type']='invoice'
lines1=[] #yes rmb_lines=[] #yes
lines2=[] #no normb_lines=[] #no
for line in obj.lines: for line in obj.lines:
if line.state!='draft': if line.state!='draft':
continue continue
prod=line.product_id
account_id=prod.sale_account_id.id
if not account_id:
raise Exception("Please define sale account for product [%s] %s"%(prod.code, prod.name))
if line.reimbursable=='yes': if line.reimbursable=='yes':
lines1.append(('create',{ rmb_lines.append(('create',{
"product_id": line.product_id.id, "product_id": prod.id,
"description": line.description, "description": line.description,
'product_categ_code': line.product_categ_id.code,
"qty": line.qty, "qty": line.qty,
"uom_id": line.uom_id.id, "uom_id": line.uom_id.id,
"unit_price": line.price, "unit_price": line.price,
"amount": line.amount, "amount": line.amount,
#'account_id': account_id, 'account_id': account_id,
})) }))
else: else:
vals={ normb_lines.append(('create',{
"product_id": line.product_id.id, "product_id": prod.id,
'product_categ_code': line.product_categ_id.code,
"description": line.description, "description": line.description,
"qty": line.qty, "qty": line.qty,
"uom_id": line.uom_id.id, "uom_id": line.uom_id.id,
"unit_price": line.price, "unit_price": line.price,
"amount": line.amount, "amount": line.amount,
} 'account_id': account_id,
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 patient=obj.patient_id
if lines1: if rmb_lines:
ptype=patient.type_id ptype=patient.type_id
partner=ptype.contact_id partner=ptype.contact_id
if not partner: if not partner:
@ -418,21 +413,10 @@ class HDCase(Model):
"company_id": company_id, "company_id": company_id,
} }
vals["partner_id"]=partner.id vals["partner_id"]=partner.id
for mode,line1 in lines1: vals['lines']=rmb_lines
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:
line1['account_id']=account_receivable_id
del line1['product_categ_code']
vals['lines']=lines1
get_model("account.invoice").create(vals,context) get_model("account.invoice").create(vals,context)
if lines2 and is_credit: if normb_lines and is_credit:
partner=patient.partner_id partner=patient.partner_id
if not partner: if not partner:
raise Exception("No contact for this patient %s"%obj.partner.name) raise Exception("No contact for this patient %s"%obj.partner.name)
@ -449,15 +433,9 @@ class HDCase(Model):
"company_id": company_id, "company_id": company_id,
'partner_id':partner.id, 'partner_id':partner.id,
} }
for mode,line2 in lines2: vals['lines']=normb_lines
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 get_model("account.invoice").create(vals,context) # create alway
obj.make_pickings() obj.make_pickings()
# prevent douplicate create invoice & picking # prevent douplicate create invoice & picking
for line in obj.lines: for line in obj.lines:
@ -926,7 +904,6 @@ class HDCase(Model):
return vals return vals
def get_invoice_policy(self,vals={},patient_id=None): def get_invoice_policy(self,vals={},patient_id=None):
print('vals ', vals)
if patient_id: if patient_id:
patient=get_model("clinic.patient").browse(patient_id) patient=get_model("clinic.patient").browse(patient_id)
st=get_model("clinic.setting").browse(1) st=get_model("clinic.setting").browse(1)

View File

@ -52,7 +52,7 @@ class ReportPaymentMatching(Model):
'date_to': _get_date_to, 'date_to': _get_date_to,
'state': 'match', 'state': 'match',
'type_id': _get_type_id, 'type_id': _get_type_id,
'show_hcode': 0, 'show_hcode': 1,
} }
def match_invoice(self,ids,context={}): def match_invoice(self,ids,context={}):

View File

@ -1,6 +1,7 @@
from netforce.model import Model, fields, get_model from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path, get_data_path from netforce.utils import get_file_path, get_data_path
from netforce.access import get_active_company from netforce.access import get_active_company
from netforce.database import get_connection
class ClinicSetting(Model): class ClinicSetting(Model):
_name="clinic.setting" _name="clinic.setting"
@ -95,4 +96,25 @@ class ClinicSetting(Model):
}) })
print("Done") print("Done")
def reset_last_import(self,ids,context={}):
res=get_model("clinic.report.payment.matching").search_read([],['date'],order="date desc")
if res:
db=get_connection()
res1=res[0]
date1='%s 00:00:00'%res1['date']
date2='%s 23:59:59'%res1['date']
exp_ids=[x['id'] for x in db.query("select id from clinic_hd_case_expense where write_time>=%s and write_time<=%s",date1,date2)]
for exp in get_model("clinic.hd.case.expense").browse(exp_ids):
exp.write({
'state': 'waiting_matching',
'ok': False,
})
for inv in exp.invoices:
payment=inv.payment_id
if payment:
if payment.state !='draft':
payment.to_draft()
print("to draft payment ", payment.id)
print("Done")
ClinicSetting.register() ClinicSetting.register()

View File

@ -1,3 +1,7 @@
=====
- get account id by product
=====
create button reset at setting create button reset at setting
- backup master data - backup master data
- patient - patient