[ADD] account: Unicity constraint on reco models
1- throw an error when creating a model with a name already taken 2- Duplicate action button create a new model with (copy) append to then name task_id: 2971488 closes odoo/odoo#99581 Signed-off-by: Olivier Colson (oco) <oco@odoo.com>
This commit is contained in:
committed by
maximilien(malb)
parent
340f465d51
commit
10dc2a4b9a
@@ -226,6 +226,8 @@ class AccountReconcileModel(models.Model):
|
||||
_order = 'sequence, id'
|
||||
_check_company_auto = True
|
||||
|
||||
_sql_constraints = [('name_unique', 'unique(name, company_id)', 'A reconciliation model already bears this name.')]
|
||||
|
||||
# Base fields.
|
||||
active = fields.Boolean(default=True)
|
||||
name = fields.Char(string='Name', required=True)
|
||||
@@ -412,6 +414,17 @@ class AccountReconcileModel(models.Model):
|
||||
elif record.payment_tolerance_type == 'fixed_amount' and record.payment_tolerance_param < 0:
|
||||
raise ValidationError(_("A payment tolerance defined as an amount should always be higher than 0"))
|
||||
|
||||
@api.returns('self', lambda value: value.id)
|
||||
def copy(self, default=None):
|
||||
default = default or {}
|
||||
if default.get('name'):
|
||||
return super(AccountReconcileModel, self).copy(default)
|
||||
name = _("%s (copy)", self.name)
|
||||
while self.env['account.reconcile.model'].search([('name', '=', name)], limit=1):
|
||||
name = _("%s (copy)", name)
|
||||
default['name'] = name
|
||||
return super(AccountReconcileModel, self).copy(default)
|
||||
|
||||
####################################################
|
||||
# RECONCILIATION PROCESS
|
||||
####################################################
|
||||
|
||||
@@ -805,32 +805,32 @@ class AccountChartTemplate(models.Model):
|
||||
self.create_record_with_xmlid(company, account_reconcile_model, 'account.reconcile.model', vals)
|
||||
|
||||
# Create default rules for the reconciliation widget matching invoices automatically.
|
||||
if not self.parent_id:
|
||||
self.env['account.reconcile.model'].sudo().create({
|
||||
"name": _('Invoices/Bills Perfect Match'),
|
||||
"sequence": '1',
|
||||
"rule_type": 'invoice_matching',
|
||||
"auto_reconcile": True,
|
||||
"match_nature": 'both',
|
||||
"match_same_currency": True,
|
||||
"allow_payment_tolerance": True,
|
||||
"payment_tolerance_type": 'percentage',
|
||||
"payment_tolerance_param": 0,
|
||||
"match_partner": True,
|
||||
"company_id": company.id,
|
||||
})
|
||||
|
||||
self.env['account.reconcile.model'].sudo().create({
|
||||
"name": _('Invoices/Bills Perfect Match'),
|
||||
"sequence": '1',
|
||||
"rule_type": 'invoice_matching',
|
||||
"auto_reconcile": True,
|
||||
"match_nature": 'both',
|
||||
"match_same_currency": True,
|
||||
"allow_payment_tolerance": True,
|
||||
"payment_tolerance_type": 'percentage',
|
||||
"payment_tolerance_param": 0,
|
||||
"match_partner": True,
|
||||
"company_id": company.id,
|
||||
})
|
||||
|
||||
self.env['account.reconcile.model'].sudo().create({
|
||||
"name": _('Invoices/Bills Partial Match if Underpaid'),
|
||||
"sequence": '2',
|
||||
"rule_type": 'invoice_matching',
|
||||
"auto_reconcile": False,
|
||||
"match_nature": 'both',
|
||||
"match_same_currency": True,
|
||||
"allow_payment_tolerance": False,
|
||||
"match_partner": True,
|
||||
"company_id": company.id,
|
||||
})
|
||||
self.env['account.reconcile.model'].sudo().create({
|
||||
"name": _('Invoices/Bills Partial Match if Underpaid'),
|
||||
"sequence": '2',
|
||||
"rule_type": 'invoice_matching',
|
||||
"auto_reconcile": False,
|
||||
"match_nature": 'both',
|
||||
"match_same_currency": True,
|
||||
"allow_payment_tolerance": False,
|
||||
"match_partner": True,
|
||||
"company_id": company.id,
|
||||
})
|
||||
|
||||
return True
|
||||
|
||||
|
||||
Reference in New Issue
Block a user