Skip to Content
Menu
This question has been flagged
2 Replies
2061 Views

Hi,

I have a really strange problem occuring while creating invoices in odoo unittests.

I define a sale order with one order line:

partner_values = {
'name': 'Test',
'email': 'test@odoo.com',
'country_id': 57
}
partner = cls.env['res.partner'].create(partner_values)

# create 1 product
product_values = {'name': 'Bread',
'list_price': 5,
'type': 'product',
'invoice_policy': 'delivery'}
product = cls.env['product.product'].create(product_values)

# product uom
cls.product_uom_unit = cls.env.ref('uom.product_uom_unit')

values = {
'partner_id': partner.id,
'order_line': [(0, 0, {
'name': product.name,
'product_id': product.id,
'product_uom': cls.product_uom_unit.id,
'price_unit': product.list_price,
'product_uom_qty': 1.0})],
}

Then I confirm the order and validate the picking and create the invoice.
Everything works fine so far.

In the next step I try to re-run the steps again:
- confirm sale order -> works fine
- validate picking -> works fine (I have sale order line.qty_delivered = 2.0 which is correct)
- create the invoice -> invoice_status is still 'to invoice'

Problem:
With debugging I found out, that the sale order line is changed inside the account_move.create() method, so that after creating the account_move the qty_delivered is suddenly 1.0.
That leads to invoice_status = 'to invoice' because qty_delivered < qty_invoiced (= 2.0)

When I test it manually everything works as expected, but with the automated tests I get the error that invoice_status is 'to invoice' instead of 'invoiced'.

Does anyone have an idea what might be the problem here?

Avatar
Discard
Author Best Answer

I have found out that it is an odoo bug. In test_sale_stock.py it says:

# There is a bug with `new` and `_origin`

# If you create a first new from a record, then change a value on the origin record, than create another new,

# this other new wont have the updated value of the origin record, but the one from the previous new

# Here the problem lies in the use of `new` in `move = self_ctx.new(new_vals)`,

# and the fact this method is called multiple times in the same transaction test case.

# Here, we update `qty_delivered` on the origin record, but the `new` records which are in cache with this order line

# as origin are not updated, nor the fields that depends on it.

Avatar
Discard