I am trying to create an invoice from a custom object but I am getting errors from on validation .When I post, i get the following error: "
ValueError: Wrong value for account.move.line_ids: {'display_type': 'line_section', 'name': 'Phone Bill', 'product_id': 11783, 'product_uom_id': 19, 'current_reading': 66.0, 'current_date': datetime.date(2020, 11, 3), 'quantity': 17.0, 'price_unit': 565.0, 'account_id': 19, 'debit': 9605.0, 'credit': 0.0}
current_date and current_reading are custom fields i created. I am aware that Odoo automatically creates values for line_ids from invoice_line_ids if line_ids is not provided, so I am really stuck about this error.
Here's my code for creating the invoice:
def validate_entry(self):
active_ids = self._context.get('active_ids', []) or []
company = self.env.user.company_id
journal = self.env['account.move'].with_context(force_company=company.id, type='out_invoice')._get_default_journal()
for reads in self.env['reading.upload'].browse(active_ids):
if reads.reading >= reads.previous_reading and reads.state == 'draft':
account = reads.product_id.product_tmpl_id._get_product_accounts()['income']
if not account:
raise UserError(_('No account defined for product "%s".') % reads.product_id.name)
inv_line_ids= {
'display_type': 'line_section',
'name': reads.product_id.name,
'product_id': reads.product_id.id,
'product_uom_id': reads.product_id.uom_id.id,
'current_reading': reads.reading,
'current_date': reads.read_date,
'quantity': reads.reading - reads.previous_reading,
'price_unit': reads.product_id.product_tmpl_id.list_price,
'account_id': account.id,
'debit': (reads.reading - reads.previous_reading) * reads.product_id.product_tmpl_id.list_price,
'credit': 0.0,
#'currency_id': reads.meter_id.customer_id.currency_id.id,
#'tax_ids':[],
}
invoice = {
'type': 'out_invoice',
'invoice_date':reads.read_date,
'narration': reads.remark,
'invoice_user_id': reads.current_user.id,
'partner_id': reads.meter_id.customer_id.id,
'fiscal_position_id': reads.meter_id.customer_id.property_account_position_id.id,
'invoice_line_ids': inv_line_ids,
'journal_id': journal.id,
'currency_id': reads.meter_id.customer_id.currency_id.id,
'doc_type': 'bill',
}
moves = self.env['account.move'].with_context(default_type='out_invoice').create(invoice)
reads.write({'state':'uploaded'})
Any help given will be appreciated. Thanks