fix_acc
watcha.h 2015-08-27 10:01:57 +07:00
parent 3987ee2b8b
commit 5e680d983b
3 changed files with 55 additions and 2 deletions

View File

@ -1,3 +1,3 @@
#from . import clinic_setting
from . import repost_invoice
from . import conv_bal
#from . import repost_invoice

View File

@ -39,7 +39,6 @@ class Migration(migration.Migration):
'state': 'draft',
})
ids=list(hdcase_ids)
for seq in get_model("sequence").search_browse([['type','in',['cust_invoice','clinic_invoice_noclaim']]]):
for run in seq.running:
run.delete()

View File

@ -181,4 +181,58 @@ class ConvBal(Model):
}
}
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]
if not context.get('is_append'):
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)
line=dict(zip(headers,row))
print("line",line)
if not line.get("Number"):
continue
number=line["Number"].strip()
if not number:
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()
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_cur=float(line["Amount Cur"].strip().replace(",","") or 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,
}
get_model("conv.sale.invoice").create(vals)
return {
"next": {
"name": "conv_bal",
"active_id": obj.id,
"view_xml": "conv_bal2",
}
}
ConvBal.register()