Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

How to filter fields in one2many base on it's many2one?

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
defaultspython2.7openerp7default_get
4 Odpowiedzi
10958 Widoki
Awatar
Anirudh Lou

We know that in class sale_order has sale_order_line. I am wondering now how can i filter/set default value for some fields. Here is my illustration.

In class res_partner i add some field of type selection:

'part_type' : fields.selection([('child','Child'),('adult','Adult'),('senior','Senior')],'Partner Type')

In sale_order_line i also add this:

'rule_applied' : fields.selection([('low','Low'),('lower','Lower'),('lowest','Lowest')],'Rule') 

Now, if a user select a partner in sale_order and if he try to add an item on its sale_order_line i want to set the default value of rule_applied according to this criteria: If the partner_type of partner selected is child then the default value of rule_applied is Lowest, if senior then Lower and if adult then Low. I tried this method but it does not work:


    def default_get(self, cr, uid, fields, context=None):
res = super(sale_order_line, self).default_get(cr, uid, fields, context=context)
_logger.info("\n\n\t\t\tSetting up rule >>> fields %s"%(str(context)))
_logger.info("\n\n\t\t\tSetting up rule >>> res %s"%(str(res)))
if 'partner_id' in fields or 'order_id' in fields:
partner_id = res['partner_id']
order_id = res['order_id']
if partner_id:
part_list = self.pool.get('res.partner').search(cr,uid,[('customer','=',True)])
partner = self.pool.get('res.partner').browse(cr,uid,part_list,context=context)
if partner.part_type == 'child':
res['rule_applied'] = 'lowest'
elif partner.part_type == 'adult':
res['rule_applied'] = 'low'
elif partner.part_type == 'senior':
res['rule_applied'] = 'lowe'
else:
res['rule_applied'] = False
if order_id:
order = self.pool.get('sale.order').browse(cr,uid,order_id,context=context)
partner = self.pool.get('res.partner').browse(cr,uid,order.partner_id.id,context=context)
if partner.part_type == 'child':
res['rule_applied'] = 'lowest'
elif partner.part_type == 'adult':
res['rule_applied'] = 'low'
elif partner.part_type == 'senior':
res['rule_applied'] = 'lowe'
else:
res['rule_applied'] = False

return res

But it does not work. upon running, my does not work.

Help is much needed.

0
Awatar
Odrzuć
Awatar
Axel Mendoza
Najlepsza odpowiedź

If I need to code this I will do the following steps:

Add a field to sale.order to use it only for determine the default value to be passed to the order_lines fields

'rule_tpl' : fields.dummy(type="selection",selection=[('low','Low'),('lower','Lower'),('lowest','Lowest')],string='Rule') 

Create an onchange method on the partner field to return the value of the new field rule_tpl using your conditions, that method already exist for sale.order you will be overriding in order to add more values, for that just call super() of your class (for example for the class sale_order will be super(sale_order, self) ). Something like this:

class sale_order(osv.osv):
_name = 'sale.order'
_inherit = 'sale.order'
...
...
def onchange_partner_id(self, cr, uid, ids, partner_id, context=None):
        res = super(sale_order, self).onchange_partner_id(cr, uid, ids, partner_id, context=context)
        partner = self.pool.get('res.partner').browse(cr,uid,partner_id,context=context)
if partner.part_type == 'child':
  res['value']['rule_tpl'] = 'lowest'
elif partner.part_type == 'adult':
res['value']['rule_tpl'] = 'low'
elif partner.part_type == 'senior':
res['value']['rule_tpl'] = 'lower'
else:
res['value']['rule_applied'] = False
return res
...
... 

sale_order()

then in sale.order view form you need to declare the new field rule_tpl with invisible="1" and use it in the context passed to the field order_lines, like this example:


        <record model="ir.ui.view" id=field_tpl_sale_order">
<field name="name">field.tpl.sale.order.view.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form" />
<field name="arch" type="xml">
<field name="origin" position="after">
<field name="rule_tpl" invisible="1"/>
</field>
<field name="order_lines" position="attributes">
<attribute name="context">{'default_rule_applied': rule_tpl}</attribute>
</field>
</field>
</record>

With this setup I think that you will be ok, the default_ values passed in the context of relation fields cause that records created in that field assume those values as defaults

2
Awatar
Odrzuć
Anirudh Lou
Autor

Okay thanks a lot. I'll try it tomorrow at computer lab. By the way in that case do i still need to define default_get in sale_order_line or no need?

Anirudh Lou
Autor

Why does overriding onchange_partner_id produce a client error, it says: "TypeError: val is undefined" i also tried to copy the original method and add what you suggested but same error output.

Anirudh Lou
Autor

I guess it's because my field is of type dummy. So, with all due respect, i change it to a regular field selection.

Axel Mendoza

The error you mentioned could be more verbosed?? With what you said is impossible to know what is causing it. I don't think that dummy is the source of the error. Please post the error log

Anirudh Lou
Autor

Thanks! It helped me a lot.

Anirudh Lou
Autor

with fields.dummy this is what i get: OpenERP Client Error TypeError: val is undefined http://localhost:8069/web/static/src/js/pyeval.js:685

Awatar
Pawan
Najlepsza odpowiedź

Anirudh,
    

So, If it is not there in res, then ... pass the partner_id in context of sale_order_line(one2many) field and then you can easily get it in default get of sale order line context, which you already implemented ..

There in default_get use that partner_id for your further operation...    

hope it helps!    

0
Awatar
Odrzuć
Anirudh Lou
Autor

Yeah, thanks for pointing it out it's order_partner_id, but it's not present in res.

Anirudh Lou
Autor

From sale_order_line how can i get the value of partner_id in sale_order? I think i cannot rely on order_partner_id because it is of type related and by default it has no value. Just correct me if i am wrong.

Pawan

check my updated answer....

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
How do I create a message box/ dialog box in openerp 7 with 'Ok' and 'Cancel' buttons in it
python2.7 openerp7
Awatar
Awatar
3
wrz 18
6288
Hide edit button according to status in openerp
python2.7 openerp7
Awatar
0
lut 16
4375
How to get the sum of field in a column?
python2.7 openerp7
Awatar
0
sie 15
6293
Default value of a field depending on a field of parent model
defaults default_get
Awatar
0
lip 15
4664
How to show two fields from the same table whith on change
python2.7 openerp7
Awatar
Awatar
1
mar 15
1230
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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