Skip to content
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

[WIP] #407

Closed
wants to merge 1 commit into from
Closed

[WIP] #407

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
3 changes: 2 additions & 1 deletion stock_ux/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '',
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions stock_ux/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 39 additions & 1 deletion stock_ux/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions stock_ux/models/res_company.py
Original file line number Diff line number Diff line change
@@ -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')
1 change: 1 addition & 0 deletions stock_ux/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
31 changes: 31 additions & 0 deletions stock_ux/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions stock_ux/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@
</div>
</div>
</div>

<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane"/>
<div class="o_setting_right_pane">
<span class="o_form_label">Secondary Currency</span>
<span class="fa fa-lg fa-building-o" title="Values set here are company-specific." role="img" aria-label="Values set here are company-specific." groups="base.group_multi_company"/>
<div class="text-muted">
bla bla bla
</div>
<div class="text-muted">
<field name="secondary_currency_id" options="{'no_create': True, 'no_open': True}"/>
</div>
</div>
</div>
</xpath>
</field>
</record>
Expand Down
49 changes: 49 additions & 0 deletions stock_ux/views/stock_valuation_layer_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<odoo>
<record id="stock_valuation_layer_form" model="ir.ui.view">
<field name="name">stock.valuation.layer.form</field>
<field name="model">stock.valuation.layer</field>
<field name="inherit_id" ref="stock_account.stock_valuation_layer_form"/>
<field name="arch" type="xml">
<notebook>
<page string="Valuation" name="valuation">
<group groups="base.group_multi_currency">
<field name="secondary_currency_id" invisible="1"/>
<field name="secondary_currency_unit_cost" />
<field name="secondary_currency_value" />
<field name="secondary_currency_remaining_value" />
<field name="secondary_currency_price_diff_value" />
</group>
</page>
</notebook>
</field>
</record>

<record id="stock_valuation_layer_tree" model="ir.ui.view">
<field name="name">stock.valuation.layer.tree</field>
<field name="model">stock.valuation.layer</field>
<field name="inherit_id" ref="stock_account.stock_valuation_layer_tree"/>
<field name="arch" type="xml">
<field name="unit_cost" position="after">
<field name="secondary_currency_id" invisible="1"/>
<field name="secondary_currency_unit_cost" optional="hide" groups="base.group_multi_currency"/>
</field>
<field name="value" position="after">
<field name="secondary_currency_id" invisible="1"/>
<field name="secondary_currency_value" optional="hide" groups="base.group_multi_currency"/>
</field>
</field>
</record>

<!-- reporting view -->
<record id="stock_valuation_layer_report_tree" model="ir.ui.view">
<field name="name">stock.valuation.layer.report.tree</field>
<field name="model">stock.valuation.layer</field>
<field name="inherit_id" ref="stock_account.stock_valuation_layer_report_tree"/>
<field name="arch" type="xml">
<field name="remaining_value" position="after">
<field name="secondary_currency_remaining_value" optional="hide" groups="base.group_multi_currency"/>
</field>
</field>
</record>

</odoo>