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

Odoo13 How to add properly a constraint to an existing field in res.partner?

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
vatres.partnerres.company
3 Replies
11613 Tampilan
Avatar
Osiris

I added two many2one mandatory fields (taxid_type and taxpayer_type) to the Partner model. Just one of these is used in Company model(taxpayer_id).

I also created the _inverse_taxpayer method to syncronize the values from res.partner to res.company and inherited the create method from res.company to do the inverse syncronization.

Now I'm having a problem. The Vat field must be constrained in res.partner according to taxid_type when creating contacts type company. But this same field in res.company just must have a constraint, its length must be igual to 13. When I install the module and configure the vat in res.company form, I'm having the next error


File "/home/odoo/odoo13/extra-addons/custommodules/mymodule/models/partner.py", line 35, in check_vat
    if len(record.vat) < 13:
TypeError: object of type 'bool' has no len()


This is my partner.py module


class Partner(models.Model):
    _inherit = 'res.partner'

    taxid_type = fields.Many2one('lec.taxid.type', string='TaxID Type')
    taxpayer_type = fields.Many2one('lec.taxpayer.type', string='Tax Payer Type')

    @api.constrains('vat', 'taxid_type', 'taxpayer_type')
    def check_vat(self):
        for record in self:
            if len(record.vat) < 13:
                raise ValidationError('Tax id is minor than allowed partner')
            elif len(record.vat) > 13:
                raise ValidationError('Tax id is major than allowed')


And this is my company.py module

class Company(models.Model):
    _inherit = 'res.company'

    taxpayer_type = fields.Many2one('lec.taxpayer.type', related='partner_id.taxpayer_type', string='Tax Payer Type', compute='_compute_taxpayertype', inverse='_inverse_taxpayer')

    @api.constrains('vat')
    def check_vat(self):

        if len(self.vat) < 13:
            raise UserError('tax id is minor than allowed company')
        elif len(self.vat) > 13:
            raise UserError('tax id is major than allowed')
   
    #The next method returns the value inserted in res.partner to res.company and assign to the corresponding field
    def _inverse_taxpayer(self):
        for company in self:
            company.partner_id.taxpayer_type = company.taxpayer_type


    #The next method set the value inserted in res.company to res.partner and assign to the corresponding field
    # partner's contact payertype
    @api.model
    def create(self, vals):
        if not vals.get('name') or vals.get('partner_id'):
            self.clear_caches()
            return super(Company, self).create(vals)
        partner = self.env['res.partner'].create({
            'taxpayer_type': vals.get('taxpayer_type'),
        })
        # compute stored fields, for example address dependent fields
        partner.flush()
        vals['partner_id'] = partner.id
        self.clear_caches()
        company = super(Company, self).create(vals)
        return company

Does anyone know how can I solve this problem and achieve my objective

0
Avatar
Buang
Avatar
Niyas Raphy (Walnut Software Solutions)
Jawaban Terbai

Hi,

You are getting this error because as there is no value in the corresponding field. You can solve it by adding an IF condition in the code,

Error:

TypeError: object of type 'bool' has no len()

Solution:

if record.vat:
if len(record.vat) < 13:
raise ValidationError('Tax id is minor than allowed partner')
elif len(record.vat) > 13:
raise ValidationError('Tax id is major than allowed')

You can apply similar if condition in the other places too.


Thanks

0
Avatar
Buang
Osiris
Penulis

But with that approach, the field vat will not have a restriction of mandatory field. How can I make these fields mandatory only for company contact creation in res.partner?

Niyas Raphy (Walnut Software Solutions)

If you are saying you need to make it as required add and else condition to the first it and show warning that the value is required

Osiris
Penulis

The the problems comes again, when the user tries to setup the company configuration res.company the message will appear again because the vat in res.partner is empty.

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 can i detect partner created from company Diselesaikan
res.partner res.company
Avatar
Avatar
1
Nov 22
5305
Take the value in res.company (company_registry) in Odoo 15
res.partner company res.company
Avatar
Avatar
2
Okt 24
2630
How to add data to res.partner fields for multiple companies via API
res.partner res.user res.company company_id
Avatar
0
Des 20
6421
How to store the branches of a company in Odoo? Diselesaikan
res.partner branch res.company v12
Avatar
Avatar
Avatar
2
Des 19
8781
How to properly update one column value to be showed in another with fields.related?
fields res.partner fields.related res.company
Avatar
1
Okt 15
8625
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