stock_account_usability: add shortcut to stock.valuation.layer from product form view
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
from . import models
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ This module has been written by Alexis de Lattre from Akretion <alexis.delattre@
|
|||||||
'author': 'Akretion',
|
'author': 'Akretion',
|
||||||
'website': 'http://www.akretion.com',
|
'website': 'http://www.akretion.com',
|
||||||
'depends': ['stock_account', 'stock_usability'],
|
'depends': ['stock_account', 'stock_usability'],
|
||||||
'data': ['views/stock_move.xml'],
|
'data': [
|
||||||
|
'views/stock_move.xml',
|
||||||
|
'views/product.xml',
|
||||||
|
],
|
||||||
'installable': True,
|
'installable': True,
|
||||||
}
|
}
|
||||||
|
|||||||
1
stock_account_usability/models/__init__.py
Normal file
1
stock_account_usability/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
|||||||
|
from . import product
|
||||||
38
stock_account_usability/models/product.py
Normal file
38
stock_account_usability/models/product.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
# Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||||
|
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
|
class ProductTemplate(models.Model):
|
||||||
|
_inherit = 'product.template'
|
||||||
|
|
||||||
|
def action_open_stock_valuation_layer(self):
|
||||||
|
self.ensure_one()
|
||||||
|
ppo = self.env['product.product']
|
||||||
|
if len(self.product_variant_ids) == 1:
|
||||||
|
action = ppo._get_stock_valuation_layer_action(self.product_variant_ids.id)
|
||||||
|
else:
|
||||||
|
action = ppo._get_stock_valuation_layer_action()
|
||||||
|
action["domain"] = [('product_id', 'in', self.product_variant_ids.ids)]
|
||||||
|
return action
|
||||||
|
|
||||||
|
|
||||||
|
class ProductProduct(models.Model):
|
||||||
|
_inherit = 'product.product'
|
||||||
|
|
||||||
|
def action_open_stock_valuation_layer(self):
|
||||||
|
self.ensure_one()
|
||||||
|
return self._get_stock_valuation_layer_action(self.id)
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def _get_stock_valuation_layer_action(self, product_id=None):
|
||||||
|
action = self.env["ir.actions.actions"]._for_xml_id(
|
||||||
|
"stock_account.stock_valuation_layer_action")
|
||||||
|
if product_id:
|
||||||
|
action["context"] = {
|
||||||
|
'search_default_product_id': product_id,
|
||||||
|
'search_default_group_by_product_id': 1,
|
||||||
|
}
|
||||||
|
return action
|
||||||
54
stock_account_usability/views/product.xml
Normal file
54
stock_account_usability/views/product.xml
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright 2022 Akretion France (http://www.akretion.com/)
|
||||||
|
@author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||||
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
-->
|
||||||
|
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
<record id="product_product_to_inventory_valuation" model="ir.actions.act_window">
|
||||||
|
<field name="name">Inventory Valuation</field>
|
||||||
|
<field name="res_model">stock.valuation.layer</field>
|
||||||
|
<field name="view_mode">tree,form</field>
|
||||||
|
<field name="groups_id" eval="[(4, ref('stock.group_stock_manager'))]"/>
|
||||||
|
<field name="context">{'search_default_group_by_product_id': 1, 'search_default_product_id': active_id}</field>
|
||||||
|
<field name="binding_model_id" ref="product.model_product_product" />
|
||||||
|
<field name="binding_view_types">form</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
-->
|
||||||
|
<!-- product template only form view -->
|
||||||
|
<record id="product_template_form_view_procurement_button" model="ir.ui.view">
|
||||||
|
<field name="model">product.template</field>
|
||||||
|
<field name="inherit_id" ref="stock.product_template_form_view_procurement_button"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<div name="button_box" position="inside">
|
||||||
|
<button class="oe_stat_button"
|
||||||
|
name="action_open_stock_valuation_layer"
|
||||||
|
string="Inventory Valuation"
|
||||||
|
icon="fa-usd"
|
||||||
|
type="object" attrs="{'invisible': [('type', '!=', 'product')]}">
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
<!-- product.product only form view -->
|
||||||
|
<record id="product_form_view_procurement_button" model="ir.ui.view">
|
||||||
|
<field name="model">product.product</field>
|
||||||
|
<field name="inherit_id" ref="stock.product_form_view_procurement_button"/>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<div name="button_box" position="inside">
|
||||||
|
<button class="oe_stat_button"
|
||||||
|
name="action_open_stock_valuation_layer"
|
||||||
|
string="Inventory Valuation"
|
||||||
|
icon="fa-usd"
|
||||||
|
type="object" attrs="{'invisible': [('type', '!=', 'product')]}">
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
</odoo>
|
||||||
Reference in New Issue
Block a user