Skip to Content
Menu
This question has been flagged
1 Reply
2596 Views

I have these two models:

class bsi_production_order(models.Model):
_name = 'bsi.production.order'

name = fields.Char('Reference', required=True, index=True, copy=False, readonly='True', default='New')
date = fields.Date(string="Production Date")
production_type = fields.Selection([
        ('budgeted','Budgeted'),
        ('nonbudgeted','Non Budgeted'),
        ('direct','Direct Order'),
    ], string='Type of Order', index=True,  
    track_visibility='onchange', copy=False,
    help=" ")
notes = fields.Text(string="Notes")
order_lines = fields.One2many('bsi.production.order.lines', 'production_order', states={'finished': [('readonly', True)], 'cancel': [('readonly', True)]}, string="Order lines", copy=True)
print_orders = fields.One2many('bsi.print.order', 'production_orders', string="Print Orders")
warehouse_quantity = fields.Char(compute='quantity', string='Quantity per warehouse')

class bsi_production_order_lines(models.Model):
_name = 'bsi.production.order.lines'

production_order = fields.Many2one('bsi.production.order', string="Production Orders")
isbn = fields.Many2one('product.product', string="ISBN", domain="[('is_isbn', '=', True)]")
qty = fields.Integer(string="Quantity")
consumed_qty = fields.Float(string="Consumed quantity")
remaining_qty = fields.Float(string="Remaining quantity")

So, from bsi.production.order, I access bsi.production.order.lines through order_lines field.

I need to check for isbn, which is actually a product, check how much there is on stock locations, then compare it, to the order_lines field qty, to see if there is enough quantity.

This is the method I have:

@api.multi
@api.constrains('order_lines', 'order_lines.qty', 'order_lines.isbn')
def check_quantity(self):
    for rec in self:
        if rec.order_lines:
            for line in rec.order_lines:
                if line.qty > rec.isbn.qty_available:
                    raise Warning(('Quantity is invalid.'))

But everytime I click on this button it throws me:

Odoo Server Error
Traceback (most recent call last):
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 546, in _handle_exception
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 583, in dispatch
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 319, in _call_function
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\service\model.py", line 118, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 316, in checked_call
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 812, in __call__
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\http.py", line 412, in response_wrap
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 948, in call_button
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\web\controllers\main.py", line 936, in _call_kw
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 268, in wrapper
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\.\openerp\api.py", line 399, in old_api
File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\addons\bsi\models\models.py", line 501, in check_quantity
AttributeError: 'bsi.production.order' object has no attribute 'isbn'

I know isbn is on bsi.production.order.lines object, and not bsi.production.order , but I have the constrains decorator which should take care of it.


Any ideas?




Avatar
Discard
Best Answer

hi

@api.multi
@api.constrains('order_lines', 'order_lines.qty', 'order_lines.isbn')
def check_quantity(self):
    for rec in self:
        if rec.order_lines:
            for line in rec.order_lines:
                #if line.qty > rec.isbn.qty_available:
if line.qty > line.isbn.qty_available:
raise Warning(('Quantity is invalid.'))

the problem is you are calling bsi_production_order.isbn and not bsi_production_order_lines.isbn

Avatar
Discard
Author

Thank You very much

Related Posts Replies Views Activity
1
Apr 23
787
0
Mar 22
1768
4
Mar 22
30563
0
Jan 18
2507
3
Jun 15
4480