improve conversion balance
parent
27105dba01
commit
e20d25029f
|
@ -1,7 +1,3 @@
|
|||
from . import clinic_setting
|
||||
#from . import update_account_tracking
|
||||
#from . import print_labor_cost
|
||||
#from . import hdcase
|
||||
from . import conv_bal
|
||||
#from . import remove_conv_bal
|
||||
#from . import update_labor_cost_line
|
||||
#from . import conv_bal
|
||||
from . import repost_invoice
|
||||
|
|
|
@ -9,16 +9,21 @@ class Migration(migration.Migration):
|
|||
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',
|
||||
})
|
||||
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={})
|
||||
|
||||
|
||||
cbv.write({
|
||||
'date_fmt': '%d/%m/%Y',
|
||||
'file': 'ar.csv',
|
||||
})
|
||||
print("import sale file (step 2)running ...")
|
||||
|
@ -37,7 +42,7 @@ class Migration(migration.Migration):
|
|||
'date_fmt': '%Y-%m-%d',
|
||||
})
|
||||
|
||||
# next 3
|
||||
print(">> next 3")
|
||||
print("create_open_entry...")
|
||||
cbv.create_open_entry()
|
||||
print("create_sale_invoices...")
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
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.repos.invoice"
|
||||
_version="2.10.0"
|
||||
|
||||
def migrate(self):
|
||||
set_active_user(1)
|
||||
set_active_company(1)
|
||||
for hdcase in get_model('clinic.hd.case').search_browse([]):
|
||||
for inv in hdcase.invoices:
|
||||
if inv.state=='waiting_payment':
|
||||
print('repost ---> ', inv.number)
|
||||
inv.to_draft()
|
||||
inv.post()
|
||||
print("Done!")
|
||||
for shop in get_model('clinic.shop').search_browse([]):
|
||||
for inv in shop.invoices:
|
||||
print('repost ---> ', inv.number)
|
||||
inv.to_draft()
|
||||
inv.post()
|
||||
return True
|
||||
|
||||
Migration.register()
|
|
@ -141,3 +141,4 @@ from . import report_cycle_setting
|
|||
from . import print_labor_cost
|
||||
from . import print_labor_cost_line
|
||||
from . import conv_bal
|
||||
from . import conv_sale_invoice
|
||||
|
|
|
@ -249,6 +249,7 @@ class AccountInvoice(Model):
|
|||
desc=line['description']
|
||||
ar_debit_id=None
|
||||
#ar_credit_id=None
|
||||
# search from patient_type
|
||||
for prod_id in get_model('product').search([['name','=',desc]]):
|
||||
for ptype_id in get_model("clinic.patient.type").search([['contact_id','=',partner.id]]):
|
||||
acc=prod_acc(prod_id,ptype_id,'credit')
|
||||
|
@ -256,8 +257,17 @@ class AccountInvoice(Model):
|
|||
ar_debit_id=acc.get("ar_debit_id")
|
||||
if ar_debit_id:
|
||||
break
|
||||
|
||||
# search from patient
|
||||
if not ar_debit_id:
|
||||
raise Exception("Missing AR Debit Account for product %s"%(desc))
|
||||
for pt in get_model('clinic.patient').search_browse([['partner_id','=',partner.id]]):
|
||||
acc=prod_acc(prod_id,pt.type_id.id,'credit')
|
||||
ar_debit_id=acc.get("ar_debit_id")
|
||||
if ar_debit_id:
|
||||
break
|
||||
if not ar_debit_id:
|
||||
import pdb; pdb.set_trace()
|
||||
raise Exception("Missing AR Debit Account for product %s"%(desc), partner.id, partner.name)
|
||||
line_vals={
|
||||
"description": desc,
|
||||
"account_id": ar_debit_id,
|
||||
|
|
|
@ -27,10 +27,12 @@ class ConvBal(Model):
|
|||
"reconcile_move_line_id": inv.move_line_id.id,
|
||||
"currency_id": inv.account_id.currency_id.id,
|
||||
"currency_rate": inv.amount_due/inv.amount_cur if inv.amount_cur else None,
|
||||
"department_id": inv.department_id.id,
|
||||
}
|
||||
line_vals={
|
||||
"description": desc,
|
||||
"amount": abs(inv.amount_cur or inv.amount_due),
|
||||
"track_id": inv.track_id.id,
|
||||
}
|
||||
vals["lines"].append(("create",line_vals))
|
||||
res=get_model("account.invoice").search([["number","=",inv.number]])
|
||||
|
@ -66,11 +68,26 @@ class ConvBal(Model):
|
|||
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]])
|
||||
|
@ -100,7 +117,6 @@ 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,
|
||||
|
@ -111,10 +127,11 @@ class ConvBal(Model):
|
|||
"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
|
||||
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]])
|
||||
|
@ -133,6 +150,8 @@ class ConvBal(Model):
|
|||
"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:
|
||||
|
@ -150,6 +169,8 @@ class ConvBal(Model):
|
|||
"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 {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
from netforce.model import Model, fields
|
||||
|
||||
class ConvSaleInvoice(Model):
|
||||
_inherit="conv.sale.invoice"
|
||||
_transient=True
|
||||
_fields={
|
||||
"department_id": fields.Many2One("clinic.department","Department"),
|
||||
"track_id": fields.Many2One("account.track.categ","Track1"),
|
||||
}
|
||||
|
||||
|
||||
ConvSaleInvoice.register()
|
Loading…
Reference in New Issue