# -*- 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
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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>
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
Create product from own model
Đã xử lý
|
|
1
thg 6 18
|
3091 | |
|
0
thg 1 25
|
821 | ||
|
2
thg 6 20
|
6185 | ||
|
9
thg 9 19
|
4117 | ||
|
5
thg 5 19
|
3407 |
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.