|
| 1 | +# Copyright 2025 Nextev Srl |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
| 3 | + |
| 4 | +from odoo import _, api, fields, models |
| 5 | +from odoo.exceptions import ValidationError |
| 6 | + |
| 7 | + |
| 8 | +class MoveLineOtherData(models.Model): |
| 9 | + """Model for storing AltriDatiGestionali (2.2.1.16) on invoice lines for export. |
| 10 | +
|
| 11 | + This model stores additional management data that can be manually entered |
| 12 | + on account.move.line records and exported into the FatturaPA XML. |
| 13 | + """ |
| 14 | + |
| 15 | + _name = "l10n_it_edi.move.line.other.data" |
| 16 | + _description = "Invoice Line Other Data for Export" |
| 17 | + _rec_name = "display_name" |
| 18 | + |
| 19 | + move_line_id = fields.Many2one( |
| 20 | + "account.move.line", |
| 21 | + string="Invoice Line", |
| 22 | + required=True, |
| 23 | + ondelete="cascade", |
| 24 | + index=True, |
| 25 | + ) |
| 26 | + name = fields.Char( |
| 27 | + string="Data Type", |
| 28 | + required=True, |
| 29 | + help="TipoDato: Type of additional data (max 10 characters)", |
| 30 | + size=10, |
| 31 | + ) |
| 32 | + text_ref = fields.Char( |
| 33 | + string="Text Reference", |
| 34 | + help="RiferimentoTesto: Text reference (max 60 characters)", |
| 35 | + size=60, |
| 36 | + ) |
| 37 | + num_ref = fields.Float( |
| 38 | + string="Number Reference", |
| 39 | + digits=(16, 8), |
| 40 | + help="RiferimentoNumero: Numeric reference (up to 8 decimal places)", |
| 41 | + ) |
| 42 | + date_ref = fields.Date( |
| 43 | + string="Date Reference", |
| 44 | + help="RiferimentoData: Date reference", |
| 45 | + ) |
| 46 | + |
| 47 | + @api.depends("name", "text_ref", "num_ref", "date_ref") |
| 48 | + def _compute_display_name(self): |
| 49 | + for record in self: |
| 50 | + parts = [record.name] |
| 51 | + if record.text_ref: |
| 52 | + parts.append(record.text_ref) |
| 53 | + if record.num_ref: |
| 54 | + parts.append(str(record.num_ref)) |
| 55 | + if record.date_ref: |
| 56 | + parts.append(str(record.date_ref)) |
| 57 | + record.display_name = ": ".join(parts) |
| 58 | + |
| 59 | + @api.constrains("name", "text_ref", "num_ref", "date_ref") |
| 60 | + def _check_at_least_one_ref(self): |
| 61 | + for record in self: |
| 62 | + has_text = bool(record.text_ref) |
| 63 | + # For Float fields, check if value was explicitly set (not default 0.0) |
| 64 | + has_num = bool(record.num_ref) |
| 65 | + has_date = bool(record.date_ref) |
| 66 | + if not has_text and not has_num and not has_date: |
| 67 | + raise ValidationError( |
| 68 | + _( |
| 69 | + "At least one of Text Reference, Number Reference, " |
| 70 | + "or Date Reference must be provided." |
| 71 | + ) |
| 72 | + ) |
0 commit comments