Help

7

Remove _sql_constraints

I want to remove _sql_constraints (database level).

For example in account_invoice.py there is a constraints on number field. Now I want to remove it.

Can anyone have idea how to deal with this?

Thank you.

Avatar
Discard
2 Answers
8
Avatar
Andreas Brueckl
Best Answer

With the following steps I was able to remove SQL constraints in version 6.0 (but it should also work for v7.0):

  1. Remove SQL constraint in Python code
  2. Manually remove the constraint in PostgreSQL using PgAdmin3

If you do not want to change the existing module, you can

  • Create a new module and
  • replace the SQL constraint with the value CHECK(1=1)

In your example you can create a new module and write:

class account_invoice(osv.osv):
    _inherit = "account.invoice"
    _sql_constraints = [
    ('number_uniq', 'Check(1=1)', 'Invoice Number must be unique per Company!'),
    ]
account_invoice()
4 Comments
Avatar
Discard
Avatar
Anabela Damas
-

Hello @Andreas Brueckl, If I have something like this: _sql_constraints = [ ('name_company_uniq', 'unique(name, company_id)', 'Tax Name must be unique per company!'), ] But I just want to remove the unique from name, do you know how should I do it ? To keep the company and remove the name from being unique ?

Thanks

Avatar
Andreas Brueckl
-

Just keep the name 'name_company_uniq' and replace the logic with 'unique(company_id)'.

Avatar
Anabela Damas
-

That is the way I try, but I have always an error in log, so I found an workaround. But thanks.

Avatar
fadhel salhi
-

ca marche pas avec moi "check(1=1)"

2
Best Answer

Create you personal module. Inherith the account invoice class and set the _sql_constraints to null.

This is an example that I use to change the sale order _sql_constraints

class sale_order(osv.osv):

    _name = "sale.order"
    _inherit = "sale.order"

    _sql_constraints = [('name_uniq', 'unique(name, date_order)', 'Order Reference must be unique per Date!'),]

sale_order()
Avatar
Discard