تخطي للذهاب إلى المحتوى
أودو القائمة
  • تسجيل الدخول
  • جرب مجاناً
  • التطبيقات
    المالية
    • المحاسبة
    • فوترة
    • النفقات
    • جدول البيانات (BI)
    • المستندات
    • توقيع إلكتروني
    المبيعات
    • إدارة علاقات العملاء
    • المبيعات
    • نقطة البيع للمتاجر
    • نقطة البيع للمطاعم
    • الاشتراكات
    • تأجير
    المواقع الإلكترونية
    • أداة بناء المواقع الإلكترونية
    • متاجر إلكترونية
    • مدونة
    • المنتدى
    • دردشة مباشرة
    • التعليم الإلكتروني
    سلسلة التوريد
    • المستودعات
    • التصنيع
    • إدارة دورة حياة المنتج
    • المشتريات
    • الصيانة
    • الجودة
    الموارد البشرية
    • موظفون
    • التوظيف
    • إجازة عمل
    • التقييمات
    • الإحالات
    • تطبيق الأسطول
    التسويق
    • التسويق الإجتماعي
    • التسويق عبر البريد الإلكتروني
    • التسويق عبر الرسائل النصية
    • فعاليات
    • أتمتة التسويق
    • الاستطلاعات
    الخدمات
    • المشاريع
    • الجداول الزمنية
    • الخدمة الميدانية
    • مكتب المساعدة
    • التخطيط
    • مواعيد
    اﻹنتاجية
    • مناقشة
    • الموافقات
    • إنترنت الأشياء "IoT"
    • بروتوكول ربط المحادثات الصوتية عبر الإنترنت
    • المعرفة
    • WhatsApp
    التطبيقات الخارجية ستوديو أودو منصة أودو السحابية
  • قطاعات الأعمال
    البيع بالتجزئة
    • متجر كتب
    • متجر ملابس
    • متجر أثاث
    • متجر بقالة
    • متجر معدات
    • متجر ألعاب
    الطعام والضيافة
    • بار وحانة
    • المطعم
    • مطعم للوجبات السريعة
    • نزل للضيوف
    • موزّع مشروبات
    • فندق
    العقارات
    • وكالة عقارات
    • شركة هندسة معمارية
    • البناء
    • إدارة العقارات
    • العناية بالحدائق
    • اتحاد مُلاّك العقارات
    استشارة
    • مؤسسة محاسبية
    • شريك أودو
    • وكالة تسويقية
    • منشأة قانونية
    • استقطاب المواهب
    • التدقيق والتوثيق
    التصنيع
    • الأقمشة
    • معدني
    • الأثاث
    • الطعام
    • مصنع خمور
    • هدايا الشركات
    الصحة واللياقة البدنية
    • نادي رياضي
    • متجر نظارات
    • مركز لياقة بدنية
    • الممارسون الصحيون
    • صيدلية
    • صالون تصفيف الشعر
    التجارة
    • عامل صيانة
    • الأجهزة والمعدات التقنية ودعمها
    • أنظمة الطاقة الشمسية
    • صانع أحذية
    • خدمات التنظيف
    • خدمات التكييف (HVAC)
    غير ذلك
    • منظمة غير ربحية
    • وكالة بيئية
    • تأجير لوحات إعلانية
    • تصوير
    • تأجير دراجات
    • بائع وسيط للبرمجيات
    تصفح كافة قطاعات الأعمال
  • مجتمع أودو
    تعلم
    • دروس
    • التوثيق
    • شهادات
    • التدريب
    • مدونة
    • بودكاست
    قم بتعزيز التعليم
    • برنامج تعليم
    • Scale UP! لعبة الأعمال
    • قم بزيارة أودو
    احصل على البرنامج
    • تحميل
    • قارنْ الإصدارات
    • إطلاق
    تعاون
    • جيت هاب "Github"
    • المنتدى
    • فعاليات
    • الترجمات
    • كنْ شريكاً
    • خدمات الشركاء
    • سجل مكتب المحاسبة الخاص بك
    احصل على الخدمات
    • اعثر على شريك
    • اعثر على محاسب
    • قابل أحد مرشدي الأعمال
    • خدمات التنفيذ
    • مراجع العملاء
    • الدعم
    • الترقيات
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    الحصول على عرض توضيحي
  • الأسعار
  • المساعدة

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

  • إدارة علاقات العملاء
  • e-Commerce
  • المحاسبة
  • المخزون
  • PoS
  • المشروع
  • MRP
All apps
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
يجب أن تكون مسجلاً حتى تتفاعل مع المجتمع.
كافة المنشورات الأفراد الشارات
علامات التصنيف (عرض الكل)
odoo accounting v14 pos v15
حول هذا المنتدى
المساعدة

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

اشتراك

تسلم الإشعارات عندما يكون هناك نشاط في هذا المنشور

لقد تم الإبلاغ عن هذا السؤال
odoo12.0
1 الرد
3312 أدوات العرض
الصورة الرمزية
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
الصورة الرمزية
إهمال
Sehrish

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

الصورة الرمزية
Marius Stedjan
أفضل إجابة

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
الصورة الرمزية
إهمال
هل أعجبك النقاش؟ لا تكن مستمعاً فقط. شاركنا!

أنشئ حساباً اليوم لتستمتع بالخصائص الحصرية، وتفاعل مع مجتمعنا الرائع!

تسجيل
المنشورات ذات الصلة الردود أدوات العرض النشاط
Expected singleton: hr.emp.travel.location(62, 63)
odoo12.0
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
2
أكتوبر 25
2001
How to write Record Rule with domain based on the company_dependent Fields تم الحل
odoo12.0
الصورة الرمزية
الصورة الرمزية
الصورة الرمزية
3
أكتوبر 23
10769
loan request
odoo12.0
الصورة الرمزية
الصورة الرمزية
1
سبتمبر 23
4034
sum Colum of based on id
odoo12.0
الصورة الرمزية
الصورة الرمزية
1
مايو 23
3005
How to make pagination that has a table in qweb
odoo12.0
الصورة الرمزية
الصورة الرمزية
2
أبريل 23
3761
المجتمع
  • دروس
  • التوثيق
  • المنتدى
مصدر مفتوح
  • تحميل
  • جيت هاب "Github"
  • المشغل الآلي رنبوت
  • الترجمات
خدماتنا
  • استضافة أودو إس إتش
  • الدعم
  • الترقية
  • التطويرات المخصصة
  • التعليم
  • اعثر على محاسب
  • اعثر على شريك
  • كنْ شريكاً
معلومات عنا
  • شركتنا
  • أصول العلامة التجارية
  • اتصلْ بنا
  • الوظائف
  • فعاليات
  • بودكاست
  • مدونة
  • عملاء
  • قانوني • الخصوصية
  • الحماية
الْعَرَبيّة 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

أودو هو عبارة عن مجموعة من تطبيقات الأعمال مفتوحة المصدر التي تغطي جميع احتياجات شركتك، مثل: إدارة علاقات العملاء والتجارة الإلكترونية والمحاسبة والمخزون ونقاط البيع وإدارة المشاريع وما إلى ذلك.

ما يجعل من أودو مميزاً هو هدفه بأن يكون سهل الاستخدام للغاية ومتكاملاً تمامًا في الوقت ذاته.

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