Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

How to get latest date from a date field

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
pythonodoo9.0
6 Replies
9579 Tampilan
Avatar
amina

I want to get the latest date from a date field and show it in a new field of an other view so I used this function and it seems I'm doing something wrong what could it be?here is my code

def _get_latest_intervention(self, cr, uid, ids, latest, args, context=None):
       res = {}
       obj_intervention = self.pool.get('c.intervention'
       )for interv in self.browse(cr, uid, ids, context=context):
           intervention_ids = obj_intervention.search(cr, uid,    [('equipement_id' '=',, intervention_id)], order='date_intv'
           , context=context)if intervention_ids:
               res[intervention_id] = intervention_ids[-1:][0
           ]else False
       return:
               res[intervention_id] = res

to explain more this module is about management of technical centers of vehicul so I want to show the latest date of intervention of those technical centers in their form view in the field "latest" so I have created 3 menu items (centre,equipement,intervention) and I have put this function in the centre class

0
Avatar
Buang
Lucio

You are looping (for _ in self.browse...) in elements of class intervention? I don't know, I'm just guessing from variable names. Is this method inside the class "Centre" ? What's the field that links togheter "centre" and "intervention"? What does equipement has to do with all this?

amina
Penulis

yes this methode is in the class"centre" ,I did this fault I wanted to wright 'centre_id' but I wrote 'equipement_id' so there is no equipements menchened in this function every centre has his equipements and all dates of intervention of equipments either it's a corrective maintenace or a preventive one so I want to add a new field in the centre form view named latest,which shows the latest added date in the intervention form view this classes are related of course with relational fields I will put all code to make it clearer

omar ahmed

see this maybe same idea

https://stackoverflow.com/questions/49748892/get-last-order-date-customer-in-odoo-partner-view

Avatar
amina
Penulis Jawaban Terbai

I changed somethings in my code so I want to show the date in the intervention_id field, here is my code 

# -*- coding: utf-8 -*-

from openerp import models, fields, api

class centre(models.Model):

_name = 'res.partner'

_inherit = ['res.partner']

def _get_latest_intervention(self, cr, uid, ids, field_name, args, context=None):

res = {}

obj_intervention = self.pool.get('c.intervention')

for interv in self.browse(cr, uid, ids, context=context):

intervention_ids = obj_intervention.search(cr, uid, [('centre_id', '=', intervention_id)], order='date_intv', context=context)

if intervention_ids:

res[intervention_id] = intervention_ids[-1:][0]

else:

res[intervention_id] = False

return res

rs_ctr = fields.Char(string='Réseau')

nb_ligne = fields.Integer(string='Lignes')

n_agr = fields.Integer(string='N° d\'agrèment')

chef = fields.Char(string='Chef centre')

prp = fields.Char(string='Propriétaire')

equipement_id = fields.Many2one('product.template','Equipements',select=True)

intervention_id = fields.Date(compute='_get_latest_intervention', type="Date", string='Derniére intervention')

  

properties1 = fields.One2many('product.template','centre_id','Centres')

centre()

class equipement(models.Model):

_name = 'product.template'

_inherit = ['product.template']

name = fields.Char(string='Nom')

num_ligne = fields.Integer(string='N° ligne')

model_mat = fields.Char(string='Model de materiel')

centre_id = fields.Many2one('res.partner','Centres',select=True)

properties2 = fields.One2many('c.maintenance','equipement_id','Equipements')

equipement()


class maintenance(models.Model):

_name = 'c.maintenance'

_description = 'Maintenance'

STATE_SELECTION = [('c','Corrective'),('p','Préventive')]

type_int = fields.Selection(STATE_SELECTION,'Type d\'intervention')

date_intv = fields.Date(string='Date d\'intervention')

equipement_id = fields.Many2one('product.template','Equipements',select=True)

intervention_id = fields.Many2one('c.intervention','Interventions',select=True)

maintenance()

class intervention(models.Model):

_name = 'c.intervention'

STATE_SELECTION = [('c','Corrective'),('p','Préventive')]

_description = 'Interventions'

_inherits = {'res.partner':'centre_id'}

_inherit = {'c.maintenance'}

name = fields.Char(string='Nom')

type_int = fields.Selection(STATE_SELECTION,'Type d\'intervention')

properties4 = fields.One2many('c.maintenance','intervention_id','Interventions')

centre_id = fields.Many2one('res.partner','Centres',select=True)

intervention()

what could be the right way to make this work please 

0
Avatar
Buang
Melvin

Is there anyway to record the intervention of a field in another field? like computing the field to store the intervention date of another field?

Avatar
Priyesh Solanki
Jawaban Terbai

Hi,

Did you define intervention_id as a function field in another object in which you want to see latest intervention ?

0
Avatar
Buang
amina
Penulis

no I definded field latest as the function field am I doing something wrong?

Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
function get latest date
python odoo9.0
Avatar
Avatar
1
Jan 16
4527
ir_attachment: IOError: [Errno 2] No such file or directory Diselesaikan
python ir_attachment odoo9.0
Avatar
Avatar
1
Agu 21
63349
How to mention all channel user in Discuss using shortcuts?
javascript python odoo9.0
Avatar
Avatar
1
Sep 20
5519
how to return value to javascript from python? Diselesaikan
javascript python odoo9.0
Avatar
Avatar
Avatar
Avatar
3
Apr 18
32344
How to get a value from json?
python json odoo9.0
Avatar
0
Jan 16
4828
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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