Create new sale error

Hello all.

I call this code from route.py and I have error at last command sale.process([sale])
The error is trytond.exceptions.UserError: There is no "Account Category" defined on the product "Product name"

Where is the fail ?
Any help ?

     ### Sale ###
    Sale = pool.get('sale.sale')
    sale, = Sale.create([{
        'company': 1,
        'invoice_method': 'order',
        'shipment_method': 'order',
        'party': party_invoiced.id,
        'shipment_party': party_shipment.id,
        'deliverent_party': party_delivered.id,
        'invoice_address': address_invoiced.id,
        'shipment_address': address_shipment.id,
        'deliverent_address': address_delivered.id,
        'currency': currency,
    }])

    ### Lines ###
    for line in data['lines']:
        product = Product.search([('code', '=', line[1])])[0]

        Line = pool.get('sale.line')
        line, = Line.create([{
            'type': 'line',
            'sale': sale.id,
            'product': product.id,
            'unit': product.default_uom,
            'quantity': line[2],
            'unit_price': line[3],
            'note': line[0],
        }])
        LineTax = pool.get('sale.line-account.tax')
        tax, = LineTax.create([{
            'line': line.id,
            'tax': product.customer_taxes_used[0],
        }])

    sale.quote([sale])
    sale.confirm([sale])
    sale.process([sale])

The problem is that your product is not correctly configured. You are missing an Account Category on it or the account category does not have any Receivable Account

Note that this is required to process the sale as in this case an invoice is created.
Another option is to use the invoice method based on shipment. This will fix the problem but it will be raised latter when finishing the shipment.

So the best is to configure the products properly.

Thanks pokoli for your answer but I have all them at product. Do I not have them?
Is there anything else I need to do?

I see you have the company hard coded. So I’m guessing that it is not set in the context.
So depending of the version, the code can not get the company-related multivalue where the account is stored.

I have the trytond __version__ = "5.0.18"

I changed the code with :

...
'company': user.company,
...

The same error again :slightly_frowning_face:
If I use the web interface (sao), all steps work fine. I have seen the code :

modules/sale/sale.py", line 885, in process
modules/sale/sale.py", line 724, in create_invoice
modules/sale/sale.py", line 1337, in get_invoice_line
modules/account_product/product.py", line 49, in prop
modules/account_product/product.py", line 38, in wrapper
error.py", line 74, in raise_user_error

but I can not figure out what the error is

I do not know what it means but you must set the company in the context in version 5.0 for sure. It is so old that multi-company was not really supported.

Thanks, I will try this because I do POST with other client (requests) and I will let you know what happened.
I’m currently doing my job with proteus.

I will come soon…

If you consider the option to upgrade to newer series, on 6.0 we implemented the multi-company support so with that version it will be easier to manage such cases.