Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

loop through a subscription line then set value to field 0doo 13

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
pythonsubscriptionclassOdoo13.0Odoo13
3 Risposte
5816 Visualizzazioni
Avatar
Moaz Mabrok

Hi am new to both python and Odoo development, I used the web interface for customization before. I was trying to create a class to 

  1. add a field to sale.subscription Model

subscription_tier = fields.Char(string='Subscription Tier',readonly=True)

enter code here

  1. loop through subscription line to see if the customer has silver or gold subscription then set it to the field subscription_tier


class subscription_tire_set(models.Model):
    _inherit = 'sale.subscription'

    subscription_tier = fields.Char(string='Subscription Tier',readonly=True)

    @api.depends('recurring_invoice_line_ids.product_id')
    def _compute_release_to_pay(self):
        for n_subscription in self:
            result = None
            for n_subscription_line in n_subscription.recurring_invoice_line_ids:
                if any(n_subscription_line.product_id) == 'gold':

                    result = gold'
                    break
                else:
                    result = 'not'

        subscription_tier = result

I probably am doing something horribly wrong 

also a getting this massge when trying to open any customer in subscription

Something went wrong! sale.subscription(10,).subscription_tier

Thank u for the help in advance.

0
Avatar
Abbandona
Avatar
Paresh Wagh
Risposta migliore

Hi:

There seem to be a couple of syntax issues. You need to establish the linkage between the field and function for the computation to happen.

For example,

subscription_tier = fields.Char(string='Subscription Tier',readonly=True,compute='_compute_release_to_pay')
Also, you need to explicitly set the value of the field in the last line like so.
n_subscription.subscription_tier = result

You can read more about this here: 

https://www.odoo.com/documentation/13.0/reference/orm.html#computed-fields

EDIT:
Change the if...else to the following by removing the "any" and comparing 'gold' with the name. The comparison is case-sensitive, so you need to ensure that it matches your data.

                if n_subscription_line.product_id.name == 'gold':
result = gold'
break
else:
result = 'not'

Also the last line needs to be indented in by 4 spaces if you want it executed once for each subscription.



0
Avatar
Abbandona
Moaz Mabrok
Autore

it works thank u I was stuck for hours

The customer must be one only subscription_tier how can I stop the section of multiple.

should I use onchange on the `n_subscription.recurring_invoice_line_ids` or something else

Moaz Mabrok
Autore

sorry it works to add a value but it's always `not`

Paresh Wagh

I have edited my previous reply and added more information related to your questions under the EDIT section

Moaz Mabrok
Autore

Thank for your quick reply works like a charm and sorry for the delay i had uni finals

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
create domain from a custom field in `sale.subscription` odoo 13 Risolto
python subscription odoo Odoo13.0 Odoo13
Avatar
1
mag 20
3965
how to get the source document of a subscription odoo
python subscription Odoo13.0
Avatar
0
lug 20
4208
how to update quantity_done value based on stock.picking Validation in ODOO
python odoo Odoo13.0 Odoo13
Avatar
0
gen 22
6143
how to add product to sale.subscription order line Risolto
python subscription Odoo13.0 odoo13.0
Avatar
1
giu 20
4251
How to access a custom module from the website (for portal users) [odoo13]
python portal website Odoo13.0 Odoo13
Avatar
Avatar
1
giu 22
4286
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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