跳至内容
菜单
此问题已终结

I'm adding some extra fields to products that set the product's sale price. In the process, I made the Sales Price (list_price) field a compute value. But, when Odoo.sh runs the unit tests, I get assertion errors because list_price has turned into a read only field because of the compute method. So, I tried adding an inverse method (_set_list_price) to allow the field's edition.

My issue? The inverse method doesn't apply the values to the corresponding fields when creating the record (it works when editing the record, but not when creating it).

I used the log to verify if the method was being called at all, and it is! But after the computing, the server show:

2020-04-13 22:03:07,976 3968 INFO mybranch odoo.modules.registry: At least one model cache has been invalidated, signaling through the database. 

Which doesn't appear when the inverse method works.

Here's the field definition (I overrided the Odoo's original definition by adding only the compute and inverse values).

# overriding product_template.py
# list_price: catalog price, user defined
list_price = fields.Float(
    'Sales Price', default=1.0,
     compute='_compute_list_price',
     readonly=False,
    inverse='_set_list_price',
    digits='Product Price',
     help="Price at which the product is sold to customers.")

  And here's a log's portion when the inverse method is triggered:

2020-04-13 22:12:25,987 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _set_list_price
2020-04-13 22:12:25,987 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: New standard_price -> 40.0
2020-04-13 22:12:26,013 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_fob_total
2020-04-13 22:12:26,014 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_vendor_discounted
2020-04-13 22:12:26,014 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new discount - 0.0 * 0.0% = 0.0
2020-04-13 22:12:26,014 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new fob - 0.0 - 0.0 = 0.0
2020-04-13 22:12:26,014 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_cost
2020-04-13 22:12:26,014 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_tariff_cost
2020-04-13 22:12:26,014 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new tariff cost - 8.0% x 0.0 0.0
2020-04-13 22:12:26,015 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new cost - 0.0 + 0.0 + 0.0 = 0.0
2020-04-13 22:12:26,015 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_profit_margin
2020-04-13 22:12:26,015 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new profit margin - 0.0 * 30.0% =  0.0
2020-04-13 22:12:26,047 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_fob_total
2020-04-13 22:12:26,049 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_vendor_discounted
2020-04-13 22:12:26,049 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new discount - 0.0 * 0.0% = 0.0
2020-04-13 22:12:26,049 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new fob - 0.0 - 0.0 = 0.0
2020-04-13 22:12:26,050 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_cost
2020-04-13 22:12:26,050 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_tariff_cost
2020-04-13 22:12:26,050 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new tariff cost - 8.0% x 0.0 0.0
2020-04-13 22:12:26,050 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new cost - 0.0 + 0.0 + 0.0 = 0.0
2020-04-13 22:12:26,050 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_profit_margin
2020-04-13 22:12:26,051 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new profit margin - 0.0 * 30.0% =  0.0
2020-04-13 22:12:26,055 3968 INFO ipexdr-product-fields-1023588 odoo.modules.registry: At least one model cache has been invalidated, signaling through the database.
2020-04-13 22:12:26,057 3968 INFO ipexdr-product-fields-1023588 werkzeug: 190.6.136.201 - - [13/Apr/2020 22:12:26] "POST /web/dataset/call_kw/product.template/create HTTP/1.0" 200 - 62 0.054 0.056
2020-04-13 22:12:26,269 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_list_price

After that, the fields stay the same way they were by default, but when I try to edit again:


2020-04-13 22:17:04,342 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _set_list_price
2020-04-13 22:17:04,363 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: New standard_price -> 40.0
2020-04-13 22:17:04,364 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_vendor_discounted
2020-04-13 22:17:04,365 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new discount - 40.0 * 0.0% = 0.0
2020-04-13 22:17:04,365 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_fob_total
2020-04-13 22:17:04,366 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new fob - 40.0 - 0.0 = 40.0
2020-04-13 22:17:04,366 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_cost
2020-04-13 22:17:04,366 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_tariff_cost
2020-04-13 22:17:04,366 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new tariff cost - 8.0% x 40.0 3.2
2020-04-13 22:17:04,366 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new cost - 40.0 + 3.2 + 0.0 = 43.2
2020-04-13 22:17:04,366 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_profit_margin
2020-04-13 22:17:04,367 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new profit margin - 43.2 * 30.0% =  12.96
2020-04-13 22:17:04,371 3968 INFO ipexdr-product-fields-1023588 werkzeug: 190.6.136.201 - - [13/Apr/2020 22:17:04] "POST /web/dataset/call_kw/product.template/write HTTP/1.0" 200 - 29 0.022 0.026
2020-04-13 22:17:04,558 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: _compute_list_price
2020-04-13 22:17:04,562 3968 INFO ipexdr-product-fields-1023588 odoo.addons.quote_fields.models.product: new list price - 43.2 + 12.96 = 56.160000000000004

It works, and I don't know why it doesn't when creating the Product. I've tried using onchange or depends instead of inverse, or using recordset.write() to write every record at the same time, but only create more problems.

形象
丢弃
相关帖文 回复 查看 活动
2
12月 20
7259
0
6月 21
2543
1
11月 24
39754
2
12月 22
7455
2
8月 21
7379