Перейти к содержимому
Odoo Меню
  • Войти
  • Попробовать бесплатно
  • Модули
    Финансы
    • Бухгалтерия
    • Выставление счетов
    • Расходы
    • Таблицы
    • Документооборот
    • Подпись
    Продажи
    • CRM
    • Продажи
    • POS Магазин
    • POS Ресторан
    • Подписки
    • Аренда
    Вебсайты
    • Конструктор вебсайтов
    • eCommerce
    • Блог
    • Форум
    • Онлайн-чат
    • Электронное обучение
    Логистика
    • Склад
    • Производство
    • PLM
    • Закупки
    • Обслуживание
    • Качество
    Отдел кадров
    • Сотрудники
    • Подбор персонала
    • Отпуска
    • Оценка персонала
    • Реферальная программа
    • Автопарк
    Маркетинг
    • SMM
    • E-mail рассылки
    • СМС рассылки
    • Мероприятия
    • Автоматизация маркетинга
    • Опросы
    Услуги
    • Проекты
    • Табели
    • Выездной сервис
    • Поддержка
    • Планирование
    • Встречи
    Продуктивность
    • Обсуждения
    • Согласование
    • IoT
    • VoIP-телефония
    • Knowledge
    • WhatsApp
    Сторонние приложения Модуль Студия Odoo Платформа Odoo Cloud
  • Индустрии
    Розничная торговля
    • Книжный магазин
    • Магазин одежды
    • Мебельный магазин
    • Продуктовый магазин
    • Строительный магазин
    • Магазин игрушек
    Гостинично-ресторанный бизнес
    • Бар и паб
    • Ресторан
    • Фастфуд
    • Гостевой дом
    • Дистрибьютор напитков
    • Отель
    Недвижимость
    • Агентство недвижимости
    • Архитектурное бюро
    • Строительство
    • Управление недвижимостью
    • Ландшафтный дизайн
    • Товарищество собственников жилья
    Консалтинг
    • Бухгалтерская фирма
    • Партнер Odoo
    • Маркетинговое агентство
    • Юридическая фирма
    • Подбор персонала
    • Аудиторское бюро
    Производство
    • Текстиль
    • Металл
    • Мебель
    • Продукты питания
    • Пивоварня
    • Корпоративные сувениры
    Здоровье и фитнес
    • Спортивный комплекс
    • Магазин оптики
    • Фитнес-клуб
    • Велнес-центр
    • Аптека
    • Салон красоты
    Услуги
    • Специалист по бытовым услугам
    • Продажа и обслуживание IT-оборудования
    • Солнечные энергосистемы
    • Производство обуви
    • Клининг
    • Системы ОВКВ
    Прочее
    • Некоммерческая организация
    • Консалтинг в сфере устойчивого развития
    • Аренда рекламных щитов
    • Бизнес по фотосъемке
    • Прокат велосипедов
    • Реселлер программного обеспечения
    Все индустрии
  • Community
    Обучение
    • Видео уроки
    • Документация
    • Сертификация
    • Тренинг
    • Блог
    • Подкаст
    Образование и развитие
    • Образовательная программа
    • Деловая игра Scale Up!
    • Экскурсия в офис Odoo
    ПО
    • Скачать
    • Сравнить версии
    • Релизы
    Сотрудничество
    • Github
    • Форум
    • Мероприятия
    • Перевод
    • Стать партнером
    • Услуги для партнеров
    • Зарегистрировать бухгалтерскую фирму
    Услуги
    • Найти партнера
    • Найти бухгалтера
    • Встреча с экспертом
    • Услуги по внедрению
    • Отзывы клиентов
    • Поддержка
    • Обновления
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Заказать демонстрацию
  • Цены
  • Поддержка

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

  • CRM
  • e-Commerce
  • Бухгалтерия
  • Склад
  • PoS
  • Проекты
  • MRP
