Ir al contenido
Menú
Se marcó esta pregunta
7 Respuestas
6647 Vistas

Hello Community,

Recently I have been trying to create vendor bills in odoo13 by code by apparently every time I run the code I get a message "Cannot create unbalanced journal entry. Ids: [177] Differences debit - credit: [3.5]"

3.5 in my unit_price.

My code is below:

payment_move = self.env['account.move'].create({
'type': 'in_invoice',
'partner_id': self.client.id,
})
payment_move.invoice_line_ids.create({'move_id': payment_move.id,
'quantity': 1.0,
'price_unit': 3.5,
'account_id': self.env['account.account'].search(
[('user_type_id', '=', self.env.ref('account.data_account_type_expenses').id)], limit=1).id})

Thanks in advance.

Avatar
Descartar
Mejor respuesta

This may help

Create invoices/credit notes in odoo13 by code

Avatar
Descartar

hello paresh wagh can you share your answer here i think your link can't find page.

Thank You in advance.

The link seems to be working fine. It's a link to another thread where this same topic was discussed.

@Paresh i also check and link don't work :(

Pasting the link here since there are multiple posts in the thread that provide contextual information.

https://www.odoo.com/forum/help-1/question/create-invoices-credit-notes-in-odoo13-by-code-163575#answer-163579

If this does not work, please report an issue with Odoo at

https://github.com/odoo/odoo/issues

Mejor respuesta

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
Avatar
Descartar
Mejor respuesta
See how I handle invoice_line_ids below:

            invoice_move = self.env['account.move'].create({
                'type''out_invoice',
                'partner_id': client_partner_id_variable,
            })
            invoice_move.write({
                'invoice_line_ids': [(00, {
                    'move_id': invoice_move.id,
                    'quantity'1.0,
                    'price_unit'3.5,
                    'account_id'self.env['account.account'].search( [('user_type_id''='self.env.ref('account.data_account_type_expenses').id)], limit=1 ).id
                 })]
            })
Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
dic 24
4474
1
nov 24
3249
2
abr 23
18281
1
mar 23
2480
4
ago 24
24379