コンテンツへスキップ
Odoo メニュー
  • サインイン
  • 無料で15日試す
  • アプリ
    財務
    • 会計
    • 請求
    • 経費
    • スプレッドシート(BI)
    • ドキュメント管理
    • 署名
    販売
    • CRM
    • 販売
    • POS店舗
    • POSレストラン
    • サブスクリプション
    • レンタル
    ウェブサイト
    • ウェブサイトビルダー
    • eコマース
    • ブログ
    • フォーラム
    • ライブチャット
    • eラーニング
    サプライチェーン
    • 在庫
    • 製造
    • 製品ライフサイクル管理 (PLM)
    • 購買
    • 整備
    • 品質
    人事業務
    • 従業員管理
    • 採用
    • 休暇管理
    • 人事評価
    • リファラル
    • フリート
    マーケティング
    • ソーシャルマーケティング
    • メールマーケティング
    • SMSマーケティング
    • イベント
    • マーケティングオートメーション
    • アンケート調査
    サービス
    • プロジェクト管理
    • タイムシート
    • フィールドサービス
    • ヘルプデスク
    • 計画
    • アポイントメント
    生産性向上ツール
    • ディスカッション
    • 承認
    • IoT
    • VoIP
    • ナレッジ
    • WhatsApp
    サードパーティアプリ Odooスタジオ Odooクラウドプラットホーム
  • インダストリー(業種別ソリューション)
    小売
    • 書店
    • アパレルショップ
    • 家具専門店
    • 食料品店
    • 金物店
    • 玩具店
    飲食・ホスピタリティ業界
    • バー・パブ
    • レストラン
    • ファストフード
    • ゲストハウス
    • 飲料販売代理店
    • ホテル
    不動産
    • 不動産会社
    • 建築事務所
    • 建設
    • 不動産管理
    • 造園
    • 住宅所有者組合
    コンサルティング
    • 会計事務所
    • Odooパートナー
    • マーケティングエージェンシー
    • 法律事務所
    • 人材派遣
    • 監査・認証
    製造
    • テキスタイル
    • 金属
    • 家具
    • 飲食
    • 醸造所
    • コーポレートギフト
    ヘルス & フィットネス
    • スポーツクラブ
    • 眼鏡店
    • フィットネスセンター
    • ウェルネス専門家
    • 薬局
    • ヘアサロン
    業種
    • 便利屋
    • IT ハードウェア・サポート
    • 太陽エネルギーシステム
    • 靴メーカー
    • クリーニングサービス
    • 空調設備サービス
    その他
    • 非営利団体
    • 環境機関
    • ビルボードレンタル
    • 写真
    • 自転車リース
    • ソフトウェアリセラー
    すべての業種を見る
  • コミュニティ
    学ぶ
    • チュートリアル
    • ドキュメンテーション
    • 認定
    • トレーニング
    • ブログ
    • ポッドキャスト
    教育サポート
    • 教育プログラム
    • Scale Up! ビジネスゲーム
    • Odooオフィス訪問
    ソフトを入手
    • ダウンロード
    • エディションを比較
    • リリース
    コラボレーション
    • 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:

  • CRM
  • 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 返信
3320 ビュー
アバター
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
10月 25
2006
How to write Record Rule with domain based on the company_dependent Fields 解決済
odoo12.0
アバター
アバター
アバター
3
10月 23
10797
loan request
odoo12.0
アバター
アバター
1
9月 23
4038
sum Colum of based on id
odoo12.0
アバター
アバター
1
5月 23
3013
How to make pagination that has a table in qweb
odoo12.0
アバター
アバター
2
4月 23
3762
コミュニティ
  • チュートリアル
  • ドキュメンテーション
  • フォーラム
オープンソース
  • ダウンロード
  • Github
  • Runbot
  • 翻訳
サービス
  • Odoo.shホスティング
  • サポート
  • アップグレード
  • カスタム開発
  • 教育プログラム
  • 会計事務所一覧
  • パートナー一覧
  • パートナーになる
企業情報
  • 会社概要
  • ブランドアセット
  • お問い合わせ
  • 採用情報
  • イベント
  • ポッドキャスト
  • ブログ
  • お客様一覧
  • リーガル情報 • プライバシーポリシー
  • セキュリティ
الْعَرَبيّة 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(オドゥー)は、CRM、eコマース、会計、在庫管理、POS、プロジェクト管理など、企業のさまざまな業務を一つのシステムで管理できる、ベルギー発のオープンソースのERPソフトウェアです。

高機能で使いやすく、完全に統合されたERPとして、ユニークな価値を提供しています。

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