_constraints - only last constraint is evaluated - GRAVE

Bug #564926 reported by Ferdinand on 2010-04-16
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Odoo Server (MOVED TO GITHUB)
Fix Released
Undecided
Anup(SerpentCS)

Bug Description

branch-server 2037

in this statement only the last constraint is evaluated - the first 2 are ignored - can be checked by rotating the constraints

    _constraints = [
        (_check_analytic_account_exists,"Analytic account must be entered for this account",['account_analytic_id'] ),
        (_check_analytic_account_none,"Analytic account is forbidden for this account",['account_analytic_id'] ),
        (_check_analytic_account_fixed,"The analytic account does not match the fixed analytic account defined for this account",['account_analytic_id'] ),
        ]

I attach the complete module (work in progress) for test purpose

Related branches

Ferdinand (office-chricar) wrote :

Hello Dr. Ferdinand,

If the constraints belong to the same objects,all the validation errors are thrown without fail. Its always a good practice to use the same function for the same field.
If the constraints belong to different objects, only the current object (whose create/write) is under change,will throw related constraint!

Kindly recheck,
Thanks,

Changed in openobject-server:
milestone: none → 5.0.10
status: New → Invalid
Ferdinand (office-chricar) wrote :

Does your answer mean that 2 and more constraints for the same field of the same object are not supported ?
I know if I pack all the 3 checks of the example given into ONE function - I get only ONE error message - but this is not user friendly

Yes, I tried 2 constraints for the same field and they are supported.
Please recheck.
Even I went through the server code, its alright there.

Ferdinand (office-chricar) wrote :

Sorry to come back on this - IMHO there is a problem
I have added some debug code and it shows that one constraint is never executed.

I have added the module with the debug info

AFAICS - it's always the second of the three constaints which is not executed.

to reproduce
* install 5.0.x
* got to accounts change somthing and save
* this should print for each constaint
TEST ****** _check_analytic_<constraint>

Changed in openobject-server:
status: Invalid → New
Changed in openobject-server:
status: New → Confirmed
assignee: nobody → Anup (Open ERP) (ach-openerp)
Changed in openobject-server:
status: Confirmed → In Progress
Anup(SerpentCS) (anup-serpent) wrote :

Hello Dr. Ferdinand,

  The problem occurs when we have more than one constraints on the same field. I have attached a solution with this would you please check it and notify us.

Thanks.

Ferdinand (office-chricar) wrote :

thanks
works for me

Guys,

If I remember well I confirm the issue. I had this issue in late 2008 with
the mrp_autosplit module (serial number management), where I had to comment
that contraint otherwise it would override the original constraints:

# def _check_unique_product_lot(self, cr, uid, ids):
# print "########"
# for move in self.browse(cr, uid, ids):
# if move.state == 'done' and
move.product_id.unique_production_number and move.product_qty > 1 and (\
# (move.product_id.track_production and
move.location_id.usage == 'production') or \
# (move.product_id.track_production and
move.location_dest_id.usage == 'production') or \
# (move.product_id.track_incoming and move.location_id.usage
== 'supplier') or \
# (move.product_id.track_outgoing and
move.location_dest_id.usage == 'customer')):
# return False
# return True
#
# _constraints = [
# (_check_unique_product_lot,
# """_(The product associated to the move require a unique (per
instance) production number,
# you should split the move assign a different number to every
move)""",
# ['prodlot_id'])]

Once this is fixed I'll enable/update the constraint again to make
mrp_autosplit stronger.
Thanks for taking care of this.

Raphaël Valyi
http://www.akretion.com

On Fri, Apr 23, 2010 at 10:14 AM, Anup (Open ERP) <email address hidden> wrote:

> Hello Dr. Ferdinand,
>
> The problem occurs when we have more than one constraints on the same
> field. I have attached a solution with this would you please check it and
> notify us.
>
> Thanks.
>
> ** Patch added: "constraint_patch.diff"
> http://launchpadlibrarian.net/45102989/constraint_patch.diff
>
> --
> _constraints - only last constraint is evaluated - GRAVE
> https://bugs.launchpad.net/bugs/564926
> You received this bug notification because you are subscribed to
> OpenObject Server.
>
> Status in OpenObject Server: In Progress
>
> Bug description:
> branch-server 2037
>
> in this statement only the last constraint is evaluated - the first 2 are
> ignored - can be checked by rotating the constraints
>
> _constraints = [
> (_check_analytic_account_exists,"Analytic account must be entered
> for this account",['account_analytic_id'] ),
> (_check_analytic_account_none,"Analytic account is forbidden for
> this account",['account_analytic_id'] ),
> (_check_analytic_account_fixed,"The analytic account does not match
> the fixed analytic account defined for this account",['account_analytic_id']
> ),
> ]
>
> I attach the complete module (work in progress) for test purpose
>
>
>

Thank you for your participation.
It has been fixed by revision 2041 <email address hidden>.

Changed in openobject-server:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers