Zum Inhalt springen
Odoo Menü
  • Anmelden
  • Jetzt gratis testen
  • Apps
    Finanzen
    • Buchhaltung
    • Rechnungsstellung
    • Spesenabrechnung
    • Tabellenkalkulation (BI)
    • Dokumente
    • E-Signatur
    Vertrieb
    • CRM
    • Vertrieb
    • Kassensystem – Shop
    • Kassensystem – Restaurant
    • Abonnements
    • Vermietung
    Websites
    • Website-Builder
    • E-Commerce
    • Blog
    • Forum
    • Livechat
    • E-Learning
    Lieferkette
    • Lager
    • Fertigung
    • PLM
    • Einkauf
    • Wartung
    • Qualität
    Personalwesen
    • Mitarbeiter
    • Personalbeschaffung
    • Abwesenheiten
    • Mitarbeiterbeurteilung
    • Personalempfehlungen
    • Fuhrpark
    Marketing
    • Social Marketing
    • E-Mail-Marketing
    • SMS-Marketing
    • Veranstaltungen
    • Marketing-Automatisierung
    • Umfragen
    Dienstleistungen
    • Projekte
    • Zeiterfassung
    • Außendienst
    • Kundendienst
    • Planung
    • Termine
    Produktivität
    • Dialog
    • Genehmigungen
    • IoT
    • VoIP
    • Wissensdatenbank
    • WhatsApp
    Apps von Drittanbietern Odoo Studio Odoo Cloud-Plattform
  • Branchen
    Einzelhandel
    • Buchladen
    • Kleidergeschäft
    • Möbelhaus
    • Lebensmittelgeschäft
    • Baumarkt
    • Spielwarengeschäft
    Essen & Gastgewerbe
    • Bar und Kneipe
    • Restaurant
    • Fast Food
    • Gästehaus
    • Getränkehändler
    • Hotel
    Immobilien
    • Immobilienagentur
    • Architekturbüro
    • Baugewerbe
    • Immobilienverwaltung
    • Gartenarbeit
    • Eigentümervereinigung
    Beratung
    • Buchhaltungsfirma
    • Odoo-Partner
    • Marketingagentur
    • Anwaltskanzlei
    • Talentakquise
    • Prüfung & Zertifizierung
    Fertigung
    • Textil
    • Metall
    • Möbel
    • Speisen
    • Brauerei
    • Firmengeschenke
    Gesundheit & Fitness
    • Sportklub
    • Brillengeschäft
    • Fitnessstudio
    • Therapeut
    • Apotheke
    • Friseursalon
    Handel
    • Handyman
    • IT-Hardware & -Support
    • Solarenergiesysteme
    • Schuster
    • Reinigungsdienstleistungen
    • HLK-Dienstleistungen
    Sonstiges
    • Gemeinnützige Organisation
    • Umweltschutzagentur
    • Plakatwandvermietung
    • Fotostudio
    • Fahrrad-Leasing
    • Software-Händler
    Alle Branchen ansehen
  • Community
    Lernen
    • Tutorials
    • Dokumentation
    • Zertifizierungen
    • Schulung
    • Blog
    • Podcast
    Bildung fördern
    • Bildungsprogramm
    • Scale-Up! Planspiel
    • Odoo besuchen
    Software anfragen
    • Herunterladen
    • Editionen vergleichen
    • Releases
    Zusammenarbeiten
    • Github
    • Forum
    • Veranstaltungen
    • Übersetzungen
    • Partner werden
    • Dienstleistungen für Partner
    • Buchhaltungsfirma registrieren
    Services anfragen
    • Partner finden
    • Buchhalter finden
    • Einen Experten treffen
    • Implementierungsservices
    • Kundenreferenzen
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Eine Demo erhalten
  • Preiskalkulation
  • Hilfe

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

  • CRM
  • e-Commerce
  • Buchhaltung
  • Lager
  • PoS
  • Projekte
  • MRP
All apps
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Sie müssen registriert sein, um mit der Community zu interagieren.
Alle Beiträge Personen Abzeichen
Stichwörter (Alle anzeigen)
odoo accounting v14 pos v15
Über dieses Forum
Hilfe

when i add text to date diff result get this error ValueError: invalid literal for int() with base

Abonnieren

Erhalten Sie eine Benachrichtigung, wenn es eine Aktivität zu diesem Beitrag gibt

Diese Frage wurde gekennzeichnet
odoo12.0
1 Antworten
3317 Ansichten
Avatar
Mohamed Safi

I have a date field in form that allows the users to enter a date which presumably the deadline of a task and I want to have difference between today with deadline and concern of: 1.if the date has passed, then show 'overdue' 2.if not, then show the number of days left the given date and add text that say 'the left day are {%results of difference days%}' which field type can aggregate integer with text

from odoo import models, fields
from odoo import api
from datetime import datetime


