Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Social media Marketing
    • E-mailmarketing
    • SMS Marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

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

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
pythonsubscriptionclassOdoo13.0Odoo13
3 Antwoorden
5825 Weergaven
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
Annuleer
Avatar
Paresh Wagh
Beste antwoord

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
Annuleer
Moaz Mabrok
Auteur

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
Auteur

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
Auteur

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

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
create domain from a custom field in `sale.subscription` odoo 13 Opgelost
python subscription odoo Odoo13.0 Odoo13
Avatar
1
mei 20
3993
how to get the source document of a subscription odoo
python subscription Odoo13.0
Avatar
0
jul. 20
4219
how to update quantity_done value based on stock.picking Validation in ODOO
python odoo Odoo13.0 Odoo13
Avatar
0
jan. 22
6173
how to add product to sale.subscription order line Opgelost
python subscription Odoo13.0 odoo13.0
Avatar
1
jun. 20
4261
How to access a custom module from the website (for portal users) [odoo13]
python portal website Odoo13.0 Odoo13
Avatar
Avatar
1
jun. 22
4292
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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