Skip to Content
Menu
This question has been flagged

I'm creating a custom module in Odoo, and I took inspiration from stock module, since I have to check product availability in lines, just like in stock.picking model.

This is my main model:

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

    notes = fields.Text(string="Notes")
    order_lines = fields.One2many('bsi.production.order.lines', 'production_order', string="Order lines")
    state = fields.Selection([
        ('draft','Draft'),
        ('inprogress','In progress'),
        ('print_order_inprogress','Print Order In Progress'),
        ('finished','Finished'),
        ('cancel','Cancel'),
    ], string='State', index=True,  
    track_visibility='onchange', copy=False,
    help=" ")

This is the method which by the way should also give me a Warning if no lines are specified (from order_lines One2many field)

@api.multi
def action_assign(self):
    for pick in self.browse():
        #if pick.state == 'draft':
            #self.action_confirm([pick.id])
        #skip the moves that don't need to be checked
        move_ids = [x.id for x in pick.order_lines if x.state not in ('draft', 'cancel')]
        if not move_ids:
            raise Warning(_('Warning!'), _('Enter​ ​at least​ ​1​ ​ISBN to produce'))
        self.env['bsi.production.order.lines'].action_assign(move_ids)
    return True

Note that this is actually taken from stock.picking order, I mean, I've adapted this method for my object, below is my lines method (bsi.production.order.lines)

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")

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

The point is, that this should check for isbn which is a Many2one to product.product object, and see if there is any availability for it, or, in case that no line has been specified, then throw the Warning, but every time I click, seems to load something, but no real check, or warning whatsoever.

Also no traceback on log file, nothing.

This is the button in my view:

    <button string="Check Availability" name="action_assign" states="draft" type="object" class="oe_highlight"/>

Any ideas?

Avatar
Discard
Related Posts Replies Views Activity
16
Jan 21
15523
1
Mar 15
3397
0
Mar 15
2670
1
Mar 15
11073
1
Mar 15
4201