2015-08-10 14:38:19 +00:00
|
|
|
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)
|
2015-08-19 09:24:29 +00:00
|
|
|
dom=[
|
2015-08-19 11:39:20 +00:00
|
|
|
#['department_id','=',2],
|
|
|
|
#['date','>=','2015-08-18'],
|
|
|
|
#['date','<=','2015-08-18'],
|
2015-08-19 09:24:29 +00:00
|
|
|
]
|
|
|
|
hdcase_ids=set()
|
|
|
|
for hdcase in get_model('clinic.hd.case').search_browse(dom):
|
|
|
|
reset=False
|
2015-08-10 14:38:19 +00:00
|
|
|
for inv in hdcase.invoices:
|
|
|
|
if inv.state=='waiting_payment':
|
|
|
|
inv.to_draft()
|
2015-08-19 09:24:29 +00:00
|
|
|
inv.delete()
|
|
|
|
reset=True
|
|
|
|
hdcase_ids.update({hdcase.id})
|
|
|
|
if reset:
|
|
|
|
for line in hdcase.lines:
|
|
|
|
line.write({
|
|
|
|
'state': 'draft',
|
2015-08-11 04:35:46 +00:00
|
|
|
})
|
2015-08-19 09:24:29 +00:00
|
|
|
ids=list(hdcase_ids)
|
2015-08-26 15:01:45 +00:00
|
|
|
for seq in get_model("sequence").search_browse([['type','in',['cust_invoice','clinic_invoice_noclaim']]]):
|
|
|
|
seq.write({
|
|
|
|
'running': [('delete_all'),],
|
|
|
|
})
|
2015-08-19 09:24:29 +00:00
|
|
|
for hdcase in get_model('clinic.hd.case').browse(ids):
|
|
|
|
print('remake_invoice ---> ', hdcase.number)
|
|
|
|
ctx={
|
|
|
|
'is_migrate': True,
|
|
|
|
}
|
|
|
|
hdcase.make_invoices(context=ctx)
|
2015-08-26 15:01:45 +00:00
|
|
|
hdcase.post_invoices()
|
2015-08-11 04:35:46 +00:00
|
|
|
print("Done!")
|
2015-08-10 14:38:19 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
Migration.register()
|