Skip to Content
Menu
This question has been flagged
7 Replies
2882 Views

Hi community , its so urgent Plz

I had add a boolean field in 'product.product' named 'is_dmp'. so , i want that if I try to add an artcile who have this field false in purchase order , a warning message appear . 

so this what i did :

--------------------------------------------------------------------------------------------------------------------------

from odoo import api, models

from odoo import fields

from odoo.exceptions import UserError

class product_product(models.Model):

_name = 'product.product'

_inherit = 'product.product'

is_dmp = fields.Boolean(help='Est ce que cet articles doit avoir un certificat d enregistrement', string='Necessite un enregistrement')

dmp = fields.Char('Numéro de certificat')

# purchase_ok = fields.Boolean(compute='_check_dmp'),

class PurchaseOrderLineWar(models.Model):

_name = "product.product"

_inherit = "product.product"

@api.onchange('dmp')

def _check_dmp(self):

if self.is_dmp == False:

warning_mess = {

'title': _('Warnnnnning'),

'message' : _('Attention cet article ne necessite pas un certifact DMP'),

}

return {'warning': warning_mess}  

-----------------------------------------------------------------------------------------------------------------------


Plz any idea , i need help .

Avatar
Discard

Do you want to show warning when user selects a product in purchase order line?

Best Answer

You have inherited wrong object in PurchaseOrderLineWar class.

I think you should inherit "purchase.order" or "purchase.order.line" object.

If you want to show a warning message when user selects a product in purchase order line, you should use following code:

class PurchaseOrderLine(models.Model):
    _inherit = 'purchase.order.line'

    @api.onchange('product_id')
    def change_product(self):
        if self.product_id and self.product_id.is_dmp:
            msg = {
                'title': 'Warning',
                'message': 'Your warning message.'
            }
            return {'warning': msg}

This way you can show a warning message when user selects product in purchase order line and product does not have is_dmp boolean if False.

Sudhir Arya
ERP Harbor Consulting Services
s:sudhir@erpharbor.com  w: http://www.erpharbor.com
Avatar
Discard
Author

Yes, exectly , I want to show warning when user selects a product that have is_dmp True in purchase order line?

Author

Im sorry i past a wrong code in my question hhh , i will edit it with the right one

Author

Hi community , its so urgent Plz

I had add a boolean field in 'product.product' named 'is_dmp'. so , i want that if I try to add an artcile who have this field false in purchase order , a warning message appear .

so this what i did :

--------------------------------------------------------------------------------------------------------------------------

from odoo import api, models

from odoo import fields

from odoo.exceptions import UserError

class product_product(models.Model):

_name = 'product.product'

_inherit = 'product.product'

is_dmp = fields.Boolean(help='Est ce que cet articles doit avoir un certificat d enregistrement', string='Necessite un enregistrement')

dmp = fields.Char('Numéro de certificat')

class PurchaseOrderLineWar(models.Model):

_name = 'purchase.order.line'

_inherit = 'purchase.order.line'

@api.onchange('order_line.product_id')

def _check_dmp(self):

print 'HHHHHHHHHHHHHHHHHHHHHHHHHHHH'

for a in self.order_line:

if a.product_id.is_dmp == True:

raise UserError(_("Please Select Goods your mesage"))

-----------------------------------------------------------------------------------------------------------------------

Plz any idea , i need help .

Just try the code which is in my answer. It will work for you.

Related Posts Replies Views Activity
1
Aug 20
1817
5
Dec 19
9802
4
Jan 19
3186
1
Jan 19
6384
2
Jan 19
8753