server-tools icon indicating copy to clipboard operation
server-tools copied to clipboard

[15.0] Auditlog: error when creating variants or updating lst_price

Open BT-jcamacho opened this issue 3 years ago • 1 comments

Module

auditlog

Describe the bug

When a rule exists for model product.product, creating of product.products from the Product Variants List View or changing the lst_price (Sales price) raises an Error.

To Reproduce

Affected versions: v15 at least

Steps to reproduce the behavior:

  1. Create a rule that logs write for model Product (product.product)
  2. Go to to the Product Variants list view (i.e, from Sales app -> Products -> Products Variants)
  3. Create a new variant

OR

  1. Open the form view of a variant
  2. Click on edit
  3. Change the sales price (lst_price)

Expected behavior No error should be thrown

Additional context Tested on v15 runboat

I think problems comes from a core onchange in product.product: https://github.com/odoo/odoo/blob/15.0/addons/product/models/product.py#L277-L285

@api.onchange('lst_price')
def _set_product_lst_price(self):
    for product in self:
        if self._context.get('uom'):
            value = self.env['uom.uom'].browse(self._context['uom'])._compute_price(product.lst_price, product.uom_id)
        else:
            value = product.lst_price
        value -= product.price_extra
        product.write({'list_price': value})

where they perform a write() that auditlog tries to track. As its an onchange (which is triggered when creating or updating the lst_price) the record is a "NewId record", which causes problems when reading the fields to track.

BT-jcamacho avatar May 17 '22 11:05 BT-jcamacho

Hi @BT-jcamacho, while testing to migrate from Odoo 14 to 15, I had the same problem. From what I've seen, it's because of what you comment in the issue. It's seen that in version 15 they added this decorator, causing this function to be executed by default when a new product record is created and causing the error to appear.

I've created a PR with a solution to this problem. I've tested it in my environment, and when I create a new product record or edit the sales price, that problem no longer appears.

angelvilaplana avatar Apr 18 '24 23:04 angelvilaplana