[REF] stock_account: valuation at date wizard
We add the valuation at date wizard by re-using the quantity at date wizard and adding a context key to separate the both. The same view/action is used when openning the current or at date valuation, only the `to_date` context key is changed.
This commit is contained in:
@@ -26,17 +26,6 @@
|
||||
<field name="value">manual_periodic</field>
|
||||
<field name="type">selection</field>
|
||||
</record>
|
||||
<record id="action_stock_account_valuation_report" model="ir.actions.server">
|
||||
<field name="name">Stock Valuation Report</field>
|
||||
<field name="type">ir.actions.server</field>
|
||||
<field name="state">code</field>
|
||||
<field name="model_id" ref="product.model_product_product"></field>
|
||||
<field name="binding_model_id" ref="product.model_product_product"></field>
|
||||
<field name="code">
|
||||
env['stock.move']._run_fifo_vacuum()
|
||||
action = env.ref('stock_account.product_valuation_action').read()[0]
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
|
||||
@@ -240,6 +240,34 @@ class ProductProduct(models.Model):
|
||||
value, quantity, aml_ids = fifo_automated_values.get((product.id, valuation_account_id)) or (0, 0, [])
|
||||
product.stock_fifo_real_time_aml_ids = self.env['account.move.line'].browse(aml_ids)
|
||||
|
||||
def action_valuation_at_date_details(self):
|
||||
""" Returns an action with either a list view of all the valued stock moves of `self` if the
|
||||
valuation is set as manual or a list view of all the account move lines if the valuation is
|
||||
set as automated.
|
||||
"""
|
||||
self.ensure_one()
|
||||
to_date = self.env.context.get('to_date')
|
||||
action = {
|
||||
'name': _('Valuation at date'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'context': self.env.context,
|
||||
}
|
||||
if self.valuation == 'real_time':
|
||||
action['res_model'] = 'account.move.line'
|
||||
action['domain'] = [('id', 'in', self.with_context(to_date=to_date).stock_fifo_real_time_aml_ids.ids)]
|
||||
tree_view_ref = self.env.ref('stock_account.view_stock_account_aml')
|
||||
form_view_ref = self.env.ref('account.view_move_line_form')
|
||||
action['views'] = [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')]
|
||||
else:
|
||||
action['res_model'] = 'stock.move'
|
||||
action['domain'] = [('id', 'in', self.with_context(to_date=to_date).stock_fifo_manual_move_ids.ids)]
|
||||
tree_view_ref = self.env.ref('stock_account.view_move_tree_valuation_at_date')
|
||||
form_view_ref = self.env.ref('stock.view_move_form')
|
||||
action['views'] = [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')]
|
||||
return action
|
||||
|
||||
@api.multi
|
||||
def action_open_product_moves(self):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -86,27 +86,14 @@
|
||||
</data>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_valuation_tree" model="ir.ui.view">
|
||||
<field name="name">product.valuation.tree</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="display_name" string="Product"/>
|
||||
<field name="qty_available" context="{'company_owned': True}" string="Quantity on Hand"/>
|
||||
<field name="uom_id" groups="product.group_uom"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="stock_value" sum="Stock Valuation" widget="monetary" string="Total Value"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="product_valuation_action" model="ir.actions.act_window">
|
||||
<field name="name">Product Valuation</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">product.product</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_id" ref="product_valuation_tree"/>
|
||||
<field name="view_id" ref="view_stock_product_tree2"/>
|
||||
<field name="domain">[('type', '=', 'product'), ('qty_available', '!=', 0)]</field>
|
||||
<field name="context">{}</field>
|
||||
<field name="help" type="html">
|
||||
|
||||
@@ -49,6 +49,82 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<menuitem id="menu_valuation" name="Inventory Valuation" parent="stock.menu_warehouse_report" sequence="110" action="stock_account.action_stock_account_valuation_report"/>
|
||||
<!-- valuation wizard: current or at date -->
|
||||
<record id="view_stock_quantity_history" model="ir.ui.view">
|
||||
<field name="name">Valuation Report</field>
|
||||
<field name="model">stock.quantity.history</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Choose your date">
|
||||
<group>
|
||||
<group>
|
||||
<field name="compute_at_date" widget="radio"/>
|
||||
<field name="date" attrs="{'invisible': [('compute_at_date', '=', 0)]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="open_table" string="Retrieve the inventory valuation" type="object" class="btn-primary"/>
|
||||
<button string="Cancel" class="btn-default" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_stock_product_tree2" model="ir.ui.view">
|
||||
<field name="name">product.stock.tree.2</field>
|
||||
<field name="model">product.product</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="qty_at_date"/>
|
||||
<field name="uom_id" groups="product.group_uom"/>
|
||||
<field name="currency_id" invisible="1"/>
|
||||
<field name="stock_value" sum="Stock Valuation" widget="monetary"/>
|
||||
<field name="cost_method" invisible="1"/>
|
||||
<button name="action_valuation_at_date_details" type="object" icon="fa-info-circle" attrs="{'invisible': [('cost_method', '!=', 'fifo')]}" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_stock_inventory_valuation" model="ir.actions.act_window">
|
||||
<field name="name">Valuation Report</field>
|
||||
<field name="res_model">stock.quantity.history</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="stock_account.view_stock_quantity_history"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">{'default_compute_at_date': 0, 'valuation': True}</field>
|
||||
</record>
|
||||
<menuitem id="menu_valuation" name="Inventory Valuation" parent="stock.menu_warehouse_report" sequence="110" action="action_stock_inventory_valuation"/>
|
||||
|
||||
<!-- AML specialized tree view -->
|
||||
<record id="view_stock_account_aml" model="ir.ui.view">
|
||||
<field name="name">stock.account.aml</field>
|
||||
<field name="model">account.move.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="date" />
|
||||
<field name="ref" />
|
||||
<field name="product_id" />
|
||||
<field name="quantity" />
|
||||
<field name="product_uom_id" groups="product.group_uom" />
|
||||
<field name="balance" string="Value"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- stock move specialized tree view -->
|
||||
<record id="view_move_tree_valuation_at_date" model="ir.ui.view">
|
||||
<field name="name">stock.move.tree.valuation.at.date</field>
|
||||
<field name="model">stock.move</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="date" />
|
||||
<field name="picking_id" string="Reference"/>
|
||||
<field name="state" invisible="1"/>
|
||||
<field name="product_id"/>
|
||||
<field name="product_uom_qty" string="Quantity"/>
|
||||
<field name="product_uom" options="{'no_open': True, 'no_create': True}" string="Unit of Measure" groups="product.group_uom"/>
|
||||
<field name="value" sum="Stock Valuation"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</odoo>
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from . import stock_change_standard_price
|
||||
from . import stock_quantity_history
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import models, _
|
||||
|
||||
|
||||
class StockQuantityHistory(models.TransientModel):
|
||||
_inherit = 'stock.quantity.history'
|
||||
|
||||
def open_table(self):
|
||||
if not self.env.context.get('valuation'):
|
||||
return super(StockQuantityHistory, self).open_table()
|
||||
|
||||
self.env['stock.move']._run_fifo_vacuum()
|
||||
|
||||
if self.compute_at_date:
|
||||
tree_view_id = self.env.ref('stock_account.view_stock_product_tree2').id
|
||||
form_view_id = self.env.ref('stock.product_form_view_procurement_button').id
|
||||
# We pass `to_date` in the context so that `qty_available` will be computed across
|
||||
# moves until date.
|
||||
action = {
|
||||
'type': 'ir.actions.act_window',
|
||||
'views': [(tree_view_id, 'tree'), (form_view_id, 'form')],
|
||||
'view_mode': 'tree,form',
|
||||
'name': _('Products'),
|
||||
'res_model': 'product.product',
|
||||
'domain': "[('type', '=', 'product'), ('qty_available', '!=', 0)]",
|
||||
'context': dict(self.env.context, to_date=self.date),
|
||||
}
|
||||
return action
|
||||
else:
|
||||
return self.env.ref('stock_account.product_valuation_action').read()[0]
|
||||
|
||||
Reference in New Issue
Block a user