Bỏ qua để đến Nội dung
Odoo Menu
  • Đăng nhập
  • Dùng thử miễn phí
  • Ứng dụng
    Tài chính
    • Kế toán
    • Hóa đơn
    • Chi phí
    • Bảng tính (BI)
    • Tài liệu
    • Ký tên
    Bán hàng
    • CRM
    • Bán hàng
    • POS Cửa hàng
    • POS Nhà hàng
    • Đăng ký
    • Cho thuê
    Trang web
    • Trình tạo trang web
    • Thương mại điện tử
    • Blog
    • Diễn đàn
    • Trò chuyện trực tiếp
    • Học trực tuyến
    Chuỗi cung ứng
    • Tồn kho
    • Sản xuất
    • PLM
    • Mua hàng
    • Bảo dưỡng
    • Chất lượng
    Nhân sự
    • Nhân viên
    • Tuyển dụng
    • Ngày nghỉ
    • Đánh giá
    • Giới thiệu
    • Đội xe
    Marketing
    • Marketing trên MXH
    • Marketing qua email
    • Marketing qua SMS
    • Sự kiện
    • Tự động hóa Marketing
    • Khảo sát
    Dịch vụ
    • Dự án
    • Bảng chấm công
    • Dịch vụ hiện trường
    • Hỗ trợ
    • Kế hoạch
    • Lịch hẹn
    Năng suất
    • Thảo luận
    • Phê duyệt
    • IoT
    • VoIP
    • Kiến thức
    • WhatsApp
    Ứng dụng của bên thứ ba Studio Odoo Nền tảng Đám mây Odoo
  • Ngành
    Bán lẻ
    • Nhà sách
    • Cửa hàng quần áo
    • Cửa hàng nội thất
    • Cửa hàng tạp hóa
    • Cửa hàng đồ kim khí
    • Cửa hàng đồ chơi
    Ẩm thực & Dịch vụ lưu trú
    • Bar và quán rượu
    • Nhà hàng
    • Đồ ăn nhanh
    • Guest house
    • Nhà phân phối đồ uống
    • Khách sạn
    Bất động sản
    • Công ty môi giới bất động sản
    • Công ty kiến trúc
    • Xây dựng
    • Quản lý bất động sản
    • Làm vườn
    • Hiệp hội chủ sở hữu bất động sản
    Tư vấn
    • Công ty kế toán
    • Đối tác Odoo
    • Công ty marketing
    • Công ty luật
    • Tuyển dụng
    • Thanh tra & chứng nhận
    Sản xuất
    • Dệt may
    • Kim loại
    • Nội thất
    • Ẩm thực
    • Nhà máy bia
    • Quà tặng doanh nghiệp
    Sức khoẻ & fitness
    • CLB thể thao
    • Cửa hàng kính mắt
    • Trung tâm fitness
    • Chuyên gia chăm sóc sức khỏe
    • Hiệu thuốc
    • Tiệm làm tóc
    Thương mại
    • Dịch vụ sửa chữa
    • Phần cứng CNTT & Hỗ trợ
    • Hệ thống năng lượng mặt trời
    • Công ty sản xuất giày
    • Dịch vụ vệ sinh
    • Dịch vụ HVAC
    Khác
    • Tổ chức phi lợi nhuận
    • Cơ quan môi trường
    • Cho thuê biển quảng cáo
    • Nhiếp ảnh
    • Cho thuê xe đạp
    • Đại lý phần mềm
    Xem tất cả ngành
  • Cộng đồng
    Học tập
    • Khóa học
    • Tài liệu
    • Chứng chỉ
    • Đào tạo
    • Blog
    • Podcast
    Thúc đẩy đào tạo
    • Chương trình đào tạo
    • Trò chơi kinh doanh Scale Up!
    • Tham quan Odoo
    Nhận phần mềm
    • Tải xuống
    • So sánh các phiên bản
    • Phiên bản
    Hợp tác
    • Github
    • Diễn đàn
    • Sự kiện
    • Dịch thuật
    • Trở thành đối tác
    • Dịch vụ dành cho Đối tác
    • Đăng ký công ty kế toán của bạn
    Nhận dịch vụ
    • Tìm đối tác
    • Tìm kế toán
    • Gặp chuyên gia hỗ trợ
    • Dịch vụ Triển khai
    • Khách hàng tham khảo
    • Hỗ trợ
    • Nâng cấp
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Nhận một buổi demo
  • Bảng giá
  • Trợ giúp

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
  • Dự án
  • MRP
