Skip to content

Instantly share code, notes, and snippets.

@3mrdev
Created October 8, 2022 13:43
Show Gist options
  • Save 3mrdev/af14a1de1cdd12a57aa5c8314807adac to your computer and use it in GitHub Desktop.
Save 3mrdev/af14a1de1cdd12a57aa5c8314807adac to your computer and use it in GitHub Desktop.
How to create an invoice from any model in Odoo
def create_invoice(self):
move_dict = {
'narration': "Name",
'ref': name,
'journal_id': journal_id.id,
'date': date,
}
line_ids = []
debit_line = {
'name': "Name",
'partner_id': partner_id.id,
'account_id': debit_account_id.id,
'journal_id': journal_id.id,
'date': date,
'debit': round(amount if amount > 0.0 else -amount),
'credit': 0.0,
'analytic_account_id': analytic_account_id,
'tax_line_id': tax_account_id,
}
credit_line = {
'name': "Name",
'partner_id': partner_id.id,
'account_id': credit_account_id.id,
'journal_id': journal_id.id,
'date': date,
'debit': 0.0,
'credit': round(amount if amount > 0.0 else -amount),
'analytic_account_id': analytic_account_id.id,
'tax_line_id': tax_account_id.id,
}
line_ids.append(debit_line)
line_ids.append(credit_line)
move_dict['line_ids'] = line_ids
move = self.env['account.move'].create(move_dict)
move.post()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment