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] Update view calling function from another model using button?

Odebírat

Get notified when there's activity on this post

This question has been flagged
functionbuttonodoo10.0
4 Odpovědi
10393 Zobrazení
Avatar
FEDERICO LEONI

I've inherited the pos.session model with a function triggered when an index changed:

class divina_session(models.Model):        
    _inherit = 'pos.session'
  order_paid = fields.Integer('Order Paid', store=True, default='0')

@api.multi
def _write(self, vals):
res = super(divina_session, self)._write(vals)

for record in self:
record.set_data_write(vals, record)
return res
    @api.multi    
    def set_data_write(self, vals, record):        
        if vals.get('order_paid'):
            my code here

The method is used to update a whole record on another model (pos.adm).

Pos.adm has a tree view, and I would like to update the view from button, since it doesn't update automatically after db changed... However I don't know what syntax should I use on my button definition and, most important, how to trigger it on pos.session since my index (order_paid) will not change on button press. 

Any clue?

Thanks.

F.

0
Avatar
Zrušit
FEDERICO LEONI
Autor

Solved (for now) calling directly the menu item from a button in my view. Simple and effective, even with a little drawback. 

<button name="%(adm_sessions_tree_view2)d" string="Update" type="action"
class="oe_highlight" attrs = "{'invisible':[('state','!=','opened')]}"/>

This will  update the view exactly like will do when calling the menu item itself (that is hidden on a 2 levels submenu), without the need to refresh the whole page. I'm still working on it to force an update manually but for now I can spend my effort on other issues I need to solve with other functions.

Avatar
FEDERICO LEONI
Autor Nejlepší odpověď

Solved, even if  with a not so elegant, pythonic way.

On pos.adm I created a new def since is quite easy search for the correct one (pos_session.name =is equal to pos_adm.pos_ref):

@api.multi
def _update_tree(self):

pse = self.env['pos.session'].search([('name', '=', self.pos_ref)])
pse.write({'order_paid': pse.order_paid + 1})

Since order_paid field is just an index used to trigger function is not a problem use it to force a db check.

After that I simply wrote some lines of xml for a function called by a button.

    <record id = "update" model = "ir.actions.server">
<field name = "sequence" eval = "5"/>
<field name = "name">update_session</field>
<field name = "model_id" ref = "model_pos_adm"/>
<field name = "condition">True</field>
<field name = "type">ir.actions.server</field>
<field name = "state">code</field>
<field name = "code">
pos_obj = env['pos.adm'].browse(context.get('active_id'))
pos_obj._update_tree()
</field>
</record>

The button call:

<button name="%(update)d" string="Up" type="action"
class="oe_highlight" attrs = "{'invisible':[('state','!=','opened')]}"/>

Now I have a quicker real time update on my tree view.   

0
Avatar
Zrušit
Avatar
Niyas Raphy (Walnut Software Solutions)
Nejlepší odpověď

Hi,

Inside the write function you can achieve this, check whether Vals contains order_paid value, if so you can execute your action. First of all what is the relation between pos.session and pos.admin ? You have to get it, then if you need to execute a function in the pos.admin model, you can search the records of pos.admin model and iterate over the loop and call the function.

@api.multi
def _write(self, vals):
res = super(divina_session, self)._write(vals)
if vals.get('order_paid'):
# if there is any search filters you can give it
pos_admin_rec = self.env['pos.admin'].search([])
for pos_rec in POs_admin_rec:
#here call the function in pos.admin model
pos_rec.function_name()
return res


Thanks

1
Avatar
Zrušit
FEDERICO LEONI
Autor

Niyas, thanks for your reply.

When an order is marked as paid, vals is reached two times (don't know exactly why) with tho different values. THe first time gets 'sequence_number' and the second one gets 'order_paid':

vals {'sequence_number': 17}

vals {'order_paid': 2}

Then I can intercept vals and make my call.

There is not a direct relation (nor related field) between pos.session and pos.adm.

The function on pos.session will create the basic data on pos.adm, and then the record will be populated from another function on pos.adm.

I know how to reach a function on another model (thanks anyway!) but the problem is calling by a button. I have update the thread title because was not clear.

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
api request
function api button
Avatar
0
pro 24
2014
How to open a wizard with yes or no buttons (Odoo 14) Vyřešeno
function button Buttons
Avatar
Avatar
Avatar
2
zář 22
9681
How To Calculate Age From Birthday Vyřešeno
function odoo odoo10.0
Avatar
Avatar
Avatar
Avatar
Avatar
7
zář 21
29435
How to connect button with function? Vyřešeno
function form inherit button
Avatar
Avatar
Avatar
3
pro 23
20889
how translate 'from openerp.osv import fields' of Odoo 9 to Odoo 10 Vyřešeno
function upgrading translate odoo10.0
Avatar
Avatar
Avatar
2
kvě 17
7960
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