mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-20 08:32:03 +02:00
19.0 vanilla
This commit is contained in:
parent
d1963a3c3a
commit
2d3ee4855a
7430 changed files with 2687981 additions and 2965473 deletions
|
|
@ -1,8 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
|
||||
from odoo import _, api, fields, models, tools
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class UtmSource(models.Model):
|
||||
|
|
@ -11,9 +10,17 @@ class UtmSource(models.Model):
|
|||
|
||||
name = fields.Char(string='Source Name', required=True)
|
||||
|
||||
_sql_constraints = [
|
||||
('unique_name', 'UNIQUE(name)', 'The name must be unique'),
|
||||
]
|
||||
_unique_name = models.Constraint(
|
||||
'UNIQUE(name)',
|
||||
'The name must be unique',
|
||||
)
|
||||
|
||||
@api.ondelete(at_uninstall=False)
|
||||
def _unlink_except_referral(self):
|
||||
utm_source_referral = self.env.ref('utm.utm_source_referral', raise_if_not_found=False)
|
||||
for record in self:
|
||||
if record == utm_source_referral:
|
||||
raise ValidationError(_("You cannot delete the 'Referral' UTM source record."))
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
|
|
@ -31,12 +38,13 @@ class UtmSource(models.Model):
|
|||
if len(content) >= 24:
|
||||
content = f'{content[:20]}...'
|
||||
|
||||
create_date = record.create_date or fields.date.today()
|
||||
create_date = fields.date.strftime(create_date, tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||
create_date = record.create_date or fields.Datetime.today()
|
||||
model_description = self.env['ir.model']._get(record._name).name
|
||||
return _(
|
||||
'%(content)s (%(model_description)s created on %(create_date)s)',
|
||||
content=content, model_description=model_description, create_date=create_date,
|
||||
content=content,
|
||||
model_description=model_description,
|
||||
create_date=fields.Date.to_string(create_date),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -51,9 +59,9 @@ class UtmSourceMixin(models.AbstractModel):
|
|||
source_id = fields.Many2one('utm.source', string='Source', required=True, ondelete='restrict', copy=False)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
# Exclude 'name' from fields_list to avoid retrieving it from context.
|
||||
return super().default_get([field for field in fields_list if field != "name"])
|
||||
def default_get(self, fields):
|
||||
# Exclude 'name' from fields to avoid retrieving it from context.
|
||||
return super().default_get([field for field in fields if field != "name"])
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
|
|
@ -80,23 +88,26 @@ class UtmSourceMixin(models.AbstractModel):
|
|||
|
||||
return super().create(vals_list)
|
||||
|
||||
def write(self, values):
|
||||
if (values.get(self._rec_name) or values.get('name')) and len(self) > 1:
|
||||
def write(self, vals):
|
||||
if (vals.get(self._rec_name) or vals.get('name')) and len(self) > 1:
|
||||
raise ValueError(
|
||||
_('You cannot update multiple records with the same name. The name should be unique!')
|
||||
)
|
||||
|
||||
if values.get(self._rec_name) and not values.get('name'):
|
||||
values['name'] = self.env['utm.source']._generate_name(self, values[self._rec_name])
|
||||
if values.get('name'):
|
||||
values['name'] = self.env['utm.mixin'].with_context(
|
||||
if vals.get(self._rec_name) and not vals.get('name'):
|
||||
vals['name'] = self.env['utm.source']._generate_name(self, vals[self._rec_name])
|
||||
if vals.get('name'):
|
||||
vals['name'] = self.env['utm.mixin'].with_context(
|
||||
utm_check_skip_record_ids=self.source_id.ids
|
||||
)._get_unique_names("utm.source", [values['name']])[0]
|
||||
)._get_unique_names("utm.source", [vals['name']])[0]
|
||||
|
||||
super().write(values)
|
||||
return super().write(vals)
|
||||
|
||||
def copy(self, default=None):
|
||||
def copy_data(self, default=None):
|
||||
"""Increment the counter when duplicating the source."""
|
||||
default = default or {}
|
||||
default['name'] = self.env['utm.mixin']._get_unique_names("utm.source", [self.name])[0]
|
||||
return super().copy(default)
|
||||
default_name = default.get('name')
|
||||
vals_list = super().copy_data(default=default)
|
||||
for source, vals in zip(self, vals_list):
|
||||
vals['name'] = self.env['utm.mixin']._get_unique_names("utm.source", [default_name or source.name])[0]
|
||||
return vals_list
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue