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 create and save my own Sale.Order model?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
sale.order.linesale.order12.
8974 Tampilan
Avatar
thanhps

Hi, 

I would like to copy and create my own new sale.order model and save data into a separate table in database. Therefore, I am using '_inherit' with '_name' in new model.

However, sale.order also include sale.order.line then I create my own new 'sale.order.line' as above.

When I tried to click Save button, I got the error below: 

-> raise TypeError("Mixing apples and oranges: %s - %s" % (self, other))

Here is my source code

class MyOrder(models.Model):
_name = "my.order"
_inherit = 'sale.order'
_description = "Sale Order"

order_line = fields.One2many('my.order.line', 'order_id', string='Order Lines',
states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True,
auto_join=True)
state = fields.Selection([
('draft', 'Draft'),
('sale', 'Sales Order'),
('done', 'Locked'),
('cancel', 'Cancelled'),
], string='Status', readonly=True, copy=False, index=True, track_visibility='onchange', track_sequence=3,
default='draft')

@api.model_cr
def init(self):
self._cr.execute("""
ALTER TABLE public.my_order ALTER COLUMN warehouse_id DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN picking_policy DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN partner_invoice_id DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN partner_shipping_id DROP NOT NULL;
ALTER TABLE public.my_order ALTER COLUMN team_group DROP NOT NULL;
""")

@api.model
def create(self, vals):
if vals.get('name', _('New')) == _('New'):
if 'company_id' in vals:
vals['name'] = self.env['ir.sequence'].with_context(force_company=vals['company_id']).next_by_code(
'my.order') or _('New')
else:
vals['name'] = self.env['ir.sequence'].next_by_code('my.order') or _('New')

# Makes sure 'pricelist_id' are defined
if any(f not in vals for f in ['pricelist_id']):
partner = self.env['res.partner'].browse(vals.get('partner_id'))
vals['pricelist_id'] = vals.setdefault('pricelist_id',
partner.property_product_pricelist and partner.property_product_pricelist.id)
# Change state of order to 'sale'
vals['state'] = 'sale'
vals['date_order'] = fields.Date.today()
return super(MyOrder, self).create(vals)

​
class MyOrderLine(models.Model):
_name = 'my.order.line'
_inherit = 'sale.order.line'
_description = 'Sales Order Line'

order_id = fields.Many2one('my.order', string='Order Reference', required=True, ondelete='cascade',
index=True,
copy=False)

state = fields.Selection([
('draft', 'Draft'),
('sale', 'Sales Order'),
('done', 'Done'),
('cancel', 'Cancelled'),
], related='order_id.state', string='Order Status', readonly=True, copy=False, store=True, default='draft')

@api.model_cr
def init(self):
self._cr.execute("""
ALTER TABLE public.my_order_line ALTER COLUMN customer_lead DROP NOT NULL;
""")

# Override for non-checking inventory
@api.onchange('product_uom_qty')
def _onchange_product_uom_qty(self):
return {}

# Override for non-checking inventory
@api.onchange('product_uom_qty', 'product_uom', 'route_id')
def _onchange_product_id_check_availability(self):
return {}


Thank you for your help!

0
Avatar
Buang
Niyas Raphy (Walnut Software Solutions)

Better you can use inherits the model sale.order such a way that while creating record it will get added in both models. By default in odoo, you will get example with the product.product model and product.template model.

In the product.product model there is a many2one relation to product.template model, and also product.product model is created using the _inherits

thanhps
Penulis

But it inherits only fields not methods, right?

I still want to use some compute methods in sale.order to compute price or total.

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
Merge Same Item in Sale Order Line Diselesaikan
sale.order.line sale.order
Avatar
Avatar
Avatar
2
Jan 24
6291
Combine inline editing with more detailed form view
sale.order.line sale.order
Avatar
0
Jun 23
2774
ValueError: <class 'ValueError'>: "Expected singleton: sale.order.line(<NewId ref='virtual_117'>, <NewId ref='virtual_131'>)"
sale.order.line sale.order
Avatar
Avatar
1
Des 22
4206
How to update a custom field as "Margin" default from sale.order does, when some product of sale.order.line is updated/deleted.
sale.order.line sale.order
Avatar
0
Apr 22
3229
How to get partner_id from sale.order.line? Diselesaikan
sale.order.line 12.
Avatar
Avatar
1
Jun 19
9535
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