mrp_production_backorder.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo import api, fields, models
  4. class MrpProductionBackorderLine(models.TransientModel):
  5. _name = 'mrp.production.backorder.line'
  6. _description = "Backorder Confirmation Line"
  7. mrp_production_backorder_id = fields.Many2one('mrp.production.backorder', 'MO Backorder', required=True, ondelete="cascade")
  8. mrp_production_id = fields.Many2one('mrp.production', 'Manufacturing Order', required=True, ondelete="cascade", readonly=True)
  9. to_backorder = fields.Boolean('To Backorder')
  10. class MrpProductionBackorder(models.TransientModel):
  11. _name = 'mrp.production.backorder'
  12. _description = "Wizard to mark as done or create back order"
  13. mrp_production_ids = fields.Many2many('mrp.production')
  14. mrp_production_backorder_line_ids = fields.One2many(
  15. 'mrp.production.backorder.line',
  16. 'mrp_production_backorder_id',
  17. string="Backorder Confirmation Lines")
  18. show_backorder_lines = fields.Boolean("Show backorder lines", compute="_compute_show_backorder_lines")
  19. @api.depends('mrp_production_backorder_line_ids')
  20. def _compute_show_backorder_lines(self):
  21. for wizard in self:
  22. wizard.show_backorder_lines = len(wizard.mrp_production_backorder_line_ids) > 1
  23. def action_close_mo(self):
  24. return self.mrp_production_ids.with_context(skip_backorder=True).button_mark_done()
  25. def action_backorder(self):
  26. ctx = dict(self.env.context)
  27. ctx.pop('default_mrp_production_ids', None)
  28. mo_ids_to_backorder = self.mrp_production_backorder_line_ids.filtered(lambda l: l.to_backorder).mrp_production_id.ids
  29. return self.mrp_production_ids.with_context(ctx, skip_backorder=True, mo_ids_to_backorder=mo_ids_to_backorder).button_mark_done()