| 1 | from odoo import _, api, fields, models |
| 2 | from odoo.exceptions import ValidationError |
| 3 | |
| 4 | |
| 5 | class AccountMoveLine(models.Model): |
| 6 | _inherit = "account.move.line" |
| 7 | |
| 8 | l10n_tr_ctsp_number = fields.Char( |
| 9 | string="CTSP Number", |
| 10 | compute="_compute_l10n_tr_ctsp_number", |
| 11 | store=True, |
| 12 | readonly=False, |
| 13 | ) |
| 14 | |
| 15 | @api.depends("product_id.l10n_tr_ctsp_number") |
| 16 | def _compute_l10n_tr_ctsp_number(self): |
| 17 | for record in self: |
| 18 | record.l10n_tr_ctsp_number = record.product_id.l10n_tr_ctsp_number |
| 19 | |
| 20 | @api.constrains("l10n_tr_ctsp_number") |
| 21 | def _check_l10n_tr_ctsp_number(self): |
| 22 | for record in self: |
| 23 | if record.l10n_tr_ctsp_number and len(record.l10n_tr_ctsp_number) > 12: |
| 24 | raise ValidationError(_("CTSP Number must be 12 digits or fewer.")) |