0

Good day, I am tiring to create an invoice with a custom module, the below code gives me an error.

....... invoice = self.with_context(pricelist_context).create_invoice(product_data,inv_data) Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Program Files\Odoo\15\server\odoo\http.py", line 644, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "C:\Program Files\Odoo\15\server\odoo\http.py", line 302, in _handle_exception raise exception.with_traceback(None) from new_cause TypeError: create_invoice() takes 1 positional argument but 3 were given

def create_invoice(self):
    
        product_id = self.product_id
        
        product_data = [{'product_id': product_id}]
        if self.medical_aid_company_id:
            price = product_id._get_medical_aid_price(self.medical_aid_company_id)
            if price:
                product_data[0]['price_unit'] = price

        for rec in self.billable_line_ids:
            product_data.append({
                'product_id': rec.product_id,
                'quantity': rec.qty,
            })
        inv_data = {
            'consultation_id': self.id,
            'partner': self.patient_id,
        }

        pricelist_context = {}
        if self.pricelist_id:
            pricelist_context = {'set_pricelist_id': self.pricelist_id.id}
        invoice = self.with_context(pricelist_context).create_invoice(product_data,inv_data)
        self.invoice_id = invoice.id
CZoellner
  • 13,553
  • 3
  • 25
  • 38
Abraham Kalungi
  • 45
  • 1
  • 10
  • You're calling `create_invoice()` with 2 parameters but the method is not expecting a parameter at all. – CZoellner Apr 11 '22 at 14:50
  • And it looks like you recursively calling it, too. Are you sure you want to call `create_invoice` at the end or do you probably want to call another method there? – CZoellner Apr 11 '22 at 14:53
  • You can check the create invoice from repair order [link](https://github.com/odoo/odoo/blob/15.0/addons/repair/models/repair.py#L320) – Waleed Mohsen Apr 11 '22 at 20:39

0 Answers0