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í
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textil
    • Kov
    • Nábytek
    • Jídlo
    • Pivovar
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • Podpora IT & hardware
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Procházet všechna odvětví
  • 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
    • Služby pro partnery
    • 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

why context isn't passed to .py?

Odebírat

Get notified when there's activity on this post

This question has been flagged
7 Odpovědi
7737 Zobrazení
Avatar
Andrew

Hi, I have a function called search in boatcompany.py that uses the context i'm passing in the attribute as below:

<xpath expr="//field[@name='product_id']" position="attributes">
            <attribute name="context">{'boatmodel_id': parent.boatmodel_id}</attribute>
</xpath>

I expect to get context['boatmodel_id'] in my def, but I didn't. I print context and see all the defaults context only. May I know why? Below are my files:

boatcompany.py

from osv import osv, fields

class product_product(osv.osv):
    _inherit = "product.product"
    _columns = {
        'boatlength': fields.char("Boat Length", size=10),
        'fuelcapacity': fields.char("Fuel Capacity", size=10),
        'modeloptions_id': fields.many2one('product.category','Model Options')
    }
    def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
        print context
        if context is None:
            context = {}
        if context.get('boatmodel_id'):
            print "CONTEXT===="
            print context['boatmodel_id']
            productobj = self.pool.get('product.product').read(cr, uid, context['boatmodel_id'], ['modeloptions_id'])
            args = [('categ_id','=',productobj['modeloptions_id'][0])] + args
        return super(product_product, self).search(cr, uid, args, offset, limit, order, context=context, count=count)

class sale_order(osv.osv):
    _inherit = "sale.order"
    _columns = {
        'boatmodel_id': fields.many2one("product.product", "Boat Model", domain=[('categ_id.name','=','Boat Models')])
    }

and inheriting sale_view.xml in boatcompany_view.xml as below:

   <record id="sale_view_order_form" model="ir.ui.view">
      <field name="model">sale.order</field>
      <field name="inherit_id" ref="sale.view_order_form" />
      <field name="arch" type="xml">
        <field name="partner_id" position="after">
          <field name="boatmodel_id" />
        </field>
        <xpath expr="//field[@name='product_id']" position="attributes">
          <attribute name="context">{'boatmodel_id': parent.boatmodel_id}</attribute>
        </xpath>
      </field>
    </record>
0
Avatar
Zrušit
Brett Lehrer

I'm not sure why you're trying to use the context here, or what end goal you're trying to accomplish. I think what you ought to be doing is setting the domain on the product_id field in the sales order form, if you're trying to filter that down based on another custom field you're adding in.

Jan Dasenbrock

I've got the same Problem over here. It seems like it is a bug. Somehow the context does't change, even though it should.

Avatar
Jae Landers
Nejlepší odpověď

Trick I found to work is to override the whole context with the context already passed (found using developer mode) a more explicit xpath. Also, there is another view that is overriding that field (sale.order.form.sale.stock). The below passes the appropriate context on the sales order line without opening the other form:

<record id="sale_view_order_form_inherit" model="ir.ui.view">
<field name="name">sale.view.order.form.inherit</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="boatmodel_id"/>
</field>
<xpath expr="//field[@name='order_line']/tree//field[@name='product_id']" position="attributes">
<attribute name="context">{'boatmodel_id': parent.boatmodel_id,'partner_id':parent.partner_id, 'quantity':product_uom_qty, 'pricelist':parent.pricelist_id, 'uom':product_uom"</attribute>
</xpath>
</field>
</record>



0
Avatar
Zrušit
Avatar
Jan Dasenbrock
Nejlepší odpověď

The solution from Vichai Vongvorakul didn't work for me, but I finally figured out a solution for me. First of all you need to change the Technical Settings in the Users Access Right. You have to activate "Properties on lines", so a new window pops up when you create a new order line in the sales order. Otherwise the context won't be passed correctly. You also need to change your boatcompany_view.xml like Vichai Vongvorakul to <field name="inherit_id" ref="sale_stock.view_order_form_inherit"/> not <field name="inherit_id" ref="sale.view_order_form"/>. Otherwise you won't affect the context of the field "product_id" in the window that pops up.

Hope this will help.

0
Avatar
Zrušit
Avatar
jgonzalez
Nejlepší odpověď

I had the same problem with that example. Doing those changes helped get the "boatmodel_id" in the context, but I get a bool in "modeloptions_id".

This is error that I get from OpenErp sever.

args = [('categ_id', '=', productobj['modeloptions_id'][0])] + args TypeError: 'bool' object has no attribute '__getitem__'

I really appreciate some help.

Thanks,

jgonzalez

0
Avatar
Zrušit
Avatar
Vichai Vongvorakul
Nejlepší odpověď

Change something in boatcompany_view.xml: ... <field name="inherit_id" ref="sale_stock.view_order_form_inherit"/> ...

Hope this will help.

0
Avatar
Zrušit
Jarmo Nurmela

Thanks! It helped. I had the same problem.

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