I plan to create vendor bills and automatically validate them using the following code. The problem with my code is that it creates customer invoice instead of supplier/vendor invoice and the invoice is not validated automatically. How to correct?
@api.multi
def pay_commission(self):
journal = self.env['account.invoice']._default_journal().id
supplier_line = {
'product_id': self.use_product.id,
'name': self.use_product.name,
'quantity': 1,
'account_id': journal,
'price_unit': self.commission,
}
record_line = {
'partner_id': self.user_id.id,
'invoice_line_ids': [(0, 0, supplier_line)],
}
record = self.env['account.invoice'].create(record_line)
self.env['account.invoice'].action_invoice_open()
return record