-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX][13.0]stock_account: Fix stock valuation layer #339
base: 13.0
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ def _prepare_in_svl_vals(move, quantity, unit_cost, product, is_dropship): | |
return vals | ||
|
||
|
||
def _prepare_out_svl_vals(move, quantity, unit_cost, product, value=0.0, cost_method=False): | ||
def _prepare_out_svl_vals(move, quantity, unit_cost, product, value=0.0): | ||
# Quantity is negative for out valuation layers. | ||
quantity = -quantity | ||
vals = _prepare_common_svl_vals(move, product) | ||
|
@@ -60,7 +60,7 @@ def _prepare_out_svl_vals(move, quantity, unit_cost, product, value=0.0, cost_me | |
"remaining_qty": 0.0, | ||
"remaining_value": 0.0, | ||
}) | ||
if cost_method == 'fifo': | ||
if product.cost_method == 'fifo': | ||
vals.update({ | ||
"value": value, | ||
"unit_cost": value/quantity if quantity else 0, | ||
|
@@ -166,11 +166,13 @@ def generate_stock_valuation_layer(env): | |
have_qty = not float_is_zero(previous_qty, precision_digits=precision_uom) | ||
while h_index < len(history_lines) and history_lines[h_index]["datetime"] < move["date"]: | ||
price_history_rec = history_lines[h_index] | ||
if float_compare(price_history_rec["cost"], previous_price, precision_digits=precision_price): | ||
old_price = history_lines[h_index-1]["cost"] if h_index > 0 else price_history_rec["cost"] | ||
if float_compare(price_history_rec["cost"], old_price, precision_digits=precision_price): | ||
if have_qty: | ||
svl_vals = _prepare_man_svl_vals( | ||
price_history_rec, previous_price, previous_qty, company, product) | ||
price_history_rec, old_price, previous_qty, company, product) | ||
svl_man_vals_list.append(svl_vals) | ||
old_price = price_history_rec["cost"] | ||
Comment on lines
+169
to
+175
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Khi sinh ra định giá tồn kho do việc điều chỉnh giá thủ công, dựa vào chênh lệch giá giữa các bản ghi trong |
||
previous_price = price_history_rec["cost"] | ||
h_index += 1 | ||
# Add in svl | ||
|
@@ -183,8 +185,11 @@ def generate_stock_valuation_layer(env): | |
previous_price = float_round( | ||
(previous_price * previous_qty + move["price_unit"] * move["product_qty"]) / total_qty, | ||
precision_digits=precision_price) | ||
valuation_price_unit = move["price_unit"] | ||
if product.cost_method == 'standard': | ||
valuation_price_unit = price_history_rec["cost"] | ||
svl_vals = _prepare_in_svl_vals( | ||
move, move["product_qty"], move["price_unit"], product, is_dropship) | ||
move, move["product_qty"], valuation_price_unit, product, is_dropship) | ||
svl_in_vals_list.append(svl_vals) | ||
previous_qty = total_qty | ||
Comment on lines
+188
to
194
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nếu sản phẩm được định giá theo phương pháp "Giá tiêu chuẩn" thì khi sinh ra định giá tồn kho phải lấy giá trên sản phẩm tại thời điểm đó (giá trong bảng |
||
# Add out svl | ||
|
@@ -211,10 +216,13 @@ def generate_stock_valuation_layer(env): | |
if product.cost_method == 'fifo': | ||
svl_vals = _prepare_out_svl_vals( | ||
move, move["product_qty"], abs(move["price_unit"]), product, | ||
value=move["value"], cost_method=product.cost_method) | ||
value=move["value"]) | ||
else: | ||
valuation_price_unit = previous_price | ||
if product.cost_method == 'standard': | ||
valuation_price_unit = price_history_rec["cost"] | ||
svl_vals = _prepare_out_svl_vals( | ||
move, move["product_qty"], previous_price, product) | ||
move, move["product_qty"], valuation_price_unit, product) | ||
svl_out_vals_list.append(svl_vals) | ||
previous_qty -= move["product_qty"] | ||
# Add manual adjusts after last move | ||
|
@@ -223,11 +231,12 @@ def generate_stock_valuation_layer(env): | |
# useless for Fifo because we have price unit on product form | ||
while h_index < len(history_lines): | ||
price_history_rec = history_lines[h_index] | ||
if float_compare(price_history_rec["cost"], previous_price, precision_digits=precision_price): | ||
old_price = history_lines[h_index-1]["cost"] if h_index > 0 else price_history_rec["cost"] | ||
if float_compare(price_history_rec["cost"], old_price, precision_digits=precision_price): | ||
svl_vals = _prepare_man_svl_vals( | ||
price_history_rec, previous_price, previous_qty, company, product) | ||
price_history_rec, old_price, previous_qty, company, product) | ||
svl_man_vals_list.append(svl_vals) | ||
previous_price = price_history_rec["cost"] | ||
old_price = price_history_rec["cost"] | ||
h_index += 1 | ||
all_svl_list.extend(svl_in_vals_list + svl_out_vals_list + svl_man_vals_list) | ||
if all_svl_list: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chỉnh sửa lại hàm này, không cần truyền vào
cost_method
vì đó chính làcost_method
của product