class todotask(models.Model):
    _name='todo.task'
    _description='to manage your job tasks'

    name=fields.Char('Description', required=True)
    gov_deprt_id=fields.Many2many('res.partner',string='Gov 
                 Department')
    company=fields.Many2one('res.partner',
            string='Work For')
    start_date=fields.Date('Start Date')
    deadline_date=fields.Date('Deadline')
    is_done=fields.Boolean('Done?')
    note=fields.Text('Note')
    amount=fields.Float('Cost Amount')
    remaining_days=fields.Integer(string="Remaining Days")

@api.onchange('start_date', 'deadline_date', 'remaining_days')

def calculate_date(self):
     while self.start_date and self.deadline_date:
        d1 = datetime.strptime(str(self.start_date), '%Y-%m-%d')
        d2 = datetime.strptime(str(self.deadline_date), '%Y-%m-%d')
        d3 = d2 - d1
        self.remaining_days ="{} and {}".format("tttt", str(d3.days))
0
Avatar
Verwerfen
Sehrish

Odoo Tips: http://learnopenerp.blogspot.com/

Avatar
Marius Stedjan
Beste Antwort

You can do the string logic in the view, instead of the model.

I would make the remaining_days field a computed field and make the calculate_date method set this field.
To respect the Odoo developer guidelines, name the method compute_remaining_days ;)

In the view, you can check remaining_days, and then make the view show/hide the fields and text you want.

BTW: You got some indentation errors in your code. The decorator and function must have the same indentation level as the field declarations.
Also, do you want to pick multiple Gov Departments from res.partner? If so, name the field gov_deprt_ids
If you want to pick just one, use a Many2one field, and name the field as you have done with "_id".
Do the same for any relational field in your model (hint: company)

Try this out for your model:

from odoo import api, fields, models


class TodoTask(models.Model):
    _name = 'todo.task'
    _description = 'Todo Task'
    
    name = fields.Char('Description', required=True)
    gov_deprt_id = fields.Many2one('res.partner', string='Gov Department')
    company_id = fields.Many2one('res.partner', string='Work For')
    start_date = fields.Date('Start Date')
    deadline_date = fields.Date('Deadline')
    is_done = fields.Boolean('Done?')
    note = fields.Text('Note')
    amount = fields.Float('Cost Amount')
    remaining_days = fields.Integer(
        string="Remaining Days",
        compute=_'compute_remaining_days'
    )

    @api.depends('deadline_date')
    def _compute_remaining_days(self):
        for task in self:
            if task.deadline_date:
                time_delta = task.deadline_date - fields.Date.today()
                task.remaining_days = time_delta.days

As for the view, the Odoo Docs are well documented. There are many ways you could do this.. so giving a specific example is hard. 

If you want to calculate the message to the user in python, you can make a Char/text field called for example "Message" and then compute this message with a method (like with remaining_days). Make it readonly so people can't edit it.
Making a string like you mentioned doesn't necessarily fit very well with Odoo's way of doing form views etc. Showing "Overdue" or days remaining on a smart button, or use states in the statusbar would be more Odoo-like, in my opinion.

I would also recommend reading the developer guidelines as well as PEP8 (get a linter for you editor, it helps learning - a lot!).

Hope it helps! :D


0
Avatar
Verwerfen
Diskutieren Sie gerne? Treten Sie bei, statt nur zu lesen!

Erstellen Sie heute ein Konto, um exklusive Funktionen zu nutzen und mit unserer tollen Community zu interagieren!

Registrieren
Verknüpfte Beiträge Antworten Ansichten Aktivität
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
Avatar
Avatar
Avatar
2
Okt. 25
2005
How to write Record Rule with domain based on the company_dependent Fields Gelöst
odoo12.0
Avatar
Avatar
Avatar
3
Okt. 23
10790
loan request
odoo12.0
Avatar
Avatar
1
Sept. 23
4037
sum Colum of based on id
odoo12.0
Avatar
Avatar
1
Mai 23
3012
How to make pagination that has a table in qweb
odoo12.0
Avatar
Avatar
2
Apr. 23
3762
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Herunterladen
  • Github
  • Runbot
  • Übersetzungen
Dienstleistungen
  • Odoo.sh-Hosting
  • Support
  • Upgrade
  • Individuelle Entwicklungen
  • Bildung
  • Buchhalter finden
  • Partner finden
  • Partner werden
Über uns
  • Unsere Firma
  • Markenwerte
  • Kontakt
  • Karriere
  • Veranstaltungen
  • Podcast
  • Blog
  • Kunden
  • Rechtliches • Datenschutz
  • Sicherheit
الْعَرَبيّة 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 ist eine Suite von Open-Source-Betriebsanwendungen, die alle Bedürfnisse Ihres Unternehmens abdecken: CRM, E-Commerce, Buchhaltung, Lager, Kassensystem, Projektmanagement etc.

Das einzigartige Wertversprechen von Odoo ist, dass es gleichzeitig sehr einfach zu bedienen und voll integriert ist.

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