Trợ giúp


[SOLVE][Odoo12.0]How to create bill and receive product from 1 button for purchase?

Jignesh Mehta


I added 1 button in Purchase order that is work for Receive Product and Create Bill at once.

Code :-

def receive_with_bill(self):
    new_invoice = self.action_view_invoice()
    picking_ids = self.env['stock.picking'].search([('origin', '=',])
    for picking in picking_ids:
        self.env['stock.immediate.transfer'].create({'pick_ids': [(4,]}).process()

Here Stock Picking is validated and stock is updated, but Bill isn't create.

I added print statement in action_view_invoice() which is in the under puchase module. This method is also called but Bill isn't create.

How to solve this issue in odoo12.0 ?

Any answer will be appreciable.


Ảnh đại diện
Huỷ bỏ
1 Trả lời
Best Answer

You need to write code for create invoice in your function.  action_view_invoice is not a method to create invoice. Below is the code to create invoice after receive product. You need to pass PO id in invoice during creation-

po_invoice = {
'state': 'draft',
'type': 'in_invoice',
'date_invoice': self.date_order,

inv = self.env['account.invoice'].create(po_invoice)

One more suggestion rathen than doing picking search with origin, You can find picking_ids field in PO which show all incoming shipment related to PO.

Ảnh đại diện
Huỷ bỏ