See That works fine for me.
This is becuse you are giving just one entry for example debit or credit you must do two entries with same amount like that.
'line_ids': [
(0, 0, {
'account_id': account,
'debit': sale_orders[0].charger_id,
}),
(0, 0, {
'account_id': account_other,
'credit': sale_orders[0].charger_id,
}),
I created below invoice too. I hope this will help you too.
def _prepare_invoice_values(self, order, name, amount, so_line):
invoice_line = super(VisioJournalItem, self)._prepare_invoice_values(order, name, amount, so_line)
account_a = self.env.ref('visio_chargers_journal_item.visio_b_dividends').id
account_id = self.env.ref('visio_chargers_journal_item.visio_a_dividends').id
account_o = self.env.ref('visio_chargers_journal_item.visio_c_dividends').id
sale_orders = self.env['sale.order'].browse(self._context.get('active_ids', []))
order = sale_orders[0]
so_line = order.order_line[0]
line1= {
'name': 'Freight Charger',
'price_unit': order.charger_id,
'account_id': account_id,
'exclude_from_invoice_tab': True,
}
line2 = {
'name': 'Insurance Amount',
'price_unit': order.insurance_amount_id,
'account_id': account_a,
'exclude_from_invoice_tab': True,
}
line3 = {
'name': 'Tax Amount NTN',
'price_unit': order.tax_id,
'account_id': account_o,
'exclude_from_invoice_tab': True,
}
lines = [line1, line2, line3]
for line in lines:
line['quantity'] = 1.0
line['sale_line_ids'] = [(6, 0, [so_line.id])]
line['analytic_tag_ids'] = [(6, 0, so_line.analytic_tag_ids.ids)]
line['analytic_account_id'] = order.analytic_account_id.id or False
invoice_line['invoice_line_ids'].append(line)
return invoice_line
Regards
MUHAMMAD IMRAN
Technical and Functional Consultant (ODOO)
Softtar Technologies Pvt. Ltd. Contact : Pakistan (+92)-3037701373
Address:
Allhafeez Shopping Mall
Lahore
Pakistan (Branch Office)
http://sofftar.com