invoice payment

conv_bal
watcha.h 2015-02-21 20:38:21 +07:00
parent bd7a8312f1
commit c1bb614d1e
14 changed files with 198 additions and 240 deletions

View File

@ -1,7 +1,7 @@
<action>
<field name="string">Matching Payment Group</field>
<field name="string">Invoice Payment</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.matching.payment.group</field>
<field name="model">clinic.invoice.payment</field>
<field name="menu">account_menu</field>
<field name="tabs">[
["All",[]],

View File

@ -3,7 +3,7 @@
<item string="Ratchawat">
<item string="Labor Costs" action="clinic_labor_cost"/>
<item string="Matching Payments" action="clinic_matching_payment"/>
<item string="Matching Payments (Group)" action="clinic_matching_payment_group"/>
<item string="Invoice Payments" action="clinic_invoice_payment"/>
<item string="Mathing HD Cases" action="clinic_matching_hdcase_acc"/>
<divider/>
<header string="REPORTS"/>

View File

@ -1,26 +1,34 @@
<form model="clinic.matching.payment.group" attrs='{"readonly":[["state","=","approved"]]}'>
<form model="clinic.invoice.payment" attrs='{"readonly":[["state","=","approved"]]}'>
<head>
<field name="state"/>
<button string="Print" action="print" icon="print"/>
<button string="Options" dropdown="1">
<!--<button string="Print" action="print" icon="print"/>-->
<button string="Options" dropdown="2">
<item string="To Draft" method="to_draft" states="approved"/>
</button>
</head>
<field name="name" span="3"/>
<field name="lines" nolabel="1" count="0">
<list>
<field name="matching_id" onchange="onchange_matching"/>
<field name="epo"/>
<field name="srv"/>
<field name="fee"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
</group>
<tabs>
<tab string="General">
<field name="lines" nolabel="1" count="0">
<list>
<field name="matching_id" domain='[["state","=","approved"]]' onchange="onchange_matching"/>
<field name="epo"/>
<field name="srv"/>
<field name="fee"/>
<field name="amount"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
</group>
</tab>
<tab string="Approval">
</tab>
</tabs>
<foot>
<button string="Post" method="post" type="success"/>
<button string="Submit To Approve" method="submit" states="draft" type="default" icon="arrow-right"/>
<button string="Approve" method="approve" states="waiting_approve" type="success"/>
</foot>
</form>

View File

@ -1,4 +1,4 @@
<list model="clinic.matching.payment.group" colors='{"#cfc":[["state","=","approved"]],"#dbdbdb":[["state","=","cancelled"]]}'>
<list model="clinic.invoice.payment" colors='{"#cfc":[["state","=","approved"]],"#dbdbdb":[["state","=","cancelled"]]}'>
<field name="name"/>
<field name="state"/>
</list>

View File

@ -1,10 +1,11 @@
<form model="clinic.matching.payment" attrs='{"readonly":[["state","=","approved"]]}'>
<head>
<field name="state"/>
<button string="Print" action="print" icon="print"/>
<button string="Options" dropdown="1">
<item string="Update Identification" method="update_id"/>
<item string="Make Payment" method="do_import" confirm="Are you sure?"/>
<item string="Clear Lines" method="clear_line" confirm="Are you sure?"/>
<item string="To Draft" method="to_draft" states="approved"/>
<item string="Clear" method="clear_line" confirm="Are you sure?"/>
</button>
</head>
<field name="date" onchange="onchange_date" mode="month" span="3"/>
@ -16,28 +17,36 @@
<field name="pcode" span="3"/>
<field name="hcode_id" span="3" attrs='{"required":[["pcode","=","SSO"]],"invisible":[["pcode","!=","SSO"]]}'/>
<field name="file" span="3"/>
<field name="lines" nolabel="1" count="0">
<list>
<field name="date"/>
<field name="hn"/>
<field name="pid"/>
<field name="name"/>
<field name="epo" sum="1"/>
<field name="srv" sum="1"/>
<field name="fee" sum="1"/>
<field name="amount" sum="1"/>
<field name="invoice_id" onchange="onchange_invoice" domain='[["date","=",date],["state","=","waiting_payment"]]'/>
<field name="state"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
<field name="total_match"/>
<field name="total_unmatch"/>
</group>
<foot replace="1">
<tabs>
<tab string="General">
<field name="lines" nolabel="1" count="0">
<list>
<field name="date"/>
<field name="hn"/>
<field name="pid"/>
<field name="name"/>
<field name="epo" sum="1"/>
<field name="srv" sum="1"/>
<field name="fee" sum="1"/>
<field name="amount" sum="1"/>
<field name="invoice_id" onchange="onchange_invoice" domain='[["date","=",date],["state","=","waiting_payment"]]'/>
<field name="state"/>
</list>
</field>
<group span="8" columns="1">
</group>
<group span="4" columns="1">
<field name="total"/>
<field name="total_match"/>
<field name="total_unmatch"/>
</group>
</tab>
<tab string="Approval">
<field name="user_id" span="3"/>
<button string="approve" method="approve" icon="ok" size="small"/>
</tab>
</tabs>
<foot>
<button string="Match" method="do_match" type="success" icon='ok'/>
</foot>
</form>

View File

@ -3,4 +3,5 @@
<field name="patient_type_id"/>
<field name="pcode"/>
<field name="hcode_id"/>
<field name="user_id"/>
</list>

View File

@ -1,2 +1,3 @@
from . import clinic_setting
from . import import_acc
from . import remove_conv_bal

View File

@ -72,9 +72,9 @@ class Migration(migration.Migration):
#cbv.create_open_entry()
#print("create_sale_invoices...")
#cbv.create_sale_invoices()
print("create_purch_invoices...")
cbv.create_purch_invoices()
print("Done!")
#print("create_purch_invoices...")
#cbv.create_purch_invoices()
#print("Done!")
return True
Migration.register()

View File

@ -0,0 +1,28 @@
from datetime import datetime
from netforce.model import get_model
from netforce import migration
from netforce.database import get_connection
#from netforce.access import set_active_user, get_active_user
class Migration(migration.Migration):
_name="clinic.remove.conv.bal"
_version="2.11.0"
def migrate(self):
db=get_connection()
res=db.query("""
select id, amount_due, state,date from account_invoice where extract(year from date)=2014;
""")
inv_ids=[r['id'] for r in res]
for inv in get_model("account.invoice").browse(inv_ids):
inv.to_draft()
print('%s is deleted'%(inv.number))
inv.delete()
start=datetime.now()
stop=datetime.now()
finish=stop-start
print(finish.seconds/60)
return True
Migration.register()

View File

@ -103,8 +103,8 @@ from . import make_apt
from . import make_apt_line
from . import matching_payment
from . import matching_payment_line
from . import matching_payment_group
from . import matching_payment_group_line
from . import invoice_payment
from . import invoice_payment_line
from . import matching_hdcase
from . import sale_order
from . import shop

View File

@ -1,9 +1,12 @@
import time
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
from netforce.access import get_active_company
class MatchingPaymentGroup(Model):
_name="clinic.matching.payment.group"
_string="Matching Payment Group"
class InvoicePayment(Model):
_name="clinic.invoice.payment"
_string="Invoice Payment"
def _get_all(self,ids,context={}):
res={}
@ -22,27 +25,68 @@ class MatchingPaymentGroup(Model):
_fields={
'name': fields.Char("Name",required=True),
'lines': fields.One2Many("clinic.matching.payment.group.line","group_matching_id", "Lines"),
'lines': fields.One2Many("clinic.invoice.payment.line","invoice_payment_id", "Lines"),
'total': fields.Float("Total",function="_get_all",function_multi=True),
'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'),
'state': fields.Selection([['draft','Draft'],['waiting_approve','Waiting Approve'],['approved','Approved']],'State'),
'date': fields.Date("Date"),
}
_defaults={
'state': 'draft',
'date': lambda *a: time.strftime("%Y-%m-%d"),
}
def post(self,ids,context={}):
def approve(self,ids,context={}):
count=0
for obj in self.browse(ids):
print("%s posted"%(obj.id))
res=obj.make_payment()
count+=1
if res<=1:
return res
def make_payment(self,ids,context={}):
obj=self.browse(ids)[0]
lines=[]
for line in obj.lines:
matches=line.matching_id
for match in matches:
invoice=match.invoice_id
if invoice:
vals={
'invoice_id': invoice.id,
'amount': invoice.amount_due or 0,
}
lines.append(('create', vals))
if not lines:
raise Exception("Nothing to approve")
st=get_model("clinic.setting").browse(1)
if not st.import_account_id:
raise Exception("Import account not found (Ratchawat Setting -> Accounting)")
obj=self.browse(ids)[0]
partner=obj.patient_type_id.contact_id
company_id=get_active_company()
datenow=obj.date or time.strftime("%Y-%m-%d")
vals={
"partner_id": partner.id,
"company_id": company_id,
"type": "in",
"pay_type": "invoice",
'date': datenow,
"account_id": st.import_account_id.id,
'invoice_lines': [],
'rd_cust': True, #XXX
}
payment_id=get_model("account.payment").create(vals,context={"type":"in"})
return {
'next': {
'name': 'clinic_matching_payment_group',
'name': 'payment',
'mode': 'form',
'active_id': obj.id,
'active_id': payment_id,
},
'flash': 'Posted',
'flash': 'Create Payment successfully',
}
def update_amount(self,context={}):
data=context['data']
data['total']=0
@ -63,4 +107,16 @@ class MatchingPaymentGroup(Model):
data=self.update_amount(context=context)
return data
MatchingPaymentGroup.register()
def to_draft(self,ids,context={}):
for obj in self.browse(ids):
obj.write({
'state': 'draft',
})
def sumbit(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
'state': 'waiting_approve',
})
InvoicePayment.register()

