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
    • Discuss
    • 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

Create a new record in different model

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
automatedactionscustomupdaterecord
10 Replies
16654 Tampilan
Avatar
Dominic Anyanna

Hello 

i have the following models . i would like to create a new record in model b once the state of record a switches to unit manager approved . i was able to achieve that with automated actions but dont know how to bring the parts from model a_lines to model b_lines . i would appreciate any pointers 

model a 


class ServiceRequest(models.Model):
_name = 'servicerequest.rider'
_rec_name = 'jobcard_no'
_inherit = ['mail.thread', 'mail.activity.mixin']

    vehicle_id = fields.Many2one('vehicles.rider')
    state = fields.Selection(string="", selection=[('check-in', 'check-in'), ('Technician service completed', 'Technician service completed'), ('Unit Manager parts approved', 'Unit Manager parts approved'), ('store officer parts released', 'store officer parts released'), ('Unit manager quality check', 'Unit manager quality checked'), ('Checked out', 'Checked out'), ], default='check-in', required=False, track_visibility=True, trace_visibility='onchange', )
    jobcard_no = fields.Char(string="Jobcard Number",
default=lambda self: self.env['ir.sequence'].next_by_code('increment_jobcard'),
requires=False, readonly=True, )
    operations = fields.One2many('jobcard.partsline', 'servicerequest_id', 'Parts',
                     copy=True, readonly=True, states={'check-in': [('readonly', False)]})

@api.multi
def write(self, vals):
if vals.get('state'):
if vals.get('state') == 'Confirm':
lines_dict = {
'jobcard_id': self.id,
'operations': [(6, 0, self.operations.parts_id.ids)],
}
self.env['fundrequestw.rider'].create(lines_dict)
return super(ServiceRequest, self).write(vals)




Model a_lines


class JobcardParts(models.Model):
_name = 'jobcard.partsline'

_description = 'Parts Required used'

name = fields.Text(string='Description', required=False)
servicerequest_id = fields.Many2one(comodel_name="servicerequest.rider", index=True, ondelete='cascade')
parts_id = fields.Many2one('product.product', string='Parts',
ondelete='restrict', index=True)
quantity = fields.Integer(string="Quantity", required=False, )


model b 


class FundRequestWorkshop(models.Model):
_name = 'fundrequestw.rider'
_rec_name = 'request_no'
_inherit = ['mail.thread']


_description = 'Fund request workshop'

date = fields.Date(string="Date", default=date.today(), required=False, readonly=True, states={'draft': [('readonly', False)]})
request_no = fields.Char(string="Request Number", default=lambda self: self.env['ir.sequence'].next_by_code('increment_fund_request'), requires=False, readonly=True, trace_visibility='onchange',)
programme_id = fields.Many2one(comodel_name="programme.rider", string="Programme ID", required=False, readonly=True, states={'draft': [('readonly', False)]})
jobcard_id = fields.Many2one(comodel_name="servicerequest.rider", string="Job Card ref", required=False, readonly=True, states={'draft': [('readonly', False)]})
state = fields.Selection(string="", selection=[('draft', 'draft'), ('Requested', 'Requested'), ('Approved', 'Approved'), ('Rejected', 'Rejected'),], required=False, copy=False, default='draft', readonly=True, track_visibility='onchange', )
operations = fields.One2many(
'jobcard.partsline', 'fundrequest_id', 'Parts',
copy=True, readonly=True, states={'draft': [('readonly', False)]},)
part_qty = fields.Float(string="Quantity", required=False, )


Model b_lines


class FundrequestLine(models.Model):
_name = 'fundrequest.partsline'

_description = 'Parts request line'

name = fields.Text(string='Description', required=False)
fundrequest_id = fields.Many2one(comodel_name="fundrequestw.rider", index=True, ondelete='cascade')
parts_id = fields.Many2one('product.product', string='Parts',
ondelete='restrict', index=True)
0
Avatar
Buang
Avatar
Samo Arko
Jawaban Terbai

In model a you'll need to overide the write method and there check the state and then create the record in model b.

@api.multi
def write(self, vals):
if vals.get('state'):
if vals.get('state') == 'Unit Manager parts approved'     # you should really use something shorter 
lines_dict # here get the lines that you want in a dict formatted for creating record in model b lines
self.env['fundrequest.partsline'].create(lines_dict) # here you pass the dict with vals that you want

return super(ServiceRequest, self).write(vals)
1
Avatar
Buang
Samo Arko

sorry I don't know how to use this new WYSIWYG editor. So that's why the code looks so bad.

Yenthe Van Ginneken (Mainframe Monkey)

Why not use an onchange on the state field and just do a self.env['your.model'].create() though?

Dominic Anyanna
Penulis

Thank You for your answer . i have followed your advice but i now have an error (ValueError: Expected singleton: jobcard.partsline(25, 26) )

Samo Arko

That's because you're passing more than one record. You're passing the records with id 25 and 26. You need to pass them one by one. I don't know where this happens but try to do that line with "for rec in self:" (iterate the records one by one in the recordset) and call the method on rec and not on self. Living a like also helps :)

Dominic Anyanna
Penulis

Please can you help me with a sample code based on earlier example

Samo Arko

I can't because I don't know on what line it throws this error and what are you doing on that line. You're probably calling a method with the self parameter. so the only help I can offer you is like I wrote in the earlier comment you need to use a for loop to iterate trough the objects.

for rec in self:

rec.the_method_that_throws_error()

But I don't know if that's the problem or something else. Edit your question with the code that throws the error.

Dominic Anyanna
Penulis

I have edited the question to include the code

Samo Arko

I think this line is wrong "'operations': [(6, 0, self.operations.parts_id.ids)]," it needs to be 'operations': [(0, 0, {vals_dict1}), (0, 0, {vals_dict2}), ...]. I normally use (6, 0, [ids]) on many2many fields not one2many. But I might be wrong.

Avatar
admin@marutinandanconstruction.in
Jawaban Terbai

Did you solve the issue?

0
Avatar
Buang
Dominic Anyanna
Penulis

yes

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
How do I emulate automated actions via writing a custom module?
action module automated actions custom
Avatar
0
Okt 23
1853
Code automated actions for custom Sale Order sequences in Odoo 12
automated actions
Avatar
Avatar
1
Feb 21
5449
Automated Actions : Created Product Name automatically and internal reference automatically
automated actions
Avatar
Avatar
3
Jun 20
5986
Automated actions - creating directories (v13)
automated actions
Avatar
0
Jun 20
3597
How to set automated action to inactive a user on cretin date ?
automated actions
Avatar
0
Feb 16
4741
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