All apps
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Все посты Люди Значки
Теги (Смотреть все)
odoo accounting v14 pos v15
Об этом форуме
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Все посты Люди Значки
Теги (Смотреть все)
odoo accounting v14 pos v15
Об этом форуме
Помощь

How do I fix KeyError Using Vals?

Подписаться

Получайте уведомления о появлении активности в этом посте

Этот вопрос был отмечен
keyerror
1 Ответить
19414 Представления
Аватар
Ademola Oke

I have this code:

import time
from openerp.osv import fields, osv
import openerp.addons.decimal_precision as dp
from openerp.tools.translate import _    
from openerp.tools import hashlib       
from datetime import datetime          
from operator import itemgetter      
from openerp import SUPERUSER_ID
from openerp import pooler, tools
from dateutil.relativedelta import relativedelta

class account_bank_payment(osv.osv):
    _name = "account.bank.payment"
    _description = 'PayDirect Tax Payments'
    _inherit = 'account.bank.statement.line'
    _columns = {        
        'name': fields.char('Payment Reference', size=255, required=True),
        'date': fields.date('Payment Date', required=True),
        'amount': fields.float('Amount', digits_compute=dp.get_precision('Account'), required=True),                                                 
        'ref': fields.char('Description', size=255, required=True),    
        'taxpayer_name': fields.char('Tax Payer', size=255, required=True),
        'head_subhead': fields.char('Head/Sub-head', size=255, required=True), 
        'instr_number': fields.char('Print Paper Number', size=20), 
        'system_print_number': fields.char('System Print Number', size=20), 
        'bank_name': fields.char('Bank Name', size=255, required=True),     
        'payment_type': fields.char('Payment Type', size=255, required=True),
        'payment_logid': fields.integer('Payment Log Id'),                 
        'terminal_id': fields.char('Terminal Id', size=255),                 
        'channel_name': fields.char('Channel Name', size=255),
        'location': fields.char('Channel Name', size=255),                  
        'institution_id': fields.char('Institution Id', size=255),         
        'institution_name': fields.char('Institution', size=255),
        'branch_name': fields.char('Branch', size=255),   
        'receipt_no': fields.char('Receipt No', size=255),  
        'collections_account': fields.char('Collections Account', size=255),                                                          
        'bank_code': fields.char('Bank Code', size=255),   
        'is_reversal': fields.boolean('Is Reversal', help="Indicates whether the transactions is a reversal or not."),                                                          
        'deposit_slip_number': fields.char('Deposit Slip Number', size=255),              
        'period_covered': fields.char('Period Covered', size=255),  
        'period_covered_start': fields.date('Period Covered Start'),                                      
        'period_covered_end': fields.date('Period Covered End'),
        'val_date': fields.date('Value Date'),  
        'cust_reference': fields.char('Customer Reference', size=255),
        'alternate_cust_reference': fields.char('Alternate Customer Reference', size=255),
        'payment_status': fields.integer('Payment Status'),
        'settlement_date': fields.date('Settlement Date'),
        'fee_name': fields.char('Fee Name', size=255),
        'othercustomer_info': fields.char('Other Customer Info', size=255),
        'collections_account': fields.char('Collections Account', size=255),
        'third_party_code': fields.char('Thirty Party Code', size=255),
        'customer_address': fields.char('Customer Address', size=255),
        'customer_phone_number': fields.char('Customer Phone Number', size=255),
        'depositor_name': fields.char('Depositor Name', size=255),
        'payment_currency': fields.char('Payment Currency', size=255),
        'product_group_code': fields.char('Product Group Code', size=255),
        'transaction_date': fields.date('Transaction Date'),
        'item_amount': fields.float('Item Amount', digits_compute=dp.get_precision('Account')),
        'lead_bank_code': fields.char('Lead Bank Code', size=255),
        'lead_bank_cbn_code': fields.char('Lead Bank CBN Code', size=255),
        'lead_bank_name': fields.char('Lead Bank Name', size=255),
        'ip': fields.char('IP', size=255), 
        #dummy fields for date range
        'payment_date_from':fields.function(lambda *a,**k:{}, method=True, type='date',string="Payment date from"),
        'payment_date_to':fields.function(lambda *a,**k:{}, method=True, type='date',string="Payment date to"),           
        #'status': fields.selection([('ready', 'Ready'), ('printed', 'Printed'), ('issued', 'Issued'), ('request', 'Void Request')], 'State'),   
        'state': fields.selection([('ready', 'Ready'), ('printed', 'Printed'), ('issued', 'Issued'), ('request', 'Void Request'), ('voided', 'Voided')], 'Status'),    
        'wht_schedule_id': fields.one2many('collections.wht.schedule', 'payment_reference', 'WHT Schedule', select=False, required=False, ondelete='cascade'),       
        'partner_id': fields.many2one('res.partner', 'Internal Payer Name'),
        #override the following here to remove required constraint    
        'statement_id': fields.many2one('account.bank.statement', 'Statement',
            select=False, required=False, ondelete='cascade'),
        'type': fields.selection([ 
            ('taxpayer','Tax Payer'),
            ('supplier','Supplier'),
            ('customer','Customer'),
            ('general','General')
            ], 'Type', required=False),
        'account_id': fields.many2one('account.account','Account',
            required=False),          
    }
    _defaults = {
        #'status': 'ready', 
        'state': 'ready',
        'period_covered_start' : lambda *a : None, 
        'period_covered_end' : lambda *a : None,
    }
    _sql_constraints = [
#         ('name_unique', 'unique(name)', 'The payment reference must be unique per payment!'),
#         ('payment_logid_unique', 'unique(payment_logid)', 'The payment log id must be unique per payment!'),
#         ('terminal_id', 'unique(terminal_id)', 'The terminal id must be unique per payment!'), 
         ('instr_number', 'unique(instr_number)', 'The print paper number must be unique for each payment!'),
         ('system_print_number', 'unique(system_print_number)', 'The system print number must be unique for each payment!'),
    ]
    _order = "date desc"

    def unlink(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
#         if context.get('block_statement_line_delete', False):
#             raise osv.except_osv(_('Warning!'), _('Delete operation not allowed. \
#             Please go to the associated bank statement in order to delete and/or modify bank statement line.'))
        return super(account_bank_payment, self).unlink(cr, uid, ids, context=context)

    def set_ready(self, cr, uid, ids, context):
        self.write(cr, uid, ids, {'state': 'ready'}, context=context)
        return {}

    def set_printed(self, cr, uid, ids, context):
        for payment in self.browse(cr, uid, ids, context): 
            if not payment.instr_number:
                raise osv.except_osv(_('Warning!'), _('You must enter the print paper number before setting the status to printed.'))
            else:
                self.write(cr, uid, ids, {'state': 'printed'}, context=context)
        return {}

    def set_issued(self, cr, uid, ids, context):
        self.write(cr, uid, ids, {'state': 'issued'}, context=context)
        return {} 

    def set_request(self, cr, uid, ids, context):
        for payment in self.browse(cr, uid, ids, context): 
            if not payment.note:
                raise osv.except_osv(_('Warning!'), _('You must add a note to this payment before requesting it to be voided.'))
            else:
                self.write(cr, uid, ids, {'state': 'request'}, context=context)
        return {}   

    def set_voided(self, cr, uid, ids, context):
        self.write(cr, uid, ids, {'state': 'voided'}, context=context)
        return {} 

    def onchange_papernumber(self, cr, uid, ids, instr_number, context=None):
        if instr_number:
          hash = hashlib.sha1()
          hash.update(instr_number)
          self.write(cr, uid, ids, {'system_print_number': '89' + hash.hexdigest()[:12].upper()}, context=context)               
        return {}  

    def create(self, cr, uid, vals, context=None):         
#         if vals['period_covered_start'] and vals['period_covered_end']: 
#             if vals['period_covered_end'] < vals['period_covered_start']:
#                 raise osv.except_osv(_('Warning!'), _('End date cannot be earlier than start date.')) 
#         result = super(account_bank_payment,self).create(cr, uid, vals, context=context)             
        return result  

    def write(self, cr, uid, ids, vals, context=None):
      if uid != 15 and vals['head_subhead']:   
          raise osv.except_osv(_('Warning!'), _('End date cannot be earlier than start date.'))
#         if vals['period_covered_start'] and vals['period_covered_end']: 
#             if vals['period_covered_end'] < vals['period_covered_start']:
#                 raise osv.except_osv(_('Warning!'), _('End date cannot be earlier than start date.'))  
#         result = super(account_bank_payment,self).write(cr, uid, ids, vals, context=context)             
      return result  

    def onchange_period_covered(self, cr, uid, ids, period_covered_start, period_covered_end, context=None):
        if period_covered_start and period_covered_end: 
            if period_covered_end < period_covered_start:
                raise osv.except_osv(_('Warning!'), _('End date cannot be earlier than start date.'))               
        return {}

    def onchange_head(self, cr, uid, ids, context=None):
      if uid != 15:   
          raise osv.except_osv(_('Error!'), _('You are not allowed to edit this field.'))               
      return {}  

    def onchange_description(self, cr, uid, ids, context=None):
      if uid != 15:   
          raise osv.except_osv(_('Error!'), _('You are not allowed to edit this field.'))               
      return {}

account_bank_payment()


class paydirect_payment(osv.osv):
    _name = "payments"
    _description = 'PayDirect Raw Payment Records'
    _columns = {        
        'paymentreference': fields.char('Payment Reference', size=255),
        'paymentdate': fields.date('Payment Date'),
        'itemamount': fields.float('Amount', digits_compute=dp.get_precision('Account')),                                                 
        'itemname': fields.char('Description', size=255),    
        'customername': fields.char('Customer Name', size=255),
        'itemcode': fields.char('Head/Sub-head', size=255),  
        'bankname': fields.char('Bank Name', size=255),     
        'payment_type': fields.char('Payment Type', size=255),
        'paymentlogid': fields.integer('Payment Log Id'),                 
        'terminalid': fields.char('Terminal Id', size=255),                 
        'channelname': fields.char('Channel Name', size=255),
        'location': fields.char('Channel Name', size=255),                  
        'institutionid': fields.char('Institution Id', size=255),         
        'institutionname': fields.char('Institution', size=255),
        'branchname': fields.char('Branch', size=255),   
        'receiptno': fields.char('Receipt No', size=255),  
        'collectionsaccount': fields.char('Collections Account', size=255),                                                          
        'bankcode': fields.char('Bank Code', size=255),   
        'isreversal': fields.boolean('Is Reversal', help="Indicates whether the transactions is a reversal or not."),                                                          
        'depositslipnumber': fields.char('Deposit Slip Number', size=255),                
        'custreference': fields.char('Customer Reference', size=255),
        'alternatecustreference': fields.char('Alternate Customer Reference', size=255),
        'paymentstatus': fields.integer('Payment Status'),
        'settlementdate': fields.date('Settlement Date'),
        'feename': fields.char('Fee Name', size=255),
        'othercustomerinfo': fields.char('Other Customer Info', size=255),
        'collectionsaccount': fields.char('Collections Account', size=255),
        'thirdpartycode': fields.char('Thirty Party Code', size=255),
        'customeraddress': fields.char('Customer Address', size=255),
        'customerphonenumber': fields.char('Customer Phone Number', size=255),
        'depositorname': fields.char('Depositor Name', size=255),
        'paymentcurrency': fields.char('Payment Currency', size=255),
        'productgroupcode': fields.char('Product Group Code', size=255),
        'transactiondate': fields.date('Transaction Date'),
        'itemamount': fields.float('Item Amount', digits_compute=dp.get_precision('Account')),
        'leadbankcode': fields.char('Lead Bank Code', size=255),
        'leadbankcbncode': fields.char('Lead Bank CBN Code', size=255),
        'leadbankname': fields.char('Lead Bank Name', size=255),
        'ip': fields.char('IP', size=255),          
    }
    _order = "paymentdate desc"

paydirect_payment()

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

When I try to edit a record and save, I get this error:

    Client Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\web\http.py", line 204, in dispatch
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\web\controllers\main.py", line 1125, in call_kw
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\web\controllers\main.py", line 1117, in _call_kw
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\web\session.py", line 42, in proxy
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\web\session.py", line 30, in proxy_method
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\web\session.py", line 103, in send


Server Traceback (most recent call last):
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\web\session.py", line 89, in send
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\.\openerp\netsvc.py", line 292, in dispatch_rpc
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\.\openerp\service\web_services.py", line 626, in dispatch
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\.\openerp\osv\osv.py", line 188, in execute_kw
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\.\openerp\osv\osv.py", line 131, in wrapper
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\.\openerp\osv\osv.py", line 197, in execute
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\.\openerp\osv\osv.py", line 185, in execute_cr
  File "C:\Program Files (x86)\OpenERP 7.0\Server\server\openerp\addons\account_collections\account_bank_payment.py", line 169, in write
KeyError: 'head_subhead'

Can someone help identify my error?

Thanks in advance.

0
Аватар
Отменить
Аватар
nazarii
Лучший ответ

You simply need to change if uid != 15 and vals['head_subhead']: to if uid != 15 and vals.get('head_subhead'):. Explanations are here.

0
Аватар
Отменить
Ademola Oke
Автор

Thank you. That definitely solved the problem. I copied that syntax from an existing module so I was surprised that it didn't work. Any ideas on why their syntax worked and mine didn't?

nazarii

I can't see reason why do we need to update value of this field each time we change the other one. In my opinion get() must be used everywhere in the code unless field value is required to populate each time in the vals.

Laura Jarvenpaa

@Faiyer: The reason why you get key error is that when python tries to get vals['head_subhead'] it doesn't find it from your dictionary so it throws keyerror exception, with vals.get('head_subhead') if key is not found it returns none if it doesn't find head_subhead not an exception. I would assume that in that other code they caught the keyerror exception somewhere so it didn't crash but you don't catch it anywhere so it crashes.

Ademola Oke
Автор

@Laura: Thanks. @nazarii: Can you explain more detail in your comment?

Не оставайтесь в стороне – присоединяйтесь к обсуждению!

Создайте аккаунт сегодня, чтобы получить доступ к эксклюзивным функциям и стать частью нашего замечательного сообщества!

Регистрация
Похожие посты Ответы Просмотры Активность
KeyError: line_ids after removing a One2many from a custom model (want to cleanly remove without uninstall)
keyerror
Аватар
0
авг. 25
933
odoo module update not updating fully resulting in key value error
keyerror
Аватар
0
нояб. 23
2480
KeyError: 'socket' Решено
keyerror
Аватар
Аватар
Аватар
2
апр. 25
9298
Why is KeyError: 'teacher_id' ? Решено
keyerror
Аватар
Аватар
Аватар
6
сент. 21
24490
Odoo 11 model registry loses model
keyerror
Аватар
Аватар
4
апр. 19
5719
Сообщество
  • Видео уроки
  • Документация
  • Форум
Открытый исходный код
  • Скачать
  • Github
  • Runbot
  • Перевод
Услуги
  • Хостинг Odoo.sh
  • Поддержка
  • Обновление
  • Индивидуальные решения по доработке
  • Образование
  • Найти бухгалтера
  • Найти партнера
  • Стать партнером
О нас
  • Наша компания
  • Активы бренда
  • Cвяжитесь с нами
  • Вакансии
  • Мероприятия
  • Подкаст
  • Блог
  • Клиенты
  • Правовые документы • Конфиденциальность
  • Безопасность
الْعَرَبيّة 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 – это набор бизнес-модулей с открытым исходным кодом, который закроет все потребности вашей компании: CRM, E-commerce, Бухгалтерия, Склад, POS, управление проектами и др.

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