migration: remake invoice

fix_acc
watcha.h 2015-08-19 16:24:29 +07:00
parent 387e5a567a
commit 8f6eea82aa
2 changed files with 24 additions and 22 deletions

View File

@ -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

View File

@ -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',