From 8fa154b148f4aaa70ee9504c21c00e1b03edb991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Scarafia?= Date: Wed, 25 Oct 2023 23:21:59 -0300 Subject: [PATCH] [WIP] --- stock_ux/__manifest__.py | 3 +- stock_ux/models/__init__.py | 2 + stock_ux/models/product_product.py | 40 ++++++++++++++- stock_ux/models/res_company.py | 11 +++++ stock_ux/models/res_config_settings.py | 1 + stock_ux/models/stock_valuation_layer.py | 31 ++++++++++++ stock_ux/views/res_config_settings_views.xml | 14 ++++++ .../views/stock_valuation_layer_views.xml | 49 +++++++++++++++++++ 8 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 stock_ux/models/res_company.py create mode 100644 stock_ux/models/stock_valuation_layer.py create mode 100644 stock_ux/views/stock_valuation_layer_views.xml diff --git a/stock_ux/__manifest__.py b/stock_ux/__manifest__.py index 03ba0474c..37da4bff4 100644 --- a/stock_ux/__manifest__.py +++ b/stock_ux/__manifest__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'Stock UX', - 'version': "16.0.2.10.0", + 'version': "16.0.2.11.0", 'category': 'Warehouse Management', 'sequence': 14, 'summary': '', @@ -48,6 +48,7 @@ 'views/stock_picking_type_views.xml', 'views/report_deliveryslip.xml', 'views/res_config_settings_views.xml', + 'views/stock_valuation_layer_views.xml', 'wizards/stock_operation_wizard_views.xml', 'report/stock_ux_report.xml', 'report/ir.action.reports.xml', diff --git a/stock_ux/models/__init__.py b/stock_ux/models/__init__.py index 39cab3d36..a0811e1ca 100644 --- a/stock_ux/models/__init__.py +++ b/stock_ux/models/__init__.py @@ -12,3 +12,5 @@ from . import stock_picking_type from . import res_config_settings from . import stock_rule +from . import res_company +from . import stock_valuation_layer diff --git a/stock_ux/models/product_product.py b/stock_ux/models/product_product.py index 487322df0..7e03ee3bd 100644 --- a/stock_ux/models/product_product.py +++ b/stock_ux/models/product_product.py @@ -2,13 +2,51 @@ # For copyright and license notices, see __manifest__.py file in module root # directory ############################################################################## -from odoo import models, fields +from odoo import models, fields, api import statistics class ProductProduct(models.Model): _inherit = 'product.product' + # TODO implementar, para hacerlo tendriamos que almacenar los campos de stck valuation layer + # secondary_currency_id = fields.Many2one(related='company_id.secondary_currency_id') + # secondary_currency_value_svl = fields.Float(compute='_compute_seconday_currency_value_svl', compute_sudo=True) + # secondary_currency_quantity_svl = fields.Float(compute='_compute_seconday_currency_value_svl', compute_sudo=True) + # secondary_currency_avg_cost = fields.Monetary(string="Average Cost", compute='_compute_seconday_currency_value_svl', compute_sudo=True, currency_field='company_seconday_currency_') + + # @api.depends('secondary_currency_id', 'secondary_currency_value_svl', 'secondary_currency_quantity_svl', 'secondary_currency_avg_cost') + # @api.depends_context('to_date', 'company') + # def _compute_value_svl(self): + # """Compute totals of multiple svl related values""" + # company_id = self.env.company + # self.company_currency_id = company_id.currency_id + # domain = [ + # ('product_id', 'in', self.ids), + # ('company_id', '=', company_id.id), + # ] + # if self.env.context.get('to_date'): + # to_date = fields.Datetime.to_datetime(self.env.context['to_date']) + # domain.append(('create_date', '<=', to_date)) + # groups = self.env['stock.valuation.layer']._read_group(domain, ['value:sum', 'quantity:sum'], ['product_id']) + # products = self.browse() + # # Browse all products and compute products' quantities_dict in batch. + # self.env['product.product'].browse([group['product_id'][0] for group in groups]).sudo(False).mapped('qty_available') + # for group in groups: + # product = self.browse(group['product_id'][0]) + # value_svl = company_id.currency_id.round(group['value']) + # avg_cost = value_svl / group['quantity'] if group['quantity'] else 0 + # product.value_svl = value_svl + # product.quantity_svl = group['quantity'] + # product.avg_cost = avg_cost + # product.total_value = avg_cost * product.sudo(False).qty_available + # products |= product + # remaining = (self - products) + # remaining.value_svl = 0 + # remaining.quantity_svl = 0 + # remaining.avg_cost = 0 + # remaining.total_value = 0 + def get_product_rotation(self, location=False, compute_stdev=False): self.ensure_one() # we should use cache for this date diff --git a/stock_ux/models/res_company.py b/stock_ux/models/res_company.py new file mode 100644 index 000000000..9c1ca0b3a --- /dev/null +++ b/stock_ux/models/res_company.py @@ -0,0 +1,11 @@ +############################################################################## +# For copyright and license notices, see __manifest__.py file in module root +# directory +############################################################################## +from odoo import models, fields + + +class ResCompany(models.Model): + _inherit = 'res.company' + + secondary_currency_id = fields.Many2one('res.currency') diff --git a/stock_ux/models/res_config_settings.py b/stock_ux/models/res_config_settings.py index 1564aeb1c..5a93e3404 100644 --- a/stock_ux/models/res_config_settings.py +++ b/stock_ux/models/res_config_settings.py @@ -23,3 +23,4 @@ class ResConfigSettings(models.TransientModel): 'En Comprobantes de Transferencia mostrar cantidades pendientes de entrega', config_parameter='stock_ux.delivery_slip_remaining_qty' ) + secondary_currency_id = fields.Many2one(related='company_id.secondary_currency_id', readonly=False) diff --git a/stock_ux/models/stock_valuation_layer.py b/stock_ux/models/stock_valuation_layer.py new file mode 100644 index 000000000..44722ad02 --- /dev/null +++ b/stock_ux/models/stock_valuation_layer.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models, tools +from odoo.tools import float_compare, float_is_zero + + +class StockValuationLayer(models.Model): + + _inherit = 'stock.valuation.layer' + + secondary_currency_id = fields.Many2one(related='company_id.secondary_currency_id') + secondary_currency_unit_cost = fields.Monetary('Unit Value(SC)', compute='_compute_secondary_currency_amounts', currency_field='secondary_currency_id', compute_sudo=True) + secondary_currency_value = fields.Monetary('Total Value (SC)', compute='_compute_secondary_currency_amounts', currency_field='secondary_currency_id', compute_sudo=True) + secondary_currency_remaining_value = fields.Monetary('Remaining Value (SC)', compute='_compute_secondary_currency_amounts', currency_field='secondary_currency_id', compute_sudo=True) + secondary_currency_price_diff_value = fields.Monetary('Invoice value correction with invoice currency (SC)', compute='_compute_secondary_currency_amounts', currency_field='secondary_currency_id', compute_sudo=True) + + @api.depends('secondary_currency_id', 'secondary_currency_unit_cost', 'secondary_currency_value', 'secondary_currency_remaining_value', 'secondary_currency_price_diff_value') + def _compute_secondary_currency_amounts(self): + # por performance usamos get_conversion_date en vez de convert, para pedirlo solo una vez porque la fecha es la misma + with_secondary_currency = self.filtered('secondary_currency_id') + (self - with_secondary_currency).secondary_currency_unit_cost = False + (self - with_secondary_currency).secondary_currency_value = False + (self - with_secondary_currency).secondary_currency_remaining_value = False + (self - with_secondary_currency).secondary_currency_price_diff_value = False + for rec in with_secondary_currency: + rate = rec.currency_id._get_conversion_rate(rec.currency_id, rec.secondary_currency_id, rec.company_id, rec.create_date) + rec.secondary_currency_unit_cost = rec.secondary_currency_id.round(rec.unit_cost * rate) if rec.unit_cost else 0.0 + rec.secondary_currency_value = rec.secondary_currency_id.round(rec.value * rate) if rec.value else 0.0 + rec.secondary_currency_remaining_value = rec.secondary_currency_id.round(rec.remaining_value * rate) if rec.remaining_value else 0.0 + rec.secondary_currency_price_diff_value = rec.secondary_currency_id.round(rec.price_diff_value * rate) if rec.price_diff_value else 0.0 diff --git a/stock_ux/views/res_config_settings_views.xml b/stock_ux/views/res_config_settings_views.xml index 834007643..8893a08c1 100644 --- a/stock_ux/views/res_config_settings_views.xml +++ b/stock_ux/views/res_config_settings_views.xml @@ -45,6 +45,20 @@ + +
+
+
+ Secondary Currency + +
+ bla bla bla +
+
+ +
+
+
diff --git a/stock_ux/views/stock_valuation_layer_views.xml b/stock_ux/views/stock_valuation_layer_views.xml new file mode 100644 index 000000000..c0767bc76 --- /dev/null +++ b/stock_ux/views/stock_valuation_layer_views.xml @@ -0,0 +1,49 @@ + + + stock.valuation.layer.form + stock.valuation.layer + + + + + + + + + + + + + + + + + + stock.valuation.layer.tree + stock.valuation.layer + + + + + + + + + + + + + + + + stock.valuation.layer.report.tree + stock.valuation.layer + + + + + + + + +