import csv import xlrd from netforce.model import get_model from netforce import migration from netforce.access import set_active_user, set_active_company from netforce.database import get_connection class Migration(migration.Migration): _name="clinic.update.line.amount" _version="2.12.5" def migrate(self): set_active_company(1) set_active_user(1) cond=[ ['date','>=','2016-11-10'], ['date','<=','2016-11-15'], ['state','in',['waiting_payment','paid']], ] settings=get_model('settings').browse(1) cst=get_model("clinic.setting").browse(1) prod_acc=cst.get_product_account currency_id=settings.currency_id.id for hdcase in get_model("clinic.hd.case").search_browse(cond): print("hdcase.number ", hdcase.id, hdcase.number) patient=hdcase.patient_id ptype=patient.type_id partner=ptype.contact_id track_id=hdcase.branch_id.track_id.id for line in hdcase.lines: categ=line.product_categ_id if line.reimbursable=='yes' and categ.id==34: #Erythopo... prod=line.product_id acc=prod_acc(prod.id,hdcase.patient_type_id.id) account_id=acc.get("ar_credit_id",None) ar_debit_id=acc.get("ar_debit_id",None) # account receiveable amount=line.amount or (line.price*line.qty) or 0 if not amount: continue lines=[ ('create',{ "product_id": prod.id, "description": line.description or "", "qty": line.qty, "uom_id": line.uom_id.id, "unit_price": line.price or 0, "amount": amount, 'account_id': account_id, #'ar_debit_id': ar_debit_id, 'track_id': track_id, }) ] context={ 'date' : hdcase.date, 'branch_id': hdcase.branch_id.id, "type": "out", "inv_type": "invoice", } vals={ "type": "out", "inv_type": "invoice", "tax_type": "tax_in", 'date': hdcase.date, 'due_date': hdcase.date, "ref": '%s (%s)'%(patient.name or '',patient.number or ''), 'department_id': hdcase.department_id.id, "related_id": "clinic.hd.case,%s"%hdcase.id, "currency_id": currency_id, "company_id": hdcase.company_id.id, "partner_id": partner.id, 'patient_partner_id':patient.partner_id.id, 'account_id':account_id, 'lines':lines, } inv_id=get_model("account.invoice").create(vals,context=context) inv=get_model("account.invoice").browse(inv_id) inv.post() Migration.register()