Trợ giúp

0

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

Avatar
Jignesh Mehta

Hello,

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

Code :-

@api.multi
def receive_with_bill(self):
    new_invoice = self.action_view_invoice()
    picking_ids = self.env['stock.picking'].search([('origin', '=', self.name)])
    for picking in picking_ids:
        picking.action_confirm()
        picking.button_validate()
        self.env['stock.immediate.transfer'].create({'pick_ids': [(4, picking.id)]}).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 purchase.py 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.

Thanks,

Ảnh đại diện
Huỷ bỏ
1 Trả lời
3
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 = {
'partner_id': self.partner_id.id,
'account_id': self.partner_id.property_account_payable_id.id,
'state': 'draft',
'type': 'in_invoice',
'date_invoice': self.date_order,
'purchase_id': self.id,
}

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

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ỏ