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

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

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
odoo12.0
1 Beantwoorden
3324 Weergaven
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
Annuleer
Sehrish

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

Avatar
Marius Stedjan
Beste antwoord

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
Annuleer
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
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
Avatar
Avatar
Avatar
2
okt. 25
2006
How to write Record Rule with domain based on the company_dependent Fields Opgelost
odoo12.0
Avatar
Avatar
Avatar
3
okt. 23
10803
loan request
odoo12.0
Avatar
Avatar
1
sep. 23
4038
sum Colum of based on id
odoo12.0
Avatar
Avatar
1
mei 23
3013
How to make pagination that has a table in qweb
odoo12.0
Avatar
Avatar
2
apr. 23
3764
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