diff --git a/netforce_clinic/models/conv_bal.py b/netforce_clinic/models/conv_bal.py index 169ab5e..4bfb59c 100644 --- a/netforce_clinic/models/conv_bal.py +++ b/netforce_clinic/models/conv_bal.py @@ -10,7 +10,6 @@ class ConvBal(Model): def create_sale_invoices(self,ids,context={}): obj=self.browse(ids)[0] - settings=get_model("settings").browse(1) desc="Conversion balance %s"%obj.date for inv in obj.sale_invoices: vals={ @@ -44,12 +43,12 @@ class ConvBal(Model): }) #if abs(inv2.amount_total)-abs(inv.amount_due)>0.001: # XXX #raise Exception("Failed to update invoice %s: different amount"%inv.number) - #if inv2.state=="draft": - #raise Exception("Failed to update invoice %s: invalid state"%inv.number) - #inv2.write({ - #"move_id": obj.move_id.id, - #"reconcile_move_line_id": inv.move_line_id.id, - #}) + if inv2.state=="draft": + raise Exception("Failed to update invoice %s: invalid state"%inv.number) + inv2.write({ + "move_id": obj.move_id.id, + "reconcile_move_line_id": inv.move_line_id.id, + }) else: get_model("account.invoice").create(vals) @@ -63,10 +62,10 @@ class ConvBal(Model): 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) + #print("row",row) row+="," #XXX append blank column for Amount Cur line=dict(zip(headers,row)) - print("line",line) + #print("line",line) if not line.get("Number"): continue number=line["Number"].strip() @@ -84,9 +83,16 @@ class ConvBal(Model): 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 - amts=[m.split(":")[1] for m in line['Memo'].split(",")] + print("*"*80) for acc_code in acc_codes: acc_code=acc_code.strip() res=get_model("account.account").search([["code","=",acc_code]]) @@ -94,6 +100,7 @@ class ConvBal(Model): raise Exception("Account code not found: %s"%acc_code) acc_id=res[0] amount_due=amts[count] + print(acc_code, acc_id, amount_due) vals={ "conv_id": obj.id, "number": number, @@ -103,10 +110,31 @@ class ConvBal(Model): "due_date": due_date, "amount_due": amount_due, "account_id": acc_id, - "amount_cur": amount_cur, + "amount_cur": amount_due, #XXX } get_model("conv.sale.invoice").create(vals) count+=1 + print("*"*80) + 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 + } + get_model("conv.sale.invoice").create(vals) else: res=get_model("account.account").search([["code","=",acc_code]]) if not res: