You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.6 KiB
45 lines
1.6 KiB
# -*- coding: utf-8 -*-
|
|
###############################################################################
|
|
#
|
|
# Cybrosys Technologies Pvt. Ltd.
|
|
#
|
|
# Copyright (C) 2023-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
|
|
# Author: Sagarika B (odoo@cybrosys.com)
|
|
#
|
|
# You can modify it under the terms of the GNU AFFERO
|
|
# GENERAL PUBLIC LICENSE (AGPL v3), Version 3.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details.
|
|
#
|
|
# You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
# (AGPL v3) along with this program.
|
|
#
|
|
###############################################################################
|
|
""" project.task model """
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class ProjectTask(models.Model):
|
|
""" inherits project.task """
|
|
_inherit = 'project.task'
|
|
|
|
unique_code = fields.Char(string='Unique Code', readonly=True,
|
|
help='Unique code for each task.')
|
|
|
|
_sql_constraints = [
|
|
('unique_code', 'unique(unique_code, company_id)',
|
|
'Code must be unique per company!'),
|
|
]
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
""" extends the create method to generate the unique code """
|
|
for vals in vals_list:
|
|
project = self.env['project.project'].browse(vals.get('project_id'))
|
|
if project.sequence_id:
|
|
vals['unique_code'] = project.sequence_id.next_by_id()
|
|
return super().create(vals_list)
|
|
|