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
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    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

odoo 15 compute days differance

Abonare

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

Această întrebare a fost marcată
attributeerrorcomputed-fieldsv15
2 Răspunsuri
3318 Vizualizări
Imagine profil
سلمى سنتر

try to compute the days differance 


error:

raise exception.with_traceback(None) from new_cause
AttributeError: 'test.testing' object has no attribute '_compute_p_days'




py:

from datetime import date, timedelta
from odoo.exceptions import ValidationError
from odoo import api, fields, models


class test_testing(models.Model):
_name = 'test.testing'
_description = 'test code'

start_date = fields.Date(string = 'Start Date',
required = True)
end_date = fields.Date(string = 'End Date',
required = True)
p_days = fields.Float(string = 'Plan Days',
compute = '_compute_p_days',
default = lambda self: self._compute_p_days)
g_days = fields.Float(string = 'Days Gone',
compute = '_compute_g_days',
default = lambda self: self._compute_g_days)


@api.depends('start_date')
def _compute_g_days(self):
self.g_days = 0
for record in self:
if record.start_date > date.today():
raise ValidationError('Start date should not greater than end date.')
else:
record.g_days = (date.today() - record.start_date).days


@api.depends('start_date', 'end_date')
def _compute_p_days(self):
self.p_days = 0
for record in self:
if record.start_date > record.end_date:
raise ValidationError('Start date should not greater than end date.')
else:
record.p_days = (record.end_date - record.start_date).days

XML:

xml version="1.0" encoding="utf-8"?>


id="test_testing_view_form" model="ir.ui.view">
name="name">test.testing.form
name="model">test.testing
name="arch" type="xml">
string="Testing Code">

string="Information">
name="start_date" type="date"/>
name="end_date" type="date"/>
name="p_days"/>
name="g_days"/>






id="test_testing_tree" model="ir.ui.view">
name="name">test.testing.tree
name="model">test.testing
name="arch" type="xml">
string="Testing">
name="start_date" type="date"/>
name="end_date" type="date"/>
name="p_days"/>
name="g_days"/>




id="test_testing_action" model="ir.actions.act_window">
name="name">testing Code
name="type">ir.actions.act_window
name="res_model">test.testing
name="view_mode">tree,form
name="context">{}
name="domain">[]
name="help" type="html">

class="o_view_nocontent_smiling_face">
Create your first project!






id="menu_test"
name="test"
parent="test_root"
action="test_testing_action"
sequence="20"
/>




0
Imagine profil
Abandonează
Imagine profil
Bhavin Vekariya
Cel mai bun răspuns

Hey...


Please , try to without lambda function in field.

0
Imagine profil
Abandonează
Imagine profil
CandidRoot Solutions Private Limited
Cel mai bun răspuns
You can make changes like below to make your code working:

p_days = fields.Float(string = 'Plan Days',
compute = '_compute_p_days',
default = 0)
g_days = fields.Float(string = 'Days Gone',
compute = '_compute_g_days',
default = 0)


@api.depends('start_date')
def _compute_g_days(self):
for record in self:
record.g_days = 0
if record.start_date > date.today():
raise ValidationError('Start date should not greater than end date.')
else:
record.g_days = (date.today() - record.start_date).days


@api.depends('start_date', 'end_date')
def _compute_p_days(self):
for record in self:
if record.start_date and record.end_date:
if record.start_date > record.end_date:
raise ValidationError('Start date should not greater than end date.')
else:
record.p_days = (record.end_date - record.start_date).days
else:
record.p_days = 0


Thanks & Regards,

​

CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat
0
Imagine profil
Abandonează
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
Compute field to store in DB
computed-fields v15
Imagine profil
Imagine profil
1
iun. 23
3936
computed field doesnt work with a domain
fleet computed-fields v15
Imagine profil
0
apr. 24
2300
Odoo 15 - compute method triggered twice every time? Rezolvat
compute computed computed-fields v15
Imagine profil
Imagine profil
2
iul. 22
7932
Prevent navigation if records are not save
v15
Imagine profil
Imagine profil
Imagine profil
2
oct. 25
3176
Creating user creates duplicated partner_id
v15
Imagine profil
Imagine profil
1
sept. 25
3098
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