Skip to content

[IMP] inventory: improve stock info and UI in product form #886

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

Draft
wants to merge 1 commit into
base: 18.0
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions update_on_hand/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
11 changes: 11 additions & 0 deletions update_on_hand/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
'name': 'Update Quantity On Hand',
'version': '1.0',
'author': 'niyp',
'depends': ['stock'],
'data': [
'views/product_template_views.xml',
],
'installable': True,
'license': 'LGPL-3',
}
1 change: 1 addition & 0 deletions update_on_hand/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import product_template
13 changes: 13 additions & 0 deletions update_on_hand/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = 'product.template'

is_multicompany = fields.Boolean(compute="_compute_is_multicompany")

@api.depends('company_id')
def _compute_is_multicompany(self):
for record in self:
user = self.env.user
record.is_multicompany = len(user.company_ids) > 1
78 changes: 78 additions & 0 deletions update_on_hand/views/product_template_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record id="view_product_template_form_inherited" model="ir.ui.view">
<field name="name">product.template.form.custom.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_only_form_view" />
<field name="arch" type="xml">

<xpath expr="//button[@name='action_update_quantity_on_hand']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>

<xpath expr="//button[@invisible='not show_on_hand_qty_status_button']"
position="attributes">
<attribute name="invisible">1</attribute>
</xpath>

<xpath expr="//field[@name='virtual_available']"
position='attributes'>
<attribute name='decoration-danger'>virtual_available &lt; 0</attribute>
<attribute name='decoration-primary'>virtual_available == 0</attribute>
</xpath>

<xpath
expr="//button[@name='action_product_tmpl_forecast_report']/div/span[hasclass('o_stat_value', 'd-flex', 'gap-1')]/field[@name='uom_name']"
position='replace'>
<span>Forecasted</span>
</xpath>

<xpath
expr="//button[@name='action_product_tmpl_forecast_report']/div/span[hasclass('o_stat_value', 'd-flex', 'gap-1')]"
position='before'>
<span class="o_stat_value d-flex gap-1">
<field name="qty_available" nolabel="1" class="oe_inline" />
<field name="uom_name" class="oe_inline" />
</span>
</xpath>

<xpath
expr="//button[@name='action_product_tmpl_forecast_report']/div/span[hasclass('o_stat_text')]"
position='attributes'>
<attribute name='invisible'>1</attribute>
</xpath>

</field>
</record>

<record id="product_template_form_view_inherit" model="ir.ui.view">
<field name="name">product.template.common.form.inherit</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">

<xpath expr="//field[@name='product_tooltip']" position='attributes'>
<attribute name='invisible'>type == 'consu'</attribute>
</xpath>

<xpath expr="//field[@name='product_tooltip']" position="after">
<label for="qty_available" invisible='not is_storable'>Quantity On Hand</label>
<span class="d-flex gap-3">
<field name="qty_available"
readonly="is_multicompany"
class="oe_inline"
invisible='not is_storable'
/>
<field name="uom_name" class="oe_inline" invisible='not is_storable' />
<button type="action"
name="%(stock.action_product_stock_view)d"
class="oe_stat_button oe_inline opacity-0 opacity-100-hover"
invisible='not is_storable'>
Update
</button>
</span>
</xpath>

</field>
</record>
</odoo>