Odoo 16 Failed to Link Invoice with sales order Via PHP Ripcord

119 Views Asked by At

I need to Create Sales order and Invoice from external API as i need to insert data to Odoo from a Web app. I have made functions to insert sales order and Invoice. Everything is working fine here. But after creating Invoice, when I try to update Sales.order model's "invoice_ids" field, the response is true but when i get detail of sale order, its invoice_ids filed has empty array.

Here is My code to insert Invoice and Update sales order with Invoice Id

 public function CreateInvoice($invoiceData, $OrderId,$IsInvoiceToBeConfirmed)
    {
        $result["err"] = 0;
        $result["invoice_id"] = 0;
        $result["order_id"] =$OrderId;
        try
        {

           
            $invoiceId = $this->models->execute_kw($this->db, $this->uid, $this->password,
                        'account.move', 'create',
                        array($invoiceData)
                        );



            
            if($invoiceId>0)
            {
                $result['invoice_id'] = $invoiceId;  

                $finalResult = $this->models->execute_kw($this->db, $this->uid, $this->password,
                    'sale.order', 'write',
                    array(array($OrderId), array('invoice_ids'=>array(array(4,$invoiceId))))
                );


                var_dump($finalResult); // Returns true
               
                die;
           }
}




0

There are 0 best solutions below