From e20d25029f89beaf0ee61d177486efcbf09b1afa Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Mon, 10 Aug 2015 21:38:19 +0700 Subject: [PATCH] improve conversion balance --- netforce_clinic/migrations/__init__.py | 8 ++---- netforce_clinic/migrations/conv_bal.py | 9 +++++-- netforce_clinic/migrations/repost_invoice.py | 26 ++++++++++++++++++++ netforce_clinic/models/__init__.py | 1 + netforce_clinic/models/account_invoice.py | 12 ++++++++- netforce_clinic/models/conv_bal.py | 25 +++++++++++++++++-- netforce_clinic/models/conv_sale_invoice.py | 12 +++++++++ 7 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 netforce_clinic/migrations/repost_invoice.py create mode 100644 netforce_clinic/models/conv_sale_invoice.py diff --git a/netforce_clinic/migrations/__init__.py b/netforce_clinic/migrations/__init__.py index 0f34312..bde4b2c 100644 --- a/netforce_clinic/migrations/__init__.py +++ b/netforce_clinic/migrations/__init__.py @@ -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 diff --git a/netforce_clinic/migrations/conv_bal.py b/netforce_clinic/migrations/conv_bal.py index 387a1a3..64cf82d 100644 --- a/netforce_clinic/migrations/conv_bal.py +++ b/netforce_clinic/migrations/conv_bal.py @@ -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...") diff --git a/netforce_clinic/migrations/repost_invoice.py b/netforce_clinic/migrations/repost_invoice.py new file mode 100644 index 0000000..40b2b92 --- /dev/null +++ b/netforce_clinic/migrations/repost_invoice.py @@ -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() diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py index babbd2b..7c9cbfa 100644 --- a/netforce_clinic/models/__init__.py +++ b/netforce_clinic/models/__init__.py @@ -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 diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py index 44d1c39..7e40169 100644 --- a/netforce_clinic/models/account_invoice.py +++ b/netforce_clinic/models/account_invoice.py @@ -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, diff --git a/netforce_clinic/models/conv_bal.py b/netforce_clinic/models/conv_bal.py index 4bfb59c..6023d6e 100644 --- a/netforce_clinic/models/conv_bal.py +++ b/netforce_clinic/models/conv_bal.py @@ -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 { diff --git a/netforce_clinic/models/conv_sale_invoice.py b/netforce_clinic/models/conv_sale_invoice.py new file mode 100644 index 0000000..4ecfb59 --- /dev/null +++ b/netforce_clinic/models/conv_sale_invoice.py @@ -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()