跳至內容
Odoo 選單
  • 登入
  • 免費試用
  • 應用程式
    財政
    • 會計
    • 發票
    • 開支報銷
    • 試算表 (BI)
    • 文件管理
    • 電子簽名
    銷售
    • 客戶關係
    • 銷售
    • POS 銷售點管理 - 零售
    • POS 銷售點管理 - 餐廳
    • 訂閱
    • 租賃
    網站
    • 網站製作
    • 電子商務
    • 網誌
    • 討論區
    • 線上客服
    • 網上學習
    供應鏈
    • 庫存
    • 製造管理
    • 產品生命周期
    • 採購
    • 保養維護
    • 品質管理
    人力資源
    • 員工管理
    • 招聘
    • 休假
    • 工作表現評核
    • 內部推薦
    • 車隊管理
    市場推廣
    • 社交媒體推廣
    • 電郵推廣
    • 短訊營銷
    • 活動
    • 自動化推廣
    • 網上調查
    服務
    • 專案管理
    • 工時管理
    • 外勤服務管理
    • 技術支援
    • 工作規劃
    • 預約管理
    生產力
    • 聊天
    • 批核
    • 物聯網
    • VoIP
    • 知識庫
    • WhatsApp
    第三方應用程式 Odoo Studio Odoo 雲端平台
  • 行業
    零售
    • 書店
    • 服裝店
    • 家具店
    • 食品雜貨店
    • 五金店
    • 玩具店
    餐飲及款待
    • 酒吧及酒館
    • 餐廳
    • 快餐
    • 賓館
    • 飲品分銷商
    • 酒店
    房地產
    • 地產代理公司
    • 建築師事務所
    • 建造業
    • 物業管理
    • 園藝
    • 業主聯會
    顧問服務
    • 會計公司
    • Odoo 合作夥伴
    • 市場推廣公司
    • 律師事務所
    • 人才招募
    • 審計及認證
    製造管理
    • 紡織
    • 金屬
    • 家具
    • 食品
    • 啤酒廠
    • 企業禮品
    保健與健身
    • 運動俱樂部
    • 眼鏡店
    • 健身中心
    • 健康從業人員
    • 藥房
    • 髮型屋
    技術行業
    • 雜工
    • IT 硬體與支援
    • 太陽能系統
    • 鞋匠
    • 清潔服務
    • 暖通空調服務
    其他
    • 非牟利組織
    • 環境保護機構
    • 廣告板租賃
    • 攝影服務
    • 自行車租賃
    • 軟體經銷商
    瀏覽所有行業
  • 社群
    學習
    • 教學影片
    • 使用說明
    • 認證
    • 培訓
    • 網誌
    • Podcast
    增強教學效能
    • 教育計劃
    • 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:

  • 客戶關係
  • e-Commerce
  • 會計
  • 庫存
  • PoS
  • 專案管理
  • MRP
All apps
只限註冊用戶才可與社群互動。
所有帖文 人 獎章
標籤 (查看所有)
odoo accounting v14 pos v15
關於此討論區
只限註冊用戶才可與社群互動。
所有帖文 人 獎章
標籤 (查看所有)
odoo accounting v14 pos v15
關於此討論區
支援

Why am I getting a mandatory field is not correctly error on this extended contracts code?

訂閱

此帖文有活動時,接收通知

此問題已被標幟
inheritanceintegrityerrorcontractsodoo8.0
20 回覆
19109 瀏覽次數
頭像
Yenthe Van Ginneken (Mainframe Monkey)

Hi guys,

I've been extending the contracts from the sales module so that you can create contracts for cars (linking to fleet.vehicle). I've added the following fields to the model account.analytic.invoice.line:

