콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6939 화면

I have these 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)

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", compute="_remaining_func")

    @api.onchange('qty', 'consumed_qty')
    def _remaining_func(self):
        if self.consumed_qty or self.qty:
            self.remaining_qty = self.consumed_qty - self.qty

I'm trying to loop into bsi.production.order.lines and check all the 'isbn' which are products, this is what I've tried so far:

  1. @api.multi

        @api.depends('order_lines', 'order_lines.isbn')

        def checkit(self):

            for record in self:

                if self.order_lines.isbn:

                    return self.order_lines.isbn

                else:

                    raise Warning(('Enter​ ​at least​ ​1​ ​ISBN to produce'))

But If I add more than one product or 'isbn' to line, it throws me the 'Expected singleton' error.

How can I properly loop through bsi.production.order.lines?










아바타
취소
베스트 답변

Hello Alberto,

If you want to do like this, without any lines production can't be start.
For that you need to try create and write method for this.

Example :-

from openerp import models, fields, api, _ from openerp.exceptions import UserError

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

    @api.model
    def create(self, vals):
        result = super(bsi_production_order, self).create(vals)
        if not result.order_lines:
            raise UserError(_('You Can not Start Production Without any Product.'))
        return result

    @api.multi
    def write(self, vals):
        result = super(WorkOrder, self).write(vals)
        if not self.order_lines:
            raise UserError(_('You Can not Start Production Without any Product.'))
        return result


Hope it will helps you.
Thanks,

아바타
취소
작성자

Thank You Jignesh :) Awesome approach

관련 게시물 답글 화면 활동
1
3월 25
848
0
7월 25
354
2
6월 25
1281
1
5월 25
1306
0
3월 25
1156