This question has been flagged
3 Replies
5263 Views

I got this error when i click on "Run Procurement"  button in the module "Inventory" or when I click 'Confirm Sale' in module 'Sale'.

Odoo Warning - Validation Error

Error while validating constraint

'purchase.order.line' object has no attribute 'purchase_id'   

Note that the route of  the product listed in the sales order has been set to 'Buy' and 'Make to Order'.  Also I  created a reordering rule for this product. I I wanted is to trigger a purchase order whenever the stock  reaches the minimum level.  I am using odoo version 9.0c-20170906

Avatar
Discard
Best Answer

Hi,

You can check whether you are getting this issue in odoo runbot or not. You can access it from the following link :  http://runbot.odoo.com/runbot

Choose V9 and log in using the credentials email: admin and password: admin

If you are not able to reproduce the issue in the runbot please update your version to the latest of odoo v9.


Most probably you will not get such an error in runbot, if you found means you can report it at : https://github.com/odoo/odoo/issues

 Thanks

Avatar
Discard
Author Best Answer

Samo Arko, reordering rule is from the feature of inventory module. Anyway, i traced the code that triggers creation of purchase order, the error raised at line 983 in purchase.py of purchase module. Ill try in runboot if i could recreate the error.

#981            if not po_line:
#982                vals = procurement._prepare_purchase_order_line(po, supplier)
#983                self.env['purchase.order.line'].create(vals)
#984        return res
Avatar
Discard

Then you probably try to create it with wrong data.

To see what you're passing you can create a custom module where you inherit the model and override the method (copy/paste) and add raise ValidationError('values {}'.format(vals)) before the code on line 983 and you'll with what data you try to create the record.

Author

Thanks for the input. I already traced the culprit. It came from the custom module named operating_unit. They put a constraint in purchase _id in the inherited model of procurement.order.

Best Answer

Your reordering rule, is it a custom module? If it is you need to add the module sale to the dependencies of your custom module.

If you have an error in your custom code it can prevent to load the module whole and this can cause the problem.

This two things are normally what causes my modules to raise the validation constrain error.   

Avatar
Discard