From 8f6eea82aa1ded05da0662a38a3c4c2d6f351b74 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Wed, 19 Aug 2015 16:24:29 +0700 Subject: [PATCH] migration: remake invoice --- netforce_clinic/migrations/repost_invoice.py | 42 ++++++++++---------- netforce_clinic/models/hd_case.py | 4 +- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/netforce_clinic/migrations/repost_invoice.py b/netforce_clinic/migrations/repost_invoice.py index 401fb53..7a59ab8 100644 --- a/netforce_clinic/migrations/repost_invoice.py +++ b/netforce_clinic/migrations/repost_invoice.py @@ -9,30 +9,32 @@ class Migration(migration.Migration): def migrate(self): set_active_user(1) set_active_company(1) - for hdcase_line in get_model('clinic.hd.case.line').search_browse([['description','=',None]]): - prod=hdcase_line.product_id - if prod: - hdcase_line.write({ - 'description': prod.name, - }) - - for hdcase in get_model('clinic.hd.case').search_browse([]): + dom=[ + ['department_id','=',2], + ['date','>=','2015-08-18'], + ['date','<=','2015-08-18'], + ] + hdcase_ids=set() + for hdcase in get_model('clinic.hd.case').search_browse(dom): + reset=False for inv in hdcase.invoices: if inv.state=='waiting_payment': - print('hdcase:repost ---> ', inv.number) inv.to_draft() - inv.write({ - 'hdcase_reconcile': True, + inv.delete() + reset=True + hdcase_ids.update({hdcase.id}) + if reset: + for line in hdcase.lines: + line.write({ + 'state': 'draft', }) - inv.post() - for shop in get_model('clinic.shop').search_browse([]): - for inv in shop.invoices: - print('shop:repost ---> ', inv.number) - inv.to_draft() - inv.write({ - 'hdcase_reconcile': True, - }) - inv.post() + ids=list(hdcase_ids) + for hdcase in get_model('clinic.hd.case').browse(ids): + print('remake_invoice ---> ', hdcase.number) + ctx={ + 'is_migrate': True, + } + hdcase.make_invoices(context=ctx) print("Done!") return True diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index 2c6588e..92bb355 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -741,8 +741,8 @@ class HDCase(Model): vals['lines']=lines get_model("account.invoice").create(vals,context) - obj.make_pickings() - # prevent douplicate create invoice & picking + if not context.get('is_migrate'): + obj.make_pickings() for line in obj.lines: line.write({ 'state': 'done',