Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

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

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
pythonsubscriptionclassOdoo13.0Odoo13
3 Răspunsuri
5809 Vizualizări
Imagine profil
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
Imagine profil
Abandonează
Imagine profil
Paresh Wagh
Cel mai bun răspuns

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
Imagine profil
Abandonează
Moaz Mabrok
Autor

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
Autor

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
Autor

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
create domain from a custom field in `sale.subscription` odoo 13 Rezolvat
python subscription odoo Odoo13.0 Odoo13
Imagine profil
1
mai 20
3961
how to get the source document of a subscription odoo
python subscription Odoo13.0
Imagine profil
0
iul. 20
4202
how to update quantity_done value based on stock.picking Validation in ODOO
python odoo Odoo13.0 Odoo13
Imagine profil
0
ian. 22
6120
how to add product to sale.subscription order line Rezolvat
python subscription Odoo13.0 odoo13.0
Imagine profil
1
iun. 20
4242
How to access a custom module from the website (for portal users) [odoo13]
python portal website Odoo13.0 Odoo13
Imagine profil
Imagine profil
1
iun. 22
4268
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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