Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    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
    Výroba
    • 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
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Help

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

odoo 15 compute days differance

Odoberať

Get notified when there's activity on this post

This question has been flagged
attributeerrorcomputed-fieldsv15
2 Replies
3267 Zobrazenia
Avatar
سلمى سنتر

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
Avatar
Zrušiť
Avatar
Bhavin Vekariya
Best Answer

Hey...


Please , try to without lambda function in field.

0
Avatar
Zrušiť
Avatar
CandidRoot Solutions Private Limited
Best Answer
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
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
Compute field to store in DB
computed-fields v15
Avatar
Avatar
1
jún 23
3869
computed field doesnt work with a domain
fleet computed-fields v15
Avatar
0
apr 24
2253
Odoo 15 - compute method triggered twice every time? Solved
compute computed computed-fields v15
Avatar
Avatar
2
júl 22
7850
Prevent navigation if records are not save
v15
Avatar
Avatar
Avatar
2
okt 25
3085
Creating user creates duplicated partner_id
v15
Avatar
Avatar
1
sep 25
3010
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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