joaquimlozano

mrp_workorder.py

Oct 21st, 2020 (edited)
555
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime, timedelta
  3. from odoo import api, fields, models, _
  4. from odoo.tools.safe_eval import safe_eval
  5.  
  6. import logging
  7.  
  8. _logger = logging.getLogger(__name__)
  9.  
  10.  
  11. class StartWorkorderWizard(models.TransientModel):
  12.     _name = 'mrp_extend.workorder.wizard'
  13.     _description = "Start selected workorders"
  14.  
  15.     component_lot_ids = fields.Many2many('stock.production.lot', string="components lot ids")
  16.     end_product_lot_id = fields.Many2one('stock.production.lot', string="finished lot id")
  17.     mrp_workcenter = fields.Many2one('mrp.workcenter', 'workcenter')
  18.  
  19.     def action_start_workorder(self):
  20.         """
  21.        Workorders search
  22.        :return:
  23.        """
  24.         workorders = self.env['mrp.workorder'].search(
  25.             [('production_date', '=', fields.Date.today()),
  26.              ('workcenter_id', '=', self.mrp_workcenter.id),
  27.              ('state', '=', 'ready')],
  28.             order='date_planned_start desc')
  29.  
  30.         for wo in workorders:
  31.            
  32.             # HERE CODE FOR UPDATE LINES WITH LOT FROM COMPONENT_LOT_IDS
  33.            
  34.             wo.update({'finished_lot_id': self.end_product_lot_id})
  35.             wo.button_start()
  36.  
RAW Paste Data