res_company.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Company(models.Model):
  5. _inherit = 'res.company'
  6. manufacturing_lead = fields.Float(
  7. 'Manufacturing Lead Time', default=0.0, required=True,
  8. help="Security days for each manufacturing operation.")
  9. def _create_unbuild_sequence(self):
  10. unbuild_vals = []
  11. for company in self:
  12. unbuild_vals.append({
  13. 'name': 'Unbuild',
  14. 'code': 'mrp.unbuild',
  15. 'company_id': company.id,
  16. 'prefix': 'UB/',
  17. 'padding': 5,
  18. 'number_next': 1,
  19. 'number_increment': 1
  20. })
  21. if unbuild_vals:
  22. self.env['ir.sequence'].create(unbuild_vals)
  23. @api.model
  24. def create_missing_unbuild_sequences(self):
  25. company_ids = self.env['res.company'].search([])
  26. company_has_unbuild_seq = self.env['ir.sequence'].search([('code', '=', 'mrp.unbuild')]).mapped('company_id')
  27. company_todo_sequence = company_ids - company_has_unbuild_seq
  28. company_todo_sequence._create_unbuild_sequence()
  29. def _create_per_company_sequences(self):
  30. super(Company, self)._create_per_company_sequences()
  31. self._create_unbuild_sequence()
  32. def _get_security_by_rule_action(self):
  33. res = super()._get_security_by_rule_action()
  34. res['manufacture'] = self.manufacturing_lead
  35. return res