Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
4852 Представления

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,

Аватар
Отменить
Лучший ответ

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.

Аватар
Отменить
Related Posts Ответы Просмотры Активность
6
мая 20
4649
0
мар. 15
4259
4
авг. 25
2073
1
июн. 22
3179
2
нояб. 21
2687