Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
3006 Widoki

Hi All,

I couldn't  get the backorder and moveline in stock.picking table

Below i mentioned my code.

If have done any mistake in code plz correct me.


class StockPicking(models.Model):
    _inherit = "stock.picking"

    alert_count = fields.Integer(compute='_compute_alert', string='Quality Alerts', default=0)
    alert_ids = fields.Many2many('quality.alert', compute='_compute_alert', string='Quality Alerts', copy=False)
   
    @api.model
    def create(self, vals):
        res = super(StockPicking, self).create(vals)
        res.generate_quality_alert()
        return res

    @api.multi
    def generate_quality_alert(self):
        quality_alert = self.env['quality.alert']
        quality_measure = self.env['quality.measure']
        stockpick=self.env['stock.picking']
        for pick in self:
            backorder = stockpick.search([('backorder_id', '=', pick.id)])
            print(backorder)
            if backorder is True:
                for line in backorder.move_lines:
                    print(line)
                    measures = quality_measure.search([('product_id', '=', line.product_id.id)])
                    if measures:
                        print(measures)
                        quality_alert.create({
                            'product_id': line.product_id.id,
                            'picking_id': backorder.id,
                            'origin': backorder.name,
                            'company_id': backorder.company_id.id,
                            'order_id': False,
                            'ordered_quantity':line.product_uom_qty,
                            'pending_quantity':line.product_uom_qty,
                        })

Awatar
Odrzuć
Najlepsza odpowiedź

Hello, 

I  ​just found some mistake into code which i corrected. Hope this will help.

Problem in code which i changed it.

1. if picking is creating. so it will contain backorder_id.but you are searching wrong like created record as reference into backorder it.

2. second search will give you browse record, or blank object. not True or False.

Please verify code. Hope this will help.

    @ api.model 
    def create (self, vals): 
        res = super (StockPicking, self) .create (vals) 
        res.generate_quality_alert () 
        return res

    @ api.multi 
    def generate_quality_alert (self): 
        quality_alert = self.env ['quality.alert'] 
        quality_measure = self.env ['quality.measure'] 
        stockpick = self.env ['stock.picking'] 
        for pick in self :  
            if pick.backorder_id:
                for line in pick.backorder_id.move_lines:
                    measures = quality_measure.search ([] ('product_id ',' = ', line.product_id.id)]) 
                    if measures:
                        quality_alert.create ({
                            product_id: line.product_id.id, 
                            picking_id: pick.backorder_id.id, 
                            origin: pick.backorder_id.name, 
                            company_id: pick.backorder_id.company_id.id, 
                            order_id: false, 
                            ordered_quantity: line.product_uom_qty, 
                            'pending_quantity': line.product_uom_qty , 
                        })


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lis 24
18634
0
sie 22
11973
3
gru 19
6854
1
gru 23
22427
2
gru 15
4148