Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Food & Hospitality
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Guest House
    • Distributor nápojů
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Trades
    • Údržbář
    • IT hardware a podpora
    • Solar Energy Systems
    • Výrobce obuvi
    • Úklidové služby
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

Odoo 10 : Domain and filtering for related fields one2many.

Odebírat

Get notified when there's activity on this post

This question has been flagged
viewsfieldsrelated_fieldsodoo10odoo10.0
2 Odpovědi
14714 Zobrazení
Avatar
Zied Haffoudhi

I have three table :

- product.

- package.

- product_package.


The product_package table have 2 fields which are related to the product and package as it mentionned bellow :

product_id = fields.Many2one('tjara.product', ondelete='cascade', string="Produit", index=True)
package_id = fields.Many2one('tjara.package', ondelete='cascade', string="Emballage", index=True)
_sql_constraints = [
('ligne_unique', 'unique (product_id, package_id)', '%(package_id)d Package is already exists for this product...!')
]


I added the _sql_contraints to avoid the duplicate fields. Because it can be only an unique relation between the product and a package.

And this is what I have in the product model :

product_package_ids = fields.One2many('tjara.product_package', 'product_id', string='Package')

And this is how to add a package from the product view :

                                <page string="Package">
                                    <label for="product_package_ids" string="Emballage"/>
                                    <field name="product_package_ids">
                                        <tree>
                                            <field name="package_id"/>
                                            <field name="price"/>
                                        </tree>
                                        <form>
                                             <field name="package_id"/>
                                            <field name="price"/>
                                        </form>
                                    </field>
                                </page>


This works fine for me. There is only one thing I want to enhance. When the user select an existing package for the product there is no error triggered. The error popped up only when you click "save the product".

I want either to display only the unexisting packages in the select field package_id. Or to pop up an error when the user try to add an existing package for the product.

 

0
Avatar
Zrušit
Avatar
Denis Baranov
Nejlepší odpověď

You can't achieve it by mere xml domain for 'package_id' or 'product_package_ids' since (1) in the latter there is no reference to a product. (2) when you create a product, it doesn't exist yet.

However, you may add the onchange for 'package_id' (in the method of tjara.product_package) to check uniq:


from odoo import exceptions
@api.multi
@api.onchange("package_id")
def onchange_package_id(self):
  for object in self: 
  if object.product_id:
    existing_ids = self.env["tjara.product_package"].search([('product_id','=',object.product_id.id)], limit=1)
    if len(existing_ids) > 0:
      raise exceptions.Warning(_('Package is already exists for this product...!'))
1
Avatar
Zrušit
Zied Haffoudhi
Autor

Thanks a lot IT Libertas,

I just replaced the 'object.product_id' by the product's name and I included a search for the package_id also. So I get the following and it's working well :

@api.onchange('package_id')

def onchange_product_package(self):

for object in self:

if object.product_id:

existing_ids = self.env["tjara.product_package"].search([('package_id', '=', object.package_id.id), ('product_id.name', '=', object.product_id.name)], limit=1)

if len(existing_ids) > 0:

raise exceptions.Warning(('Package is already exists for this product...!'))

Avatar
Bejaoui Souheil
Nejlepší odpověď

Hi,

SQL constraints are checked  when odoo send your request to database. In your case when you click the save button.

Use on_change to display alert message when the user change some values (more details).

@api.onchange('package_id',' product_id')
def onchange_product_package(self):
     if self.search([('package_id',='',self.package_id.id),('product_id_id',='',self.package_id.id)]:
         return {'warning': {'title': _('Warning'), 'message': _('your message.')}}

PS: Odoo have already product class and package classes. I don't think, it is a good idea to create new classes and not inherit the native ones.

Best regards.

1
Avatar
Zrušit
Zied Haffoudhi
Autor

Thanks a lot Souheil :)

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

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

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Is there an option or method to auto select the value in a field when you click on it in edit mode?
views fields odoo10
Avatar
Avatar
1
bře 19
5154
Odoo 10 - Inherited template field appears depends upon position Vyřešeno
views fields inherit odoo10
Avatar
Avatar
2
bře 18
5425
[CLOSED] I'm getting a validation error "Some fields are not set" set when using dynamic attributes. Vyřešeno
attrs views fields form_view odoo10
Avatar
Avatar
Avatar
8
pro 22
6543
Odoo 10 : Related fields and inheritance from third parent. (one2many)
fields relationship related related_fields odoo10
Avatar
0
kvě 17
3628
Related field; Error: 'Environment' object has no attribute 'picking_state'
related_fields odoo10
Avatar
0
dub 20
5673
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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