All apps
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Bạn cần phải đăng ký để tương tác với cộng đồng.
Tất cả bài viết Người Huy hiệu
Thẻ (Xem tất cả)
odoo accounting v14 pos v15
Về diễn đàn này
Hỗ trợ

Add "Add Products" to my custom module like in sale quotation

Đăng ký nhận tin

Nhận thông báo khi có hoạt động trên bài viết này

Câu hỏi này đã bị gắn cờ
modulesalecustomsale.order.linequotation
2 Trả lời
6695 Lượt xem
Ảnh đại diện
Christian Hardjono

I want my module to be able to add products like when you want to add products in sale quotation. Can you tell me how or reference me to a good link? Thanks

0
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Niyas Raphy (Walnut Software Solutions)
Câu trả lời hay nhất

Hi,
To get a many2one field of a product , you can add a field like this,

product_field = fields.Many2one('product.product', string="Product")

To get the same as in the sales form,

In the Py


class TestA(models.Model):
_name = 'test.a

add_product_lines = fields.One2many('test.b', 'connect_test_b', string='Products')

class TestB(models.Model):
_name = 'test.b'

connect_test_b = fields.Many2one('test.a', string="Connect")
product_id = fields.Many2one('product.product', string="Product")
description = fields.Text(string="Description")
pro_qty = fields.Integer(string='Quantity', default=1)
unit_price = fields.Float(string='Unit Price')
tax = fields.Many2one('account.tax', string='Tax')
sub_total = fields.Float(string='Sub Total')

Then in the Xml,

<page string="Product Service">
<field name="add_product_lines">
<tree editable="bottom">
<field name="product_id"/>
<field name="description"/>
<field name="pro_qty"/>
<field name="unit_price"/>
<field name="tax"/>
<field name="sub_total"/>
</tree>
</field>

</page>

Thanks


1
Ảnh đại diện
Huỷ bỏ
Ảnh đại diện
Christian Hardjono
Tác giả Câu trả lời hay nhất

Error context:
View `sales_orders.form`
[view_id: 792, xml_id: contract.sales_orders_form_view, model: contract.sales_orders, parent_id: n/a]
2017-07-03 09:08:07,631 28860 INFO test werkzeug: 127.0.0.1 - - [03/Jul/2017 09:08:07] "GET / HTTP/1.1" 500 - 2017-07-03 09:08:07,650 28860 ERROR test werkzeug: Error on request:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi
    execute(self.server.app)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute
    application_iter = app(environ, start_response)
  File "/home/christian/Odoo-8.0/openerp/service/server.py", line 295, in app
    return self.app(e, s)
  File "/home/christian/Odoo-8.0/openerp/service/wsgi_server.py", line 216, in application
    return application_unproxied(environ, start_response)
  File "/home/christian/Odoo-8.0/openerp/service/wsgi_server.py", line 202, in application_unproxied
    result = handler(environ, start_response)
  File "/home/christian/Odoo-8.0/openerp/http.py", line 1297, in __call__
    return self.dispatch(environ, start_response)
  File "/home/christian/Odoo-8.0/openerp/http.py", line 1271, in __call__
    return self.app(environ, start_wrapped)
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 588, in __call__
    return self.app(environ, start_response)
  File "/home/christian/Odoo-8.0/openerp/http.py", line 1442, in dispatch
    ir_http = request.registry['ir.http']
  File "/home/christian/Odoo-8.0/openerp/http.py", line 353, in registry
    return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None
  File "/home/christian/Odoo-8.0/openerp/modules/registry.py", line 339, in get
    update_module)
  File "/home/christian/Odoo-8.0/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/home/christian/Odoo-8.0/openerp/modules/loading.py", line 351, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/home/christian/Odoo-8.0/openerp/modules/loading.py", line 255, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/home/christian/Odoo-8.0/openerp/modules/loading.py", line 176, in load_module_graph
    _load_data(cr, module_name, idref, mode, kind='data')
  File "/home/christian/Odoo-8.0/openerp/modules/loading.py", line 118, in _load_data
    tools.convert_file(cr, module_name, filename, idref, mode, noupdate, kind, report)
  File "/home/christian/Odoo-8.0/openerp/tools/convert.py", line 897, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
  File "/home/christian/Odoo-8.0/openerp/tools/convert.py", line 983, in convert_xml_import
    obj.parse(doc.getroot(), mode=mode)
  File "/home/christian/Odoo-8.0/openerp/tools/convert.py", line 849, in parse
    self._tags[rec.tag](self.cr, rec, n, mode=mode)
  File "/home/christian/Odoo-8.0/openerp/tools/convert.py", line 759, in _tag_record
    id = self.pool['ir.model.data']._update(cr, self.uid, rec_model, self.module, res, rec_id or False, not self.isnoupdate(data_node), noupdate=self.isnoupdate(data_node), mode=self.mode, context=rec_context )
  File "/home/christian/Odoo-8.0/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/christian/Odoo-8.0/openerp/addons/base/ir/ir_model.py", line 1023, in _update
    model_obj.write(cr, uid, [res_id], values, context=context)
  File "/home/christian/Odoo-8.0/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/christian/Odoo-8.0/openerp/addons/base/ir/ir_ui_view.py", line 281, in write
    context)
  File "/home/christian/Odoo-8.0/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/christian/Odoo-8.0/openerp/api.py", line 399, in old_api
    result = method(recs, *args, **kwargs)
  File "/home/christian/Odoo-8.0/openerp/models.py", line 3792, in write
    self._write(old_vals)
  File "/home/christian/Odoo-8.0/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/christian/Odoo-8.0/openerp/api.py", line 592, in new_api
    result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
  File "/home/christian/Odoo-8.0/openerp/models.py", line 3971, in _write
    recs._validate_fields(vals)
  File "/home/christian/Odoo-8.0/openerp/api.py", line 266, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/christian/Odoo-8.0/openerp/models.py", line 1275, in _validate_fields
    raise ValidationError('\n'.join(errors))