View File

@ -1,8 +1,8 @@
from netforce.model import Model, fields
class MatchingPaymentGroupLine(Model):
_name="clinic.matching.payment.group.line"
_string="Matching Payment Group Line"
class InvoicePaymentLine(Model):
_name="clinic.invoice.payment.line"
_string="Invoice Payment Line"
def _get_all(self,ids,context={}):
res={}
@ -17,12 +17,12 @@ class MatchingPaymentGroupLine(Model):
return res
_fields={
'group_matching_id': fields.Many2One("clinic.matching.payment.group","Group Matching",required=True,on_delete="cascade"),
'matching_id': fields.Many2One("clinic.matching.payment","Group Matching"),
'invoice_payment_id': fields.Many2One("clinic.invoice.payment","Invcoie Payment",required=True,on_delete="cascade"),
'matching_id': fields.Many2One("clinic.matching.payment","Payment Matching"),
'fee': fields.Float("Fee"),
'srv': fields.Float("Service"),
'epo': fields.Float("EPO"),
'amount': fields.Float("Amount", function="_get_all", function_multi=True),
}
MatchingPaymentGroupLine.register()
InvoicePaymentLine.register()

View File

@ -3,8 +3,7 @@ from calendar import monthrange
from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path, get_data_path
from netforce.database import get_connection
from netforce.access import get_active_company
from netforce.access import get_active_company, get_active_user
from . import utils
@ -55,6 +54,7 @@ class MatchingPayment(Model):
'total_srv': fields.Float("Service",function="_get_all",function_multi=True),
'total_epo': fields.Float("EPO",function="_get_all",function_multi=True),
'state': fields.Selection([['draft','Draft'],['approved','Approved']],'State'),
'user_id': fields.Many2One("base.user","Approver"),
}
def _get_ptype(self,context={}):
@ -89,6 +89,7 @@ class MatchingPayment(Model):
'patient_type_id': _get_ptype,
'pcode': _get_pcode,
'state': 'draft',
'user_id': lambda *a: get_active_user(),
}
_order="date desc"
@ -454,172 +455,6 @@ class MatchingPayment(Model):
}
return data
def match_old(self,ids,context={}):
obj=self.browse(ids)[0]
lines=obj.get_line()
db=get_connection()
db.execute("truncate m2m_clinic_hd_case_expense_clinic_matching_payment;")
matches1={}
matches2={}
matches3={}
if obj.pcode=='SSO':
for line in lines:
hcode=line.get('hcode18')
if not hcode:
hcode='0'
hcode=int(hcode)
hcode=str(hcode)
if obj.hcode==hcode:
lsrv_amt=line.get('epoadm29') or 0
lfee_amt=line.get('amount23') or 0
lmdc_amt=line.get('allow37') or 0
dttran=line.get("dttran")
name=line.get("name14")
pid=line.get('pid')
date=dttran[0:10]
time=dttran[11:] #XXX
if not time:
print("wrong format")
continue
hn=line.get('hn')
hn=''.join([x for x in hn if x.isdigit()])
key1='%s:%s:%s:%s:%s'%(
hn,
date,
lfee_amt,
lsrv_amt,
lmdc_amt,
)
key2='%s:%s:%s:%s:%s'%(
pid,
date,
lfee_amt,
lsrv_amt,
lmdc_amt,
)
key3='%s:%s:%s:%s:%s'%(
name,
date,
lfee_amt,
lsrv_amt,
lmdc_amt,
)
vals={
'pid': pid,
'name': name,
'date': date,
'fee_amt': lfee_amt,
'service_amt': lsrv_amt,
'epo_amt': lmdc_amt,
}
if not matches1.get(key1):
matches1[key1]=vals
if not matches2.get(key2):
matches2[key2]=vals
if not matches3.get(key3):
matches2[key2]=vals
elif obj.pcode=='UC':
for line in lines:
#{'amount': '1500.0000',
#'cstat': None,
#'dttran': '2014-09-27T10:00:00',
#'epostat': 'E',
#'hdflag': 'COU',
#'hdrate': '1500.0000',
#'hn': '98511252',
#'hreg': 'NHSO1',
#'invno': '437941480',
#'paid': '0.0000',
#'paychk': '1',
#'reimbpay': '0.0000',
#'rid': '2190',
#'station': '01'}
date,time=(line['dttran'] or "").split("T")
amt=line['amount'] or "0"
amt=float(amt)
if date and time:
key1='%s-%s-%s'%(
line['hn'],
date,
amt,
)
if not matches1.get(key1):
matches1[key1]={
'invno': line['invno'],
}
note=""
exp_ids=[]
dom=[]
dom.append(['date',">=",obj.date_from])
dom.append(['date',"<=",obj.date_to])
dom.append(['patient_id.type_id',"=",obj.patient_type_id.id])
dom.append(['state','!=', 'completed'])
for exp in get_model('clinic.hd.case.expense').search_browse(dom):
exp_ids.append(exp.id)
pt=exp.patient_id
if obj.pcode=='UC':
hdcase=exp.hd_case_id
date=hdcase.date
fee_amt=0
for line in hdcase.lines:
categ=line.product_categ_id
if categ.code=='FEE':
fee_amt+=line.amount or 0
key='%s-%s-%s'%(pt.hn_no,date,amt)
found=matches1.get(key)
if found:
exp.write({
'state': 'match',
})
else:
note+="not found %s\n"%key
elif obj.pcode=='SSO':
key1='%s:%s:%s:%s:%s'%(
pt.hn_no,
exp.date,
exp.fee_amt and exp.fee_amt or 0,
exp.srv_amt and exp.srv_amt or 0,
exp.mdc_amt and exp.mdc_amt or 0,
)
key2='%s:%s:%s:%s:%s'%(
pt.name or "",
exp.date,
exp.fee_amt and exp.fee_amt or 0,
exp.srv_amt and exp.srv_amt or 0,
exp.mdc_amt and exp.mdc_amt or 0,
)
found=matches1.get(key1) or matches2.get(key2)
if found:
hdcase=exp.hd_case_id
if hdcase:
for inv in hdcase.invoices:
pass
#if
#pass
exp.write({
'state': 'match',
})
else:
note+="not found %s, %s\n"%(key1,key2)
obj.write({
'expenes': [('add',exp_ids)],
'note': note,
})
print("Done!")
flash='Succesfully'
if not exp_ids:
flash="No match"
return {
'next': {
'name': 'clinic_matching_payment',
'mode': 'form',
'active_id': obj.id,
},
'flash': flash,
}
def onchange_invoice(self,context={}):
data=context['data']
path=context['path']
@ -636,4 +471,24 @@ class MatchingPayment(Model):
get_model("clinic.matching.payment.line").delete(line_ids)
print("Cleared %s"%(line_ids))
def approve(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({
'state': 'approved',
})
return {
'next': {
'name': 'clinic_matching_payment',
'mode': 'form',
'active_id': obj.id,
},
'flash': '%s has been approved'%obj.name,
}
def to_draft(self,ids,context={}):
for obj in self.browse(ids):
obj.write({
'state': 'draft',
})
MatchingPayment.register()

View File

@ -10,7 +10,7 @@
<table class="table table-bordered">
<thead>
{{#each titles}}
<th>{{name}}</th>
<th style="text-align:center">{{name}}</th>
{{/each}}
</thead>
<tbody>
@ -20,7 +20,7 @@
<a href="/ui#name=product&active_id={{prod_id}}&mode=form"> {{prod_name}} </a>
</td>
{{#each sub_lines}}
<td>{{qty}}</td>
<td style="text-align:center">{{qty}}</td>
{{/each}}
</tr>
{{/each}}