# -*- coding: utf-8 -*-
from odoo.exceptions import except_orm, Warning, RedirectWarning
from odoo import models, fields, api, _
from odoo.tools.translate import _
from odoo import SUPERUSER_ID, api
import odoo.addons.decimal_precision as dp
class sale_order_line(models.Model):
_inherit = 'sale.order.line'
qty_available = fields.Float(compute='product_qty_location_check', string='Quantity On Hand')
@api.multi
@api.depends('product_id', 'order_id.warehouse_id')
def product_qty_location_check(self):
for line in self:
qty = self.env['stock.quant'].search([('product_id', '=', line.product_id.id),('location_id', '=', line.order_id.warehouse_id.lot_stock_id.id)])
value = qty.quantity
self.qty_available = value
My form View.....
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="view_order_form" model="ir.ui.view">
<field name="name">Sale Order</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<xpath expr="//tree/field[@name='price_unit']" position="before">
<field name="qty_available" groups="stock.group_stock_user"/>
</xpath>
</field>
</record>
</data>
</odoo>
Error while Installing/Updating Module
Traceback (most recent call last): File "/home/usman/odoo-dev/odoo/odoo/http.py", line 647, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/usman/odoo-dev/odoo/odoo/http.py", line 307, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/home/usman/odoo-dev/odoo/odoo/tools/pycompat.py", line 87, in reraise raise value File "/home/usman/odoo-dev/odoo/odoo/http.py", line 689, in dispatch result = self._call_function(**self.params) File "/home/usman/odoo-dev/odoo/odoo/http.py", line 339, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/usman/odoo-dev/odoo/odoo/service/model.py", line 97, in wrapper return f(dbname, *args, **kwargs) File "/home/usman/odoo-dev/odoo/odoo/http.py", line 332, in checked_call result = self.endpoint(*a, **kw) File "/home/usman/odoo-dev/odoo/odoo/http.py", line 933, in __call__ return self.method(*args, **kw) File "/home/usman/odoo-dev/odoo/odoo/http.py", line 512, in response_wrap response = f(*args, **kw) File "/home/usman/odoo-dev/odoo/addons/web/controllers/main.py", line 934, in call_button action = self._call_kw(model, method, args, {}) File "/home/usman/odoo-dev/odoo/addons/web/controllers/main.py", line 922, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/home/usman/odoo-dev/odoo/odoo/api.py", line 689, in call_kw return call_kw_multi(method, model, args, kwargs) File "/home/usman/odoo-dev/odoo/odoo/api.py", line 680, in call_kw_multi result = method(recs, *args, **kwargs) File "<decorator-gen-46>", line 2, in button_immediate_upgrade File "/home/usman/odoo-dev/odoo/odoo/addons/base/module/module.py", line 71, in check_and_log return method(self, *args, **kwargs) File "/home/usman/odoo-dev/odoo/odoo/addons/base/module/module.py", line 602, in button_immediate_upgrade return self._button_immediate_function(type(self).button_upgrade) File "/home/usman/odoo-dev/odoo/odoo/addons/base/module/module.py", line 541, in _button_immediate_function modules.registry.Registry.new(self._cr.dbname, update_module=True) File "/home/usman/odoo-dev/odoo/odoo/modules/registry.py", line 85, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "/home/usman/odoo-dev/odoo/odoo/modules/loading.py", line 339, in load_modules force, status, report, loaded_modules, update_module) File "/home/usman/odoo-dev/odoo/odoo/modules/loading.py", line 242, in load_marked_modules loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks) File "/home/usman/odoo-dev/odoo/odoo/modules/loading.py", line 134, in load_module_graph registry.setup_models(cr) File "/home/usman/odoo-dev/odoo/odoo/modules/registry.py", line 282, in setup_models model._setup_complete() File "/home/usman/odoo-dev/odoo/odoo/models.py", line 2397, in _setup_complete field.setup_triggers(self) File "/home/usman/odoo-dev/odoo/odoo/fields.py", line 685, in setup_triggers for model, field, path in self.resolve_deps(model): File "/home/usman/odoo-dev/odoo/odoo/fields.py", line 663, in resolve_deps field = model._fields[fname] KeyError: 'warehouse_id'
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
You need to have a look at ur .py and xml file.
1. You have added the field on sale.order.line. You need to do something like this:
<record id="view_order_tree_so" model="ir.ui.view">
<field name="name">sale.order.line.view_order_form</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='price_unit']" position="before">
<field name="qty_available" readonly="1" />
</xpath>
</field>
</record>
and then update the view on the sale order form also.
<record id="view_order_form_so" model="ir.ui.view">
<field name="name">sale.order.view_order_form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='order_line']/tree/field[@name='price_unit']" position="before">
<field name="qty_available" readonly="1"/>
</xpath>
</field>
</record>
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign upRelated Posts | Replies | Views | Activity | |
---|---|---|---|---|
|
1
Jun 18
|
2381 | ||
|
2
Jun 20
|
4207 | ||
|
9
Sep 19
|
2964 | ||
|
5
May 19
|
2444 | ||
|
5
Feb 19
|
6822 |
Hello,
2 things you have to do and check.
1) Make sure you have added warehouse module in your depends (__manifest__.py file).
2) in your custom xml record view Id is same as you inherited (view_order_form).please change your custom id ,upgrade module and then see.
Thanks.