Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
5 Trả lời
6835 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello, 

pass the type of the invoice while you create invoice.

see into below dictionary.

 inv_data = {
'type': 'in_invoice',
            '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,
        }
Ảnh đại diện
Huỷ bỏ

what if i want to add lines to invoice lines !!!!!!!!!

into inv_data dictionary add the key and value like

{'invoice_line_ids': [(0, 0, inv_line_vals)]

Câu trả lời hay nhất

you missed type field In Invoice Data .

'type': 'in_invoice'  means Vendor bill
'type': 'out_invoice' means Customer Invoice

By default it's  'out_invoice', so it's creating Customer Invoice

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất


 inv_data = {
'type': 'in_invoice',
            '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,

create a vender bill from purchase order
please tell me the answer as soon as possible.?



Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 18
3850
4
thg 10 20
8988
0
thg 5 24
1488
3
thg 2 24
10439
1
thg 11 23
2847