reimport tb
parent
b9b39afd0f
commit
8d52a9a918
|
@ -1,3 +1,4 @@
|
||||||
#from . import clinic_setting
|
#from . import clinic_setting
|
||||||
from . import repost_invoice
|
#from . import repost_invoice
|
||||||
from . import conv_bal
|
from . import conv_bal
|
||||||
|
#from . import tb_ap_import
|
||||||
|
|
|
@ -12,11 +12,43 @@ class Migration(migration.Migration):
|
||||||
#for mv in get_model("account.move").search_browse([['number','ilike', 'OPEN']]):
|
#for mv in get_model("account.move").search_browse([['number','ilike', 'OPEN']]):
|
||||||
#mv.to_draft()
|
#mv.to_draft()
|
||||||
#mv.delete()
|
#mv.delete()
|
||||||
|
|
||||||
|
# delete old account payable
|
||||||
|
dom=[
|
||||||
|
['memo','=','Conversion balance 2015-06-30'],
|
||||||
|
['type','=','in'],
|
||||||
|
['state','=','waiting_payment'],
|
||||||
|
]
|
||||||
|
for inv in get_model('account.invoice').search_browse(dom):
|
||||||
|
print('delete invoice... ', inv.number)
|
||||||
|
inv.to_draft()
|
||||||
|
inv.delete()
|
||||||
|
|
||||||
|
# delete old account rereivable
|
||||||
|
dom=[
|
||||||
|
['memo','=','Conversion balance 2015-06-30'],
|
||||||
|
['type','=','out'],
|
||||||
|
['state','=','waiting_payment'],
|
||||||
|
]
|
||||||
|
for inv in get_model('account.invoice').search_browse(dom):
|
||||||
|
print('delete invoice... ', inv.number)
|
||||||
|
inv.to_draft()
|
||||||
|
inv.delete()
|
||||||
|
# remove journal entry
|
||||||
|
dom=[
|
||||||
|
['number','=','OPENING ENTRY'],
|
||||||
|
]
|
||||||
|
for move in get_model('account.move').search_browse(dom):
|
||||||
|
print('delete accout.move... ', move.number)
|
||||||
|
move.to_draft()
|
||||||
|
move.delete()
|
||||||
|
|
||||||
cbv_id=24
|
cbv_id=24
|
||||||
cbv=get_model("conv.bal").browse(cbv_id)
|
cbv=get_model("conv.bal").browse(cbv_id)
|
||||||
cbv.write({
|
cbv.write({
|
||||||
'date_fmt': '%Y-%m-%d',
|
'date_fmt': '%Y-%m-%d',
|
||||||
'file': 'tb.csv',
|
'file': 'tb.csv',
|
||||||
|
'date': '2015-06-30',
|
||||||
})
|
})
|
||||||
print("import acc file (step 1) running ...")
|
print("import acc file (step 1) running ...")
|
||||||
get_model("conv.bal").import_acc_file([cbv.id],context={})
|
get_model("conv.bal").import_acc_file([cbv.id],context={})
|
||||||
|
@ -39,7 +71,8 @@ class Migration(migration.Migration):
|
||||||
print("import purch file (step 3) running ...")
|
print("import purch file (step 3) running ...")
|
||||||
cbv.write({
|
cbv.write({
|
||||||
'file': 'ap.csv',
|
'file': 'ap.csv',
|
||||||
'date_fmt': '%d/%m/%Y',
|
#'date_fmt': '%d/%m/%Y',
|
||||||
|
'date_fmt': '%Y-%m-%d',
|
||||||
})
|
})
|
||||||
get_model("conv.bal").import_purch_file([cbv.id],context={})
|
get_model("conv.bal").import_purch_file([cbv.id],context={})
|
||||||
get_model("conv.bal").import_purch([cbv.id],context={})
|
get_model("conv.bal").import_purch([cbv.id],context={})
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
from netforce.model import get_model
|
||||||
|
from netforce import migration
|
||||||
|
from netforce.access import set_active_user, set_active_company
|
||||||
|
|
||||||
|
class Migration(migration.Migration):
|
||||||
|
_name="clinic.tb.ap.import"
|
||||||
|
_version="2.10.0"
|
||||||
|
|
||||||
|
def migrate(self):
|
||||||
|
set_active_user(1)
|
||||||
|
set_active_company(1)
|
||||||
|
#for mv in get_model("account.move").search_browse([['number','ilike', 'OPEN']]):
|
||||||
|
#mv.to_draft()
|
||||||
|
#mv.delete()
|
||||||
|
cbv_id=24
|
||||||
|
cbv=get_model("conv.bal").browse(cbv_id)
|
||||||
|
cbv.write({
|
||||||
|
'date_fmt': '%Y-%m-%d',
|
||||||
|
'file': 'tb.csv',
|
||||||
|
'date': '2015-06-30',
|
||||||
|
})
|
||||||
|
print("import acc file (step 1) running ...")
|
||||||
|
get_model("conv.bal").import_acc_file([cbv.id],context={})
|
||||||
|
get_model("conv.bal").import_acc([cbv.id],context={})
|
||||||
|
|
||||||
|
#print("import sale file (step 2)running ...")
|
||||||
|
#del_ids=get_model("conv.sale.invoice").search([["conv_id","=",cbv.id]])
|
||||||
|
#get_model('conv.sale.invoice').delete(del_ids)
|
||||||
|
#for ar_file in ['ar_fee','ar_epo','ar_srv','ar_other']:
|
||||||
|
#cbv.write({
|
||||||
|
#'date_fmt': '%d/%m/%Y',
|
||||||
|
#'file': '%s.csv'%(ar_file),
|
||||||
|
#})
|
||||||
|
#ctx={
|
||||||
|
#'is_append': True,
|
||||||
|
#}
|
||||||
|
#get_model("conv.bal").import_sale_file([cbv.id],context=ctx)
|
||||||
|
#get_model("conv.bal").import_sale([cbv.id],context={})
|
||||||
|
|
||||||
|
print("import purch file (step 3) running ...")
|
||||||
|
cbv.write({
|
||||||
|
'file': 'ap.csv',
|
||||||
|
#'date_fmt': '%d/%m/%Y',
|
||||||
|
'date_fmt': '%Y-%m-%d',
|
||||||
|
})
|
||||||
|
get_model("conv.bal").import_purch_file([cbv.id],context={})
|
||||||
|
get_model("conv.bal").import_purch([cbv.id],context={})
|
||||||
|
|
||||||
|
cbv.write({
|
||||||
|
'date_fmt': '%Y-%m-%d',
|
||||||
|
})
|
||||||
|
# delete old account payable
|
||||||
|
dom=[
|
||||||
|
['memo','=','Conversion balance 2015-06-30'],
|
||||||
|
['type','=','in'],
|
||||||
|
['state','=','waiting_payment'],
|
||||||
|
]
|
||||||
|
for inv in get_model('account.invoice').search_browse(dom):
|
||||||
|
print('delete invoice... ', inv.number)
|
||||||
|
inv.to_draft()
|
||||||
|
inv.delete()
|
||||||
|
print(">> next 3")
|
||||||
|
print("create_open_entry...")
|
||||||
|
ctx={
|
||||||
|
'tb_ap_only': True,
|
||||||
|
}
|
||||||
|
cbv.create_open_entry(context=ctx)
|
||||||
|
#print("create_sale_invoices...")
|
||||||
|
#cbv.create_sale_invoices()
|
||||||
|
print("create_purch_invoices...")
|
||||||
|
cbv.create_purch_invoices()
|
||||||
|
print("Done!")
|
||||||
|
return True
|
||||||
|
|
||||||
|
Migration.register()
|
|
@ -54,133 +54,6 @@ class ConvBal(Model):
|
||||||
else:
|
else:
|
||||||
get_model("account.invoice").create(vals)
|
get_model("account.invoice").create(vals)
|
||||||
|
|
||||||
def _import_sale_file(self,ids,context):
|
|
||||||
obj=self.browse(ids)[0]
|
|
||||||
path=get_file_path(obj.file)
|
|
||||||
data=open(path).read()
|
|
||||||
rd=csv.reader(StringIO(data))
|
|
||||||
headers=next(rd)
|
|
||||||
headers=[h.strip() for h in headers]
|
|
||||||
del_ids=get_model("conv.sale.invoice").search([["conv_id","=",obj.id]])
|
|
||||||
get_model("conv.sale.invoice").delete(del_ids)
|
|
||||||
for row in rd:
|
|
||||||
#print("row",row)
|
|
||||||
row+="," #XXX append blank column for Amount Cur
|
|
||||||
line=dict(zip(headers,row))
|
|
||||||
#print("line",line)
|
|
||||||
track_id=None
|
|
||||||
department_id=None
|
|
||||||
department_name=line.get("Department")
|
|
||||||
if department_name:
|
|
||||||
for dpt in get_model("clinic.department").search_browse([['name','=',department_name]]):
|
|
||||||
department_id=dpt.id
|
|
||||||
track_id=dpt.branch_id.track_id.id
|
|
||||||
if not line.get("Number"):
|
|
||||||
continue
|
|
||||||
number=line["Number"].strip()
|
|
||||||
if not number:
|
|
||||||
continue
|
|
||||||
|
|
||||||
##XXX remove invoice
|
|
||||||
#for inv in get_model('account.invoice').search_browse([['number','=', number]]):
|
|
||||||
#print('number --> ', number)
|
|
||||||
#inv.to_draft()
|
|
||||||
#inv.delete()
|
|
||||||
#continue
|
|
||||||
|
|
||||||
ref=line["Reference"].strip()
|
|
||||||
contact_name=line["Contact"].strip()
|
|
||||||
res=get_model("partner").search([["name","=",contact_name]])
|
|
||||||
if not res:
|
|
||||||
raise Exception("Contact not found: '%s'"%contact_name)
|
|
||||||
contact_id=res[0]
|
|
||||||
date=datetime.datetime.strptime(line["Date"].strip(),obj.date_fmt).strftime("%Y-%m-%d")
|
|
||||||
due_date=datetime.datetime.strptime(line["Due Date"].strip(),obj.date_fmt).strftime("%Y-%m-%d")
|
|
||||||
amount_due=float(line["Amount Due"].strip().replace(",","") or 0)
|
|
||||||
acc_code=line["Account"].strip()
|
|
||||||
amount_cur=float(line["Amount Cur"].strip().replace(",","") or 0)
|
|
||||||
acc_codes=acc_code.split(",")
|
|
||||||
amts=[] #XXX
|
|
||||||
for m in line['Memo'].split(","):
|
|
||||||
amt=m.split(":")[1]
|
|
||||||
amt=amt.strip()
|
|
||||||
if amt:
|
|
||||||
amt=float(amt)
|
|
||||||
amts.append(amt)
|
|
||||||
if len(acc_codes) > 1:
|
|
||||||
count=0
|
|
||||||
print("*"*80)
|
|
||||||
for acc_code in acc_codes:
|
|
||||||
acc_code=acc_code.strip()
|
|
||||||
res=get_model("account.account").search([["code","=",acc_code]])
|
|
||||||
if not res:
|
|
||||||
raise Exception("Account code not found: %s"%acc_code)
|
|
||||||
acc_id=res[0]
|
|
||||||
amount_due=amts[count]
|
|
||||||
vals={
|
|
||||||
"conv_id": obj.id,
|
|
||||||
"number": number,
|
|
||||||
"ref": ref,
|
|
||||||
"contact_id": contact_id,
|
|
||||||
"date": date,
|
|
||||||
"due_date": due_date,
|
|
||||||
"amount_due": amount_due,
|
|
||||||
"account_id": acc_id,
|
|
||||||
"amount_cur": amount_due, #XXX
|
|
||||||
'track_id': track_id,
|
|
||||||
'department_id': department_id,
|
|
||||||
}
|
|
||||||
get_model("conv.sale.invoice").create(vals)
|
|
||||||
count+=1
|
|
||||||
elif len(amts) >= 1 and len(acc_codes)<=1:
|
|
||||||
acc_code=acc_codes[0].strip()
|
|
||||||
res=get_model("account.account").search([["code","=",acc_code]])
|
|
||||||
if not res:
|
|
||||||
raise Exception("Account code not found: %s"%acc_code)
|
|
||||||
acc_id=res[0]
|
|
||||||
for amt in amts:
|
|
||||||
amount_due=amt
|
|
||||||
vals={
|
|
||||||
"conv_id": obj.id,
|
|
||||||
"number": number,
|
|
||||||
"ref": ref,
|
|
||||||
"contact_id": contact_id,
|
|
||||||
"date": date,
|
|
||||||
"due_date": due_date,
|
|
||||||
"amount_due": amount_due,
|
|
||||||
"account_id": acc_id,
|
|
||||||
"amount_cur": amount_due, #XXX
|
|
||||||
'track_id': track_id,
|
|
||||||
'department_id': department_id,
|
|
||||||
}
|
|
||||||
get_model("conv.sale.invoice").create(vals)
|
|
||||||
else:
|
|
||||||
res=get_model("account.account").search([["code","=",acc_code]])
|
|
||||||
if not res:
|
|
||||||
raise Exception("Account code not found: %s"%acc_code)
|
|
||||||
acc_id=res[0]
|
|
||||||
vals={
|
|
||||||
"conv_id": obj.id,
|
|
||||||
"number": number,
|
|
||||||
"ref": ref,
|
|
||||||
"contact_id": contact_id,
|
|
||||||
"date": date,
|
|
||||||
"due_date": due_date,
|
|
||||||
"amount_due": amount_due,
|
|
||||||
"account_id": acc_id,
|
|
||||||
"amount_cur": amount_cur,
|
|
||||||
'track_id': track_id,
|
|
||||||
'department_id': department_id,
|
|
||||||
}
|
|
||||||
get_model("conv.sale.invoice").create(vals)
|
|
||||||
return {
|
|
||||||
"next": {
|
|
||||||
"name": "conv_bal",
|
|
||||||
"active_id": obj.id,
|
|
||||||
"view_xml": "conv_bal2",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def import_sale_file(self,ids,context):
|
def import_sale_file(self,ids,context):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
path=get_file_path(obj.file)
|
path=get_file_path(obj.file)
|
||||||
|
|
Loading…
Reference in New Issue