Hello Experts,
I am trying to generate vendor bills from the custom module. but code is inserting/creating bills in the customer invoice. Following is the code which i am using. Can you please guide where i am doing wrong.
@api.multi
def create_invoices(self):
self.state = 'create_invoices'
inv_obj = self.env['account.invoice']
inv_line_obj = self.env['account.invoice.line']
vendor = self.vendor_id
if not vendor.name:
raise UserError(
_(
'Please select a Vendor Name.'))
company_id = self.env['res.users'].browse(1).company_id
currency_value = company_id.currency_id.id
self.ensure_one()
ir_values = self.env['ir.values']
journal_id = ir_values.get_default('cust.mod', 'invoice_journal_type')
if not journal_id:
journal_id = 1
inv_data = {
'name': vendor.name,
'reference': self.name,
'account_id': vendor.property_account_payable_id.id,
'partner_id': vendor.id,
'currency_id': currency_value,
'journal_id': journal_id,
'origin': self.name,
'company_id': company_id.id,
}
inv_id = inv_obj.create(inv_data)
for records in self.cust_line:
if records.exp_id.product_id :
expense_account = records.exp_id.product.property_account_expense_id.id
if not expense_account:
raise UserError(_('There is no expense account defined for this product: "%s".') %
(records.exp_id.product.name,))
inv_line_data = {
'name': records.exp_id.product.name,
'account_id': expense_account,
'price_unit': records.amount,
'quantity': 1,
'product_id': records.exp_id.product.product_id,
'invoice_id': inv_id.id,
}
inv_line_obj.create(inv_line_data)
in xml using button code to generate vendor bill.