Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stock_currency_valuation/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from . import models
from . import wizard
# from . import wizard
14 changes: 8 additions & 6 deletions stock_currency_valuation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Stock currency valuation",
"version": "18.0.1.1.0",
"version": "19.0.1.0.0",
"category": "Warehouse Management",
"sequence": 14,
"summary": "",
Expand All @@ -9,18 +9,20 @@
"images": [],
"depends": [
"stock_account",
"stock_landed_costs",
# "stock_landed_costs",
"product_replenishment_cost",
],
"data": [
"views/product_category.xml",
"views/stock_picking.xml",
"views/stock_landed_cost_views.xml",
# "views/stock_landed_cost_views.xml",
"views/product.xml",
"views/stock_valuation_layer.xml",
"wizard/stock_valuation_layer_revaluation_views.xml",
"views/stock_move_views.xml",
#"views/product_value_views.xml",
# "views/stock_valuation_layer.xml",
# "wizard/stock_valuation_layer_revaluation_views.xml",
],
"installable": False,
"installable": True,
"auto_install": False,
"application": False,
"assets": {},
Expand Down
6 changes: 4 additions & 2 deletions stock_currency_valuation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from . import product_category
from . import stock_valuation_layer
from . import product_product
from . import product_template
from . import stock_move
from . import stock_landed_cost
from . import stock_picking
from . import product_value

# from . import stock_valuation_layer
# from . import stock_landed_cost
351 changes: 350 additions & 1 deletion stock_currency_valuation/models/product_product.py

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions stock_currency_valuation/models/product_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from odoo import api, fields, models


class ProductValue(models.Model):
_inherit = "product.value"

valuation_currency_id = fields.Many2one("res.currency", compute="_compute_valuation_currency_id", store=True)
value_in_currency = fields.Monetary(string="Value", currency_field="valuation_currency_id")

@api.depends("company_id", "move_id", "lot_id", "product_id")
def _compute_valuation_currency_id(self):
for product_value in self:
if product_value.move_id:
product_value.valuation_currency_id = product_value.move_id.product_id.with_company(
product_value.company_id
).valuation_currency_id.id
elif product_value.lot_id:
product_value.valuation_currency_id = product_value.lot_id.product_id.with_company(
product_value.company_id
).valuation_currency_id.id
elif product_value.product_id:
product_value.valuation_currency_id = product_value.product_id.with_company(
product_value.company_id
).valuation_currency_id.id

@api.model_create_multi
def create(self, vals_list):
"""Override create to set default values from product's standard_price if not provided"""
for vals in vals_list:
# Obtener el producto según el contexto
product = None
if vals.get("product_id"):
product = self.env["product.product"].browse(vals["product_id"])
elif vals.get("lot_id"):
lot = self.env["stock.lot"].browse(vals["lot_id"])
product = lot.product_id
elif vals.get("move_id"):
move = self.env["stock.move"].browse(vals["move_id"])
product = move.product_id

if product:
# Obtener la compañía
company_id = vals.get("company_id")
if not company_id:
if vals.get("move_id"):
company_id = self.env["stock.move"].browse(vals["move_id"]).company_id.id
elif vals.get("lot_id"):
company_id = self.env["stock.lot"].browse(vals["lot_id"]).company_id.id
else:
company_id = self.env.company.id

company = self.env["res.company"].browse(company_id)
product_with_company = product.with_company(company)

# Si no está definido value, usar standard_price del producto
if "value" not in vals or not vals.get("value"):
vals["value"] = product_with_company.standard_price

# Si no está definido value_in_currency y el producto tiene moneda de valuación, usar standard_price_in_currency
if (
"value_in_currency" not in vals or not vals.get("value_in_currency")
) and product_with_company.valuation_currency_id:
vals["value_in_currency"] = product_with_company.standard_price_in_currency
return super().create(vals_list)
Loading
Loading