-
-
Notifications
You must be signed in to change notification settings - Fork 535
/
Copy pathres_partner.py
47 lines (41 loc) · 1.61 KB
/
res_partner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# © 2017 Creu Blanca
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import _, api, exceptions, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
l10n_es_facturae_sending_code = fields.Selection(
[("face", "FACe")], string="Sending method"
)
# TODO: Replace this by a boolean on 15.0. We are keeping this on 13 and 14 because
# migration might be problematic
@api.constrains(
"facturae",
"vat",
"country_id",
"state_id",
"l10n_es_facturae_sending_code",
)
def _constrain_l10n_es_facturae_sending_code_face(self):
for record in self:
if (
not record.l10n_es_facturae_sending_code
or record.l10n_es_facturae_sending_code != "face"
):
continue
if not record.facturae:
raise exceptions.ValidationError(
_("Facturae must be selected in order to send to FACe")
)
if not record.vat:
raise exceptions.ValidationError(
_("Vat must be defined in order to send to FACe")
)
if not record.country_id:
raise exceptions.ValidationError(
_("Country must be defined in order to send to FACe")
)
if record.country_id.code_alpha3 == "ESP":
if not record.state_id:
raise exceptions.ValidationError(
_("State must be defined in Spain in order to send to FACe")
)