Skip to content

Commit

Permalink
[FIX] product_cost_price_avco_sync: Change Monetary fields to Float (…
Browse files Browse the repository at this point in the history
…20,8)
  • Loading branch information
carlosdauden authored and pedrobaeza committed Sep 9, 2022
1 parent ece8c4b commit ace19f5
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions product_cost_price_avco_sync/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from collections import OrderedDict, defaultdict

from odoo import _, api, models
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
from odoo.tools import float_compare, float_round

Expand All @@ -21,6 +21,11 @@ class StockValuationLayer(models.Model):

_inherit = "stock.valuation.layer"

# Change Monetary to Float improve decimal precision
unit_cost = fields.Float(digits="Product Price")
value = fields.Float(digits=(20, 8))
remaining_value = fields.Float(digits=(20, 8))

@api.model
def create(self, vals):
svl = super().create(vals)
Expand Down Expand Up @@ -219,14 +224,7 @@ def update_avco_svl_modified(self, svls_dic):
for svl, svl_dic in svls_dic.items():
vals = {}
for field_name, new_value in svl_dic.items():
if float_compare(
svl[field_name],
new_value,
# Currency decimal precision for values and high precision to others
precision_digits=svl.currency_id.decimal_places
if field_name in ("unit_cost", "value", "remaining_value")
else 8,
):
if float_compare(svl[field_name], new_value, precision_digits=8,):
vals[field_name] = new_value
# Write modified fields
if vals:
Expand Down

0 comments on commit ace19f5

Please sign in to comment.