Update product_template.py

This commit is contained in:
zainab2097 2024-08-08 13:45:54 +03:00 committed by GitHub
parent 6cf14419ca
commit 24d8c6eed7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 0 deletions

View File

@ -14,6 +14,26 @@ from odoo import fields,api, models,_
class ProductTemplate(models.Model):
_inherit = "product.template"
type_no = fields.Char("Number", default=lambda self: self._get_next_projectno(), tracking=True,copy=False)
@api.model
def _get_next_projectno(self):
next_sequence = "/ "
sequence = self.env['ir.sequence'].search(
['|', ('company_id', '=', self.env.company[0].id), ('company_id', '=', False),
('code', '=', 'seq.product.template')], limit=1)
if sequence:
next_sequence = sequence.get_next_char(sequence.number_next_actual)
return next_sequence
@api.model
def create(self, vals):
company_id = vals.get('company_id', self.default_get(['company_id'])['company_id'])
self_comp = self.with_company(company_id)
if not vals.get('type_no', False):
vals['type_no'] = self_comp.env['ir.sequence'].next_by_code('seq.product.template') or '/'
return super().create(vals)
gender = fields.Selection(
selection=[("male", "Male"), ("female", "Female")], default="male",string='Gender'
)