ParseError: "ValidateError Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Field `description` does not exist

Error context:
View `sales_orders.form`
[view_id: 792, xml_id: contract.sales_orders_form_view, model: contract.sales_orders, parent_id: n/a]" while parsing /home/christian/Odoo-8.0/custom-addons/contract/views/sales_orders.xml:4, near
<record model="ir.ui.view" id="sales_orders_form_view">
            <field name="name">sales_orders.form</field>
            <field name="model">contract.sales_orders</field>
            <field name="arch" type="xml">
                <form string="Contract Sales Orders Form">
                    <header>
                        <button name="action_draft" type="object" string="Reset to draft" states="running"/>
                        <button name="action_running" type="object" string="Run" states="draft" class="oe_highlight"/>
                        <button name="action_done" type="object" string="Mark as done" states="running" class="oe_highlight"/>
                        <button name="action_canceled" type="object" string="Cancel" states="draft,running"/>
                        <field name="state" widget="statusbar"/>
                    </header>

                    <sheet>
                        <group>
                            <field name="order_number"/>
                            <field name="partner_id"/>
                            <field name="date_contract"/>
                            <field name="interval"/>
                            <field name="interval_type"/>
                            <field name="number_of_call"/>
                            <!-- <field name="line_ids" attrs="{
                            'readonly':[('state','!=','draft')]
                            }">
                                <tree editable="bottom">
                                    <field name="product_id"/>
                                    <field name="price"/>
                                    <field name="qty"/>
                                    <field name="uom"/>
                                    <field name="subtotal" sum="Total"/>


                                </tree>
                            </field> -->
                            <field name="next_date_execute"/>
                            <field name="remain_interval"/>
                        </group>
                        <notebook>
                            <page string="Order Lines">
                                <field name="add_product_lines">
                                    <tree editable="bottom">
                                        <field name="product_id"/>
                                        <field name="description"/>
                                        <field name="pro_qty"/>
                                        <field name="unit_price"/>
                                        <field name="tax"/>
                                        <field name="sub_total"/>
                                    </tree>
                                </field>
                            </page>
                            <page string="About">
                                This is an example of notebooks
                            </page>
                        </notebook>
                    </sheet>
                </form>
            </field>
        </record>

I got that error.

I try commenting the description field, then I got the product_id not exist error.

0
Ảnh đại diện
Huỷ bỏ
Christian Hardjono
Tác giả

ah, I get where I did wrong.

I delete the TestA class and insert add_product_lines = fields.One2many('test.b', 'connect_test_b', string='Products') to my class. Now it works. Thanks.

Niyas Raphy (Walnut Software Solutions)

Can you show me the py file

Christian Hardjono
Tác giả

# -*- coding: utf-8 -*-

from openerp import models, fields, api

class sales_orders(models.Model):

_name = 'contract.sales_orders'

add_product_lines = fields.One2many('test.b', 'connect_test_b', string='Products')

order_number = fields.Char(string="Order Number")

partner_id = fields.Many2one('res.partner', string="Customer")

# line_ids = fields.One2many('sale.order.contract.line', 'contract_id',

# string="Products")

date_contract = fields.Date(string="Date Contract",

default=fields.Date.today)

interval = fields.Integer(string='Interval')

interval_type = fields.Selection(

[('day', 'Day'), ('week', 'Week'), ('month', 'Month')],

string="Interval Type", default='day')

number_of_call = fields.Integer(string="Number of Call", default=1)

next_date_execute = fields.Date(string="Next Date Execute")

remain_interval = fields.Integer(string="Remain Interval")

order_lines = fields.Text()

# Many2one('product.product', string="Product")

state = fields.Selection([

('draft', 'Draft'),

('running', 'Running'),

('done', 'Done'),

('canceled', 'Canceled')

], string="State", default='draft')

@api.multi

def action_draft(self):

self.state = 'draft'

@api.multi

def action_running(self):

self.state = 'running'

@api.multi

def action_done(self):

self.state = 'done'

@api.multi

def action_canceled(self):

self.state = 'canceled'

# class TestA(models.Model):

# _name = 'test.a'

# add_product_lines = fields.One2many('test.b', 'connect_test_b', string='Products')

class TestB(models.Model):

_name = 'test.b'

# @api.multi

# def _get_subtotal(self):

# for data in self:

# data.subtotal=data.unit_price * data.pro_qty

@api.multi

def _get_subtotal(self):

for data in self:

data.subtotal=data.price * data.qty

connect_test_b = fields.Many2one('contract.sales_orders', string="Connect")

# product_id = fields.Many2one('product.product', string="Product")

description = fields.Text(string="Description")

# pro_qty = fields.Integer(string='Quantity', default=1)

# uom=fields.Many2one('product.uom',string='Unit of Measure')

# unit_price = fields.Float(string='Unit Price')

tax = fields.Many2one('account.tax', string='Tax')

# subtotal = fields.Float(string='Sub Total', compute=_get_subtotal)

product_id=fields.Many2one('product.product',string='Product')

qty=fields.Integer(string="Quantity")

price=fields.Float(string="Unit Price")

subtotal=fields.Float(string="Sub Total",compute=_get_subtotal)

uom=fields.Many2one('product.uom',string='Unit of Measure')

@api.onchange('product_id')

# onchange price dan uom

def onchange_price(self):

self.price=self.product_id.list_price

self.uom=self.product_id.uom_id.id

@api.onchange('qty')

# onchange subtotal

def onchange_subtotal(self):

self.subtotal=self.price * self.qty

# @api.onchange('product_id')

# # onchange price dan uom

# def onchange_unit_price(self):

# self.unit_price=self.product_id.list_price

# self.uom=self.product_id.uom_id.id

# @api.onchange('pro_qty')

# # onchange subtotal

# def onchange_subtotal(self):

# self.subtotal=self.unit_price * self.pro_qty

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
Sales Order Line, Discount applied on tax amount but not on Unit price.
sale sale.order.line quotation
Ảnh đại diện
0
thg 3 15
5158
How to get module sale_quotation_sourcing working?
module sale quotation sourcing
Ảnh đại diện
0
thg 6 15
4100
Programmatically create a sale order line Đã xử lý
module sale sale.order.line programatically v9
Ảnh đại diện
Ảnh đại diện
1
thg 4 21
34607
How to generate line numbers on quotes Đã xử lý
sale sale.order.line
Ảnh đại diện
Ảnh đại diện
1
thg 1 25
4326
How to add freight charges to product cost in sale quoatation
sale sale.order.line
Ảnh đại diện
Ảnh đại diện
2
thg 8 24
6403
Cộng đồng
  • Khóa học
  • Tài liệu
  • Diễn đàn
Open source
  • Tải xuống
  • Github
  • Runbot
  • Dịch thuật
Dịch vụ
  • Lưu trữ Odoo.sh
  • Hỗ trợ
  • Nâng cấp
  • Phát triển tùy chỉnh
  • Đào tạo
  • Tìm kế toán
  • Tìm đối tác
  • Trở thành đối tác
Giới thiệu công ty
  • Công ty của chúng tôi
  • Tài sản thương hiệu
  • Liên hệ
  • Việc làm
  • Sự kiện
  • Podcast
  • Blog
  • Khách hàng
  • Pháp lý • Riêng tư
  • Bảo mật
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo là bộ ứng dụng kinh doanh có open source đáp ứng tất cả các nhu cầu của công ty bạn: CRM, thương mại điện tử, kế toán, tồn kho, POS, quản lý dự án, v.v.

Định hướng giá trị riêng biệt của Odoo là tích hợp hoàn toàn và dễ dàng sử dụng.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now