Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
modulesalecustomsale.order.linequotation
2 Replies
6809 Zobrazenia
Avatar
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
Avatar
Zrušiť
Avatar
Niyas Raphy (Walnut Software Solutions)
Best Answer

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
Avatar
Zrušiť
Avatar
Christian Hardjono
Autor Best Answer

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
Avatar
Zrušiť
Christian Hardjono
Autor

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
Autor

# -*- 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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrácia
Related Posts Replies Zobrazenia Aktivita
Sales Order Line, Discount applied on tax amount but not on Unit price.
sale sale.order.line quotation
Avatar
0
mar 15
5290
How to get module sale_quotation_sourcing working?
module sale quotation sourcing
Avatar
0
jún 15
4234
Programmatically create a sale order line Solved
module sale sale.order.line programatically v9
Avatar
Avatar
1
apr 21
34959
How to generate line numbers on quotes Solved
sale sale.order.line
Avatar
Avatar
1
jan 25
4558
How to add freight charges to product cost in sale quoatation
sale sale.order.line
Avatar
Avatar
2
aug 24
6496
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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