class account_analytic_invoice_line(osv.osv): _inherit = 'account.analytic.invoice.line' _columns = { 'car_id': fields.many2one('fleet.vehicle', 'Car'), 'analytic_car_account_id': fields.many2one('account.analytic.account', 'Analytic Account 2'), 'car_license_plate': fields.text('Nummerplaat'), 'car_mavirent_nummer': fields.text('MaviRent nummer'), 'car_chassis': fields.text('Chassis'), 'car_rent_price': fields.float('Prijs'), 'car_number_of_units': fields.integer('Aantal'), 'car_line_tax_id': fields.many2many('account.tax', 'account_car_line_tax', 'car_line_id', 'tax_id', string='BTW', required=True), 'car_account_id': fields.many2one('account.account', 'Grootboekrekening', required=True), }


Then in the contract view I've added a new one2many (the field recurring_invoice_car_line_ids) like this:

<openerp> <data> <record id="view_contract_form_inherit_be_trans" model="ir.ui.view"> <field name="name">account.analytic.account.inherit</field> <field name="model">account.analytic.account</field> <field name="inherit_id" ref="account_analytic_analysis.account_analytic_account_form_form"/> <field name="arch" type="xml"> <xpath expr="//field[@name='recurring_invoice_line_ids']" position="after"> <label for="recurring_invoice_car_line_ids" attrs="{'invisible': [('recurring_invoices','=',False)]}"/> <div attrs="{'invisible': [('recurring_invoices','=',False)]}"> <field name="recurring_invoice_car_line_ids"> <tree string="Account Analytic Lines" editable="bottom"> <field name="car_id" on_change="car_id_change(car_id, car_license_plate, car_mavirent_nummer, car_chassis, car_rent_price)" attrs="{'required':[('car_id', '!=', '')]}"/> <!--These fields are only required when there is a value in the many2one field product_id' --> <field name="car_mavirent_nummer" attrs="{'required':[('car_id', '!=', '')]}"/> <field name="car_license_plate" attrs="{'required':[('car_id', '!=', '')]}"/> <field name="car_chassis" attrs="{'required':[('car_id', '!=', '')]}"/>

<field name="car_rent_price" attrs="{'required':[('car_id', '!=', '')]}"/> <field name="car_number_of_units" attrs="{'required':[('car_id', '!=', '')]}"/> <field name="car_line_tax_id" widget="many2many_tags"/> <field name="car_account_id"/> </tree> </field> </div> </xpath> </field> </record> </data> </openerp>

Now when a record is added on this one2many a Python function (on change event) named 'car_id_change' will go off which has the following code:

def car_id_change(self, cr, uid, ids, car, car_id=None,car_name='', car_license_plate='', car_mavirent_nummer='', car_chassis='', car_rent_price=0.0,car_number_of_units=1.0, context=None): context = context or {} local_context = dict(context, car_id=car_id) result = {} if not car: return {'value': {'car_name': '', 'car_license_plate': '', car_mavirent_nummer: '', car_chassis: '','car_rent_price': 0.0, 'car_number_of_units': 1.0}} else: res = self.pool.get('fleet.vehicle').browse(cr, uid, car, context=local_context) if res['license_plate']: car_license_plate = res['license_plate'] if res['name']: car_name = res['name'] if res['MaviVoertuigNummer']: car_mavirent_nummer = res['MaviVoertuigNummer'] if res['Chassis']: car_chassis = res['Chassis'] #Get a tax to automatically add to the contract. btw_categ_pool = self.pool.get('account.tax') goede_btw_id = btw_categ_pool.search(cr, uid, [('description','=','VAT-OUT-21-S')]) result.update({'car_name': car_name,'car_license_plate': car_license_plate, 'car_mavirent_nummer': car_mavirent_nummer, 'car_chassis': car_chassis, 'car_rent_price': car_rent_price, 'car_number_of_units': car_number_of_units, 'car_line_tax_id': [(6, 0, goede_btw_id)]}) res_final = {'value':result} return res_final

Which works fine. I can choose cars and all the data is filled in automatically (atleast, which I can).
When I now click on save I get an error though:

Integrity Error

The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set [object with reference: name - name]

When I look in the terminal I will see the following:

openerp.sql_db: bad query: INSERT INTO "account_analytic_invoice_line" ("id", "car_mavirent_nummer", "car_license_plate", "car_account_id", "car_number_of_units", "car_chassis", "analytic_car_account_id", "car_rent_price", "car_id", "quantity", "create_uid", "write_uid", "create_date", "write_date") VALUES(nextval('account_analytic_invoice_line_id_seq'), 'MAV09', 'FFF-111', 819, 1, 'OPO06', 13, 0.0, 2, 1.0, 1, 1, (now() at time zone 'UTC'), (now() at time zone 'UTC')) RETURNING id

Traceback (most recent call last): File "/odoo/odoo-server/openerp/sql_db.py", line 234, in execute res = self._obj.execute(query, params) IntegrityError: null value in column "name" violates not-null constraint DETAIL: Failing row contains (27, null, 1, 2016-01-13 08:48:12.818483, null, null, 1, null, 2016-01-13 08:48:12.818483, 1, null, MAV09, 13, FFF-111, 1, OPO06, 819, 0, 2).


I do see there is a null value in the SQL statement and I know that is not allowed but what I don't know is where it is coming from or what I am missing that it is giving null. I'm passing along all the values if I'm not mistaking? So, how do I fix this?

Update: The error was coming from the fact that I didn't inherit the module 'account', I did inherit 'account_analytic_analysis' but not 'account'. I now have a new issue:

Integrity Error The operation cannot be completed, probably due to the following: - deletion: you may be trying to delete a record while other records still reference it - creation/update: a mandatory field is not correctly set [object with reference: price_unit - price.unit]


You can view and test the whole module, which is available on Github: https://github.com/Yenthe666/Dev/tree/master/aa_maatwerk_be_trans

Thanks,
Yenthe

2
頭像
捨棄
Temur

what are steps to reproduce for an updated issue?

Yenthe Van Ginneken (Mainframe Monkey)
作者

@Temur go to sales > contracts, create a new contract and add one car and no products. Then click on save, you will get a notification saying that a field is missing. When you click on save again you will get the error.

Axel Mendoza

not solved yet?

Yenthe Van Ginneken (Mainframe Monkey)
作者

@Axel sadly no! I can't find the problem in the code.

Temur

Ok. I reproduced it

Temur

@Yenthe, I traced down the error and applied quick fix to be able to save contract according of steps to reproduce above. Please refer to updated answer and adapt solution further to meet your requirements.

Yenthe Van Ginneken (Mainframe Monkey)
作者

@Temur perfect! That was exactly what I was looking for. I'll need some minor changes to have everything perfect but my problem is fixed now. Thanks a lot! Accepted & upvoted! :)

頭像
Temur
最佳答案

Try it please:

....
    goede_btw_id = btw_categ_pool.search(cr, uid, [('description','=','VAT-OUT-21-S')])
    if type(goede_btw_id) in (long, int,):
        browse_ids = [goede_btw_id]
    else:
        browse_ids = goede_btw_id
    for godie_btw_obj in btw_categ_pool.browse(cr, uid, browse_ids, context=context):
        if not goede_btw_obj.name:
            goede_btw_obj.name = goede_btw_obj.description
    result.update({'car_name': car_name,'car_license_plate': car_license_plate, 'car_mavirent_nummer': car_mavirent_nummer, 'car_chassis': car_chassis, 'car_rent_price': car_rent_price, 'car_number_of_units': car_number_of_units, 'car_line_tax_id': [(6, 0, goede_btw_id)]})
....


UPDATE:

'account' is in dependency list, but I've got "IntegrityError: null value in column "name" violates not-null constraint" anyway. this error were originated from missing mandatory field "name" in "account_analytic_invoice_line" object, I fixed it in place by replacing required=True to required=False... I.e. if it meant not to be required, it should be fixed as follows:


class account_analytic_invoice_line(models.Model):
    _inherit = "account.analytic.invoice.line"

name = fields.Text(required=False) 

this way "IntegrityError: null value in column "name" violates not-null constraint" error is gone away, as we made it not mandatory field by required=False incremental update.


But I've got next error, same as in question post: "IntegrityError: null value in column "price_unit" violates not-null constraint". This error were originated from "price_unit" field set as mandatory but not displayed in a form view. here we can apply two solutions, either add back to the view all mandatory fields, or make them not mandatory same as for the "name" field above. Then I've got more errors of same kind: "IntegrityError: null value in column "uom_id" violates not-null constraint", followed by: "IntegrityError: null value in column "product_id" violates not-null constraint"...  Just as a quick fix I've added this fields back to the Form View and finally I was able to save the contract without errors. Here is an xml with mandatory fields in place:


<record id="view_contract_form_inherit_be_trans" model="ir.ui.view">
<field name="name">account.analytic.account.inherit</field>
<field name="model">account.analytic.account</field>
<field name="inherit_id" ref="account_analytic_analysis.account_analytic_account_form_form"/>
<field name="arch" type="xml">
<!-- Make the date fields required -->
<xpath expr="//field[@name='date_start']" position="replace">
<field name="date_start" required="True"/>
</xpath>
<xpath expr="//field[@name='date']" position="replace">
<field name="date" required="True"/>
</xpath>
<xpath expr="//field[@name='recurring_invoice_line_ids']" position="after">
<label for="recurring_invoice_car_line_ids" attrs="{'invisible': [('recurring_invoices','=',False)]}"/>
<div attrs="{'invisible': [('recurring_invoices','=',False)]}">
<field name="recurring_invoice_car_line_ids">
<tree string="Account Analytic Lines" editable="bottom">
<field name="car_id" on_change="car_id_change(car_id, car_license_plate, car_mavirent_nummer, car_chassis, car_rent_price)" attrs="{'required':[('car_id', '!=', '')]}"/>
<!--These fields are only required when there is a value in the many2one field product_id' -->
<field name="car_mavirent_nummer" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_license_plate" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_chassis" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_rent_price" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_number_of_units" attrs="{'required':[('car_id', '!=', '')]}"/>
<field name="car_line_tax_id" widget="many2many_tags"/>
<field name="uom_id" />
<field name="product_id" />
<field name="price_unit" />

<field name="car_account_id"/>
</tree>
</field>
</div>
</xpath>
</field>
</record>


Now it's possible to go to sales > contracts, create a new contract and add one car and no products, then click on save and no errors, you can save it successfully. However the above changes are a quick fix, I've not investigated application logic deeper, please adapt solution to your case. For each mandatory field, either add them in the view or make them optional (NOT required) fields as I made optional the "name" field above, and/or review dependency list of your module again if it may change a behavior of your module, as other modules may change fields by incremental updates as well.






1
頭像
捨棄
Yenthe Van Ginneken (Mainframe Monkey)
作者

Thanks Temur but I was just missing the 'account' import, I only had 'account_analytic_analysis' and not 'account' and this was giving the strange error. I've updated my question since I now have another strange one.

Yenthe Van Ginneken (Mainframe Monkey)
作者

@Temur: I've decided to put it on Github so you can see all the code and test it if you'd like / need to. See https://github.com/Yenthe666/Dev/tree/master/aa_maatwerk_be_trans

Yenthe Van Ginneken (Mainframe Monkey)
作者

@Temur perfect! That was exactly what I was looking for. I'll need some minor changes to have everything perfect but my problem is fixed now. Thanks a lot! Accepted & upvoted! :)

Temur

You're welcome

頭像
Axel Mendoza
最佳答案

@Yenthe, i'm with Pawan on his answer, I don't think that converting the required field into non-required is a good idea, maybe doing that you end up getting broken another scenario.

For me better you follow what it's done on the model account.analytic.account on the method on_change_template building the values for the field recurring_invoice_line_ids, specifically this:

...

invoice_line_ids = []

for x in template.recurring_invoice_line_ids:

invoice_line_ids.append((0, 0, {

'product_id': x.product_id.id,

'uom_id': x.uom_id.id,

'name': x.name,

'quantity': x.quantity,

'price_unit': x.price_unit,

'analytic_account_id': x.analytic_account_id and x.analytic_account_id.id or False,

}))

res['value']['recurring_invoices'] = template.recurring_invoices

res['value']['recurring_interval'] = template.recurring_interval

res['value']['recurring_rule_type'] = template.recurring_rule_type

res['value']['recurring_invoice_line_ids'] = invoice_line_ids

...

Using this solution in your own onchange you need to add the needed fields that @Temur found that need to have a value in your editable tree, at least with invisible="1" so the onchange values could fill those fields and they will be sent to the model create/write and you will don't end up with errors for not-null fields
 

1
頭像
捨棄
頭像
Pawan
最佳答案

Yenthe,

There is  a predefined fields called 'name' in account_analytic_invoice_line object which is mandatory by default, which you are not defining while returning it from on change of car field.

So adding {'name': "SOME DATA"} to the returning dictionary from the function.

Regards,

 




0
頭像
捨棄
Yenthe Van Ginneken (Mainframe Monkey)
作者

Thanks for the reply Pawan! I was thinking that to initially so at some point I added a name field in the dict but even then I get this error. An example: result.update({'car_name': car_name,'car_license_plate': car_license_plate, 'car_mavirent_nummer': car_mavirent_nummer, 'car_chassis': car_chassis, 'car_rent_price': car_rent_price, 'car_number_of_units': car_number_of_units, 'car_line_tax_id': [(6, 0, goede_btw_id)], 'name': 'Demo name'})

Temur

What about 'name' field in 'account.tax' object (in the goede_btw_id one) ? it's defined as mandatory as well

Yenthe Van Ginneken (Mainframe Monkey)
作者

@Pawan and @Temur problem seem to came from the fact that I didn't inherit 'account', I had inherited 'account_analytic_analysis' but missed 'account'. I've updated my question since I now have a new issue about [object with reference: price_unit - price.unit]

Pawan

Yenthe,
price_unit also exist in "account_analytic_invoice_line", try adding {'price_unit':0.0} too in your code, and you are returning dictionary at 2 places, please confirm with both the scenarios because i can't find any other scenario for this error

Yenthe Van Ginneken (Mainframe Monkey)
作者

Pawan, That was exactly my idea too but that doesn't work either. I'll keep getting the error regarding price_unit..

Yenthe Van Ginneken (Mainframe Monkey)
作者

@Pawan and @Temur: I've decided to put it on Github so you can see all the code and test it if you'd like / need to. See https://github.com/Yenthe666/Dev/tree/master/aa_maatwerk_be_trans

喜歡這則討論?不要只閱讀,加入發表意見吧!

今天就建立帳戶,享受獨家功能,與我們精彩的社群互動!

註冊
相關帖文 回覆 瀏覽次數 活動
How to inherit / modify point of sale pages & create restrictions? 已解決
inheritance point_of_sale odoo8.0
頭像
頭像
1
11月 21
7993
How to inherit calendar popup? 已解決
inheritance popup odoo8.0
頭像
6
2月 21
16273
how to inherit the timesheet view in my new modul.
modules inheritance odoo8.0
頭像
1
6月 16
4151
In odoo 8 Contracts Form Check Date constraints method gets triggered even after providing valid input dates. How to fix this?
constraint contracts odooV8 odoo8.0
頭像
0
4月 19
4990
How to add field to One2Many with xpath expressions? 已解決
inheritance one2many xpath odoo8.0
頭像
頭像
1
4月 15
14413
社群
  • 教學影片
  • 使用說明
  • 討論區
開源
  • 下載
  • GitHub
  • Runbot 測試環境
  • 翻譯
服務
  • odoo.sh 網頁寄存
  • 支援
  • 升級
  • 自訂功能開發
  • 教育及培訓
  • 尋找會計服務
  • 尋找合作夥伴
  • 成為合作夥伴
關於我們
  • 關於 Odoo 公司
  • 品牌資產
  • 聯絡我們
  • 招聘
  • 活動
  • Podcast
  • 網誌
  • 客戶
  • 法律 • 私隱政策
  • 安全性
الْعَرَبيّة 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)、電子商務、會計、庫存管理、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