Pular para o conteúdo
Odoo Menu
  • Sign In
  • Experimente gratuitamente
  • Aplicações
    Finanças
    • Contabilidade
    • Faturação
    • Despesas
    • Assinatura eletrónica
    • Folha de cálculo
    • ESG
    Vendas
    • CRM
    • Vendas
    • Subscrições
    • POS para lojas
    • POS para restaurantes
    • Aluguer
    Website
    • Criador de sites
    • Comércio eletrónico
    • Eventos
    • Blogue
    • e-Learning
    • Fórum
    Cadeia de abastecimento
    • Inventário
    • Produção
    • Manutenção
    • PLM
    • Qualidade
    • Compras
    Recursos Humanos
    • Colaboradores
    • Folha de pagamento
    • Recrutamento
    • Ausências
    • Avaliações
    • Frota
    Marketing
    • Marketing social
    • Marketing por e-mail
    • Marketing através de SMS
    • Automação de Marketing
    • WhatsApp
    • Inquéritos
    Serviços
    • Projeto
    • Folhas de horas
    • Planeamento
    • Marcações
    • Chat em direto
    • Assistência
    Produtividade
    • Inteligência artificial
    • Conversas
    • VoIP
    • IoT
    • Documentos
    • Informação
    Aplicações de terceiros Odoo Studio Plataforma Odoo Cloud
  • Setores
    Retalho
    • Livraria
    • Loja de roupa
    • Loja de móveis
    • Mercearia
    • Loja de ferragens
    • Loja de brinquedos
    Alimentação e hotelaria
    • Bar e pub
    • Restaurante
    • Comida rápida
    • Casa de hóspedes
    • Distribuidor de bebidas
    • Hotel
    Imobiliário
    • Agência imobiliária
    • Gabinete de arquitectura
    • Construção
    • Gestão imobiliária
    • Jardinagem
    • Associação de proprietários
    Consultoria
    • Gabinete de contabilidade
    • Parceiro da Odoo
    • Agência de marketing
    • Escritório de advogados
    • Aquisição de talentos
    • Auditoria e certificação
    Produção
    • Têxtil
    • Metal
    • Móveis
    • Alimentação
    • Cervejaria
    • Brindes promocionais
    Saúde e bem-estar
    • Clube desportivo
    • Ótica
    • Ginásio
    • Profissionais de bem-estar
    • Farmácia
    • Cabeleireiro
    Ofícios
    • Handyman
    • Hardware e suporte técnico
    • Sistemas de energia solar
    • Loja de eletrónica
    • Serviços de limpeza
    • Serviços de climatização
    Outros
    • Organização sem fins lucrativos
    • Agência do ambiente
    • Aluguer de painéis publicitários
    • Estúdio de fotografia
    • Aluguer de bicicletas
    • Revendedor de software
    Veja todos os setores ⟶
  • Comunidade
    Aprender
    • Tutoriais
    • Documentação
    • Certificações
    • Formação
    • Blogue
    • Podcast
    Capacitar a educação
    • Programa de formação
    • Scale Up! O jogo de negócios
    • Visite a Odoo
    Obter o software
    • Transferir
    • Comparar edições
    • Versões
    Colaborar
    • Github
    • Fórum
    • Eventos
    • Traduções
    • Torne-se um parceiro
    • Serviços para parceiros
    • Registe a sua empresa contabilística
    • Programa de afiliados
    Obter serviços
    • Encontre um parceiro
    • Encontre um contabilista
    • Contacte um consultor
    • Serviços de implementação
    • Referências de clientes
    • Apoio
    • Atualizações
    GitHub YouTube X LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar uma demonstração
  • Preços
  • Ajuda
You need to be registered to interact with the community.
All Posts People Badges
Etiquetas (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetas (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Singleton error

Subscrever

Get notified when there's activity on this post

This question has been flagged
singletonv14
2 Respostas
4543 Vistas
Avatar
Denny
Hi, i encountered raise ValueError("Expected singleton: %s" % self) when computing age and working time
How to fix it

#computing age
@api.depends('tanggal_lahir')
def _hitung_usia(self):
if self.tanggal_lahir is not False:
self.usia = (datetime.today().date() - datetime.strptime(str(self.tanggal_lahir),'%Y-%m-%d').date()) // timedelta(days=365)

#computing working time
@api.depends('mulai_bekerja')
# @api.multi
def _lama_bekerja(self):
if self.mulai_bekerja:
years = relativedelta(date.today(), self.mulai_bekerja).years
months = relativedelta(date.today(), self.mulai_bekerja).months
day = relativedelta(date.today(), self.mulai_bekerja).days
self.lama_bekerja = str(int(years)) + ' Tahun ' + str(int(months)) + ' Bulan ' + str(day) + ' Hari'


0
Avatar
Descartar
Niyas Raphy

watch this to understand why singleton error appears: https://www.youtube.com/watch?v=Rv44nFVn_5U

Avatar
Malay Khamar
Best Answer

Hi Denny,

Please try to use a for loop in the function. 
Like:

#computing age
@api.depends('birth_date')
def _count_age(self):
for record in self:
if record.date_birth is not False:
record.age = (datetime.today().date() - datetime.strptime(str(record.date_birth),'%Y-%m-%d').date()) // timedelta(days=365)
else:
record.age = 0.0

#computing working time
@api.depends('start_work')
# @api.multi
def _long_work(self):
for record in self:
if record.start_work:
years = relativedelta(date.today(), record.start_work).years
months = relativedelta(date.today(), record.start_work).months
day = relativedelta(date.today(), record.start_work).days
record.work_long = str(int(years)) + ' Year ' + str(int(months)) + ' Month ' + str(day) + ' Day'
else:
record.work_long = '0 Year 0 Month 0 Day'



Hope it will help you.
Thanks and Vote up please.
3

Subscrever

Avatar
Descartar
Avatar
John Gaitho
Best Answer

Hi Denny,

Singleton error occurs when you call self.some_field where self is a collection of records.  Instead, you should loop through the records like this;

for rec in self:

    rec.some_field = ...

1

Subscrever

Avatar
Descartar
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Inscrever-se
Related Posts Respostas Vistas Atividade
Get Reminder Email for An Activity on a PO (v14) Solved
v14
Avatar
Avatar
2
jul. 26
5549
In user settings access group check box changed to list view how can i change back it to checkbox
v14
Avatar
Avatar
Avatar
Avatar
3
jun. 26
8450
How to sort a pivot table based on time
v14
Avatar
Avatar
1
jun. 26
5049
How to create Approval - V14
v14
Avatar
1
abr. 26
5458
Attached PDF file is not formatted properly
v14
Avatar
Avatar
1
dez. 25
4698
Comunidade
  • Tutoriais
  • Documentação
  • Fórum
Código aberto
  • Transferir
  • Github
  • Runbot
  • Traduções
Serviços
  • Alojamento Odoo.sh
  • Apoio
  • Atualizar
  • Desenvolvimentos personalizados
  • Educação
  • Encontre um contabilista
  • Encontre um parceiro
  • Torne-se um parceiro
Sobre nós
  • A nossa empresa
  • Ativos da marca
  • Contacte-nos
  • Junte-se à Odoo
  • Eventos
  • Podcast
  • Blogue
  • Clientes
  • Legal • Privacidade
  • Segurança
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) Português română русский язык Slovenský jazyk Slovenščina Español (América Latina) Español Svenska ภาษาไทย Türkçe українська Tiếng Việt

O Odoo é um conjunto de aplicações empresariais de código aberto que abrange todas as necessidades da sua empresa: CRM, comércio eletrónico, contabilidade, gestão de inventário, ponto de venda, gestão de projetos, etc.

A proposta de valor única do Odoo é ser, ao mesmo tempo, muito fácil de utilizar e totalmente integrado.

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