Skip to Content
Odoo Menu
  • Zaloguj się
  • Wypróbuj za darmo
  • Aplikacje
    Finanse
    • Księgowość
    • Fakturowanie
    • Wydatki
    • Arkusz kalkulacyjny (BI)
    • Dokumenty
    • Podpisy
    Sprzedaż
    • CRM
    • Sprzedaż
    • PoS Sklep
    • PoS Restauracja
    • Subskrypcje
    • Wypożyczalnia
    Strony Internetowe
    • Kreator Stron Internetowych
    • eCommerce
    • Blog
    • Forum
    • Czat na Żywo
    • eLearning
    Łańcuch dostaw
    • Magazyn
    • Produkcja
    • PLM
    • Zakupy
    • Konserwacja
    • Jakość
    Zasoby Ludzkie
    • Pracownicy
    • Rekrutacja
    • Urlopy
    • Ocena pracy
    • Polecenia Pracownicze
    • Flota
    Marketing
    • Marketing Społecznościowy
    • E-mail Marketing
    • SMS Marketing
    • Wydarzenia
    • Automatyzacja Marketingu
    • Ankiety
    Usługi
    • Projekt
    • Ewidencja czasu pracy
    • Usługi Terenowe
    • Helpdesk
    • Planowanie
    • Spotkania
    Produktywność
    • Dyskusje
    • Zatwierdzenia
    • IoT
    • VoIP
    • Baza wiedzy
    • WhatsApp
    Aplikacje trzecich stron Studio Odoo Odoo Cloud Platform
  • Branże
    Sprzedaż detaliczna
    • Księgarnia
    • Sklep odzieżowy
    • Sklep meblowy
    • Sklep spożywczy
    • Sklep z narzędziami
    • Sklep z zabawkami
    Żywienie i hotelarstwo
    • Bar i Pub
    • Restauracja
    • Fast Food
    • Pensjonat
    • Dystrybutor napojów
    • Hotel
    Agencja nieruchomości
    • Agencja nieruchomości
    • Biuro architektoniczne
    • Budowa
    • Zarządzanie nieruchomościami
    • Ogrodnictwo
    • Stowarzyszenie właścicieli nieruchomości
    Doradztwo
    • Biuro księgowe
    • Partner Odoo
    • Agencja marketingowa
    • Kancelaria prawna
    • Agencja rekrutacyjna
    • Audyt i certyfikacja
    Produkcja
    • Tekstylia
    • Metal
    • Meble
    • Jedzenie
    • Browar
    • Prezenty firmowe
    Zdrowie & Fitness
    • Klub sportowy
    • Salon optyczny
    • Centrum fitness
    • Praktycy Wellness
    • Apteka
    • Salon fryzjerski
    Transakcje
    • Złota rączka
    • Wsparcie Sprzętu IT
    • Systemy energii słonecznej
    • Szewc
    • Firma sprzątająca
    • Usługi HVAC
    Inne
    • Organizacja non-profit
    • Agencja Środowiskowa
    • Wynajem billboardów
    • Fotografia
    • Leasing rowerów
    • Sprzedawca oprogramowania
    Przeglądaj wszystkie branże
  • Community
    Ucz się
    • Samouczki
    • Dokumentacja
    • Certyfikacje
    • Szkolenie
    • Blog
    • Podcast
    Pomóż w nauce innym
    • Program Edukacyjny
    • Scale Up! Gra biznesowa
    • Odwiedź Odoo
    Skorzystaj z oprogramowania
    • Pobierz
    • Porównaj edycje
    • Wydania
    Współpracuj
    • Github
    • Forum
    • Wydarzenia
    • Tłumaczenia
    • Zostań partnerem
    • Usługi dla partnerów
    • Zarejestruj swoją firmę rachunkową
    Skorzystaj z usług
    • Znajdź partnera
    • Znajdź księgowego
    • Spotkaj się z doradcą
    • Usługi wdrożenia
    • Opinie klientów
    • Wsparcie
    • Aktualizacje
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Zaplanuj demo
  • Cennik
  • Pomoc

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

  • CRM
  • e-Commerce
  • Księgowość
  • Zapasy
  • PoS
  • Projekt
  • MRP
All apps
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
Wszystkie posty Osoby Odznaki
Tagi (Zobacz wszystko)
odoo accounting v14 pos v15
O tym forum
Pomoc

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

Zaprenumeruj

Otrzymaj powiadomienie o aktywności w tym poście

To pytanie dostało ostrzeżenie
vatres.partnerres.company
3 Odpowiedzi
11620 Widoki
Awatar
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
Awatar
Odrzuć
Awatar
Niyas Raphy (Walnut Software Solutions)
Najlepsza odpowiedź

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
Awatar
Odrzuć
Osiris
Autor

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
Autor

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.

Podoba Ci się ta dyskusja? Dołącz do niej!

Stwórz konto dzisiaj, aby cieszyć się ekskluzywnymi funkcjami i wchodzić w interakcje z naszą wspaniałą społecznością!

Zarejestruj się
Powiązane posty Odpowiedzi Widoki Czynność
How can i detect partner created from company Rozwiązane
res.partner res.company
Awatar
Awatar
1
lis 22
5308
Take the value in res.company (company_registry) in Odoo 15
res.partner company res.company
Awatar
Awatar
2
paź 24
2632
How to add data to res.partner fields for multiple companies via API
res.partner res.user res.company company_id
Awatar
0
gru 20
6426
How to store the branches of a company in Odoo? Rozwiązane
res.partner branch res.company v12
Awatar
Awatar
Awatar
2
gru 19
8784
How to properly update one column value to be showed in another with fields.related?
fields res.partner fields.related res.company
Awatar
1
paź 15
8627
Społeczność
  • Samouczki
  • Dokumentacja
  • Forum
Open Source
  • Pobierz
  • Github
  • Runbot
  • Tłumaczenia
Usługi
  • Hosting Odoo.sh
  • Wsparcie
  • Aktualizacja
  • Indywidualne rozwiązania
  • Edukacja
  • Znajdź księgowego
  • Znajdź partnera
  • Zostań partnerem
O nas
  • Nasza firma
  • Zasoby marki
  • Skontaktuj się z nami
  • Oferty pracy
  • Wydarzenia
  • Podcast
  • Blog
  • Klienci
  • Informacje prawne • Prywatność
  • Bezpieczeństwo Odoo
الْعَرَبيّة 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 to pakiet aplikacji biznesowych typu open source, które zaspokoją wszystkie potrzeby Twojej firmy: CRM, eCommerce, księgowość, inwentaryzacja, punkt sprzedaży, zarządzanie projektami itp.

Unikalną wartością Odoo jest to, że jest jednocześnie bardzo łatwe w użyciu i w pełni zintegrowane.

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