i use method to create automatic create journal use this script odoo11:
po_line_vals1 = {
'name': ref,
'account_id': line.product_id.property_account_expense_id.id,
'credit': 0.0 if float_compare(amount, 0.0, precision_digits=prec) > 0 else -amount,
'debit': amount if float_compare(amount, 0.0, precision_digits=prec) > 0 else 0.0,
'journal_id': r.journal_id.id,
'move_id': pur_order.id,
'company_id': r.company_id.id,
'currency_id': company_currency != current_currency and current_currency.id or False,
'amount_currency': company_currency != current_currency and - 1.0 * line.standard_price or 0.0,
}
po_line_vals2 = {
'name': ref,
'account_id': line.x_stock_out_account.id,
'debit': 0.0 if float_compare(amount, 0.0, precision_digits=prec) > 0 else -amount,
'credit': amount if float_compare(amount, 0.0, precision_digits=prec) > 0 else 0.0,
'journal_id': r.journal_id.id,
'move_id': pur_order.id,
'company_id': r.company_id.id,
'currency_id': company_currency != current_currency and current_currency.id or False,
'amount_currency': company_currency != current_currency and line.standard_price or 0.0,
}
vals = {
'line_ids': [(0, 0, po_line_vals1),(0, 0, po_line_vals2)],
}
purchase_order_obj.create(vals)
else:
po_line_vals1 = {
'name': ref,
'account_id': line.product_id.property_account_expense_id.id,
'debit': 0.0 if float_compare(amount, 0.0, precision_digits=prec) > 0 else -amount,
'credit': amount if float_compare(amount, 0.0, precision_digits=prec) > 0 else 0.0,
'journal_id': r.journal_id.id,
'vehicle_id': r.vehicle_id.id,
'partner_id': r.person_id.id,
'company_id': r.company_id.id,
'currency_id': company_currency != current_currency and current_currency.id or False,
'amount_currency': company_currency != current_currency and - 1.0 * line.standard_price or 0.0,
}
po_line_vals2 = {
'name': ref,
'account_id': line.x_stock_out_account.id,
'credit': 0.0 if float_compare(amount, 0.0, precision_digits=prec) > 0 else -amount,
'debit': amount if float_compare(amount, 0.0, precision_digits=prec) > 0 else 0.0,
'journal_id': r.journal_id.id,
'vehicle_id': r.vehicle_id.id,
'partner_id': r.person_id.id,
'company_id': r.company_id.id,
# 'analytic_account_id': category_id.account_analytic_id.id if category_id.type == 'purchase' else False,
'currency_id': company_currency != current_currency and current_currency.id or False,
'amount_currency': company_currency != current_currency and line.standard_price or 0.0,
}
vals = {
'ref': r.name,
'stock_picking': self.id,
'date': adv_exp_date or False,
'journal_id': r.journal_id.id,
'company_id': r.company_id.id,
'narration': r.note,
'line_ids': [(0, 0, po_line_vals1), (0, 0, po_line_vals2)],
}
purchase_order_obj.create(vals)
This jurnal has been created
but when i create 2 item. all item succes created if value second item is zero. if second item value not zero is error "canot create unbalanced journal."
anyone can help me ?