Skip to content

Commit

Permalink
l10n_fr_das2: replace onchange by computed fields
Browse files Browse the repository at this point in the history
  • Loading branch information
alexis-via committed Mar 11, 2024
1 parent 450d8f0 commit cc8e36f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
34 changes: 24 additions & 10 deletions l10n_fr_das2/models/l10n_fr_das2.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,12 @@ class L10nFrDas2Line(models.Model):
required=True,
)
partner_siret = fields.Char(
string="SIRET", size=14, states={"done": [("readonly", True)]}
compute="_compute_partner_siret",
store=True,
readonly=False,
string="SIRET",
size=14,
states={"done": [("readonly", True)]},
)
company_id = fields.Many2one(related="parent_id.company_id", store=True)
currency_id = fields.Many2one(
Expand Down Expand Up @@ -853,7 +858,12 @@ class L10nFrDas2Line(models.Model):
state = fields.Selection(related="parent_id.state", store=True)
note = fields.Html()
job = fields.Char(
string="Profession", size=30, states={"done": [("readonly", True)]}
compute="_compute_job",
store=True,
readonly=False,
string="Profession",
size=30,
states={"done": [("readonly", True)]},
)

_sql_constraints = [
Expand Down Expand Up @@ -945,16 +955,20 @@ def _compute_total_amount(self):
line.to_declare = to_declare
line.total_amount = total_amount

@api.depends("partner_id")
def _compute_partner_siret(self):
for line in self:
if line.partner_id and line.partner_id.siren and line.partner_id.nic:
line.partner_siret = line.partner_id.siret

@api.depends("partner_id")
def _compute_job(self):
for line in self:
if line.partner_id and line.partner_id.fr_das2_job:
line.job = line.partner_id.fr_das2_job

@api.constrains("partner_siret")
def check_siret(self):
for line in self:
if line.partner_siret and not is_valid(line.partner_siret):
raise ValidationError(_("SIRET '%s' is invalid.") % line.partner_siret)

@api.onchange("partner_id")
def partner_id_change(self):
if self.partner_id:
if self.partner_id.siren and self.partner_id.nic:
self.partner_siret = self.partner_id.siret
if self.partner_id.fr_das2_job:
self.job = self.partner_id.fr_das2_job
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# generated from manifests external_dependencies
pyfrdas2
pypdf>=3.1.0
python-stdnum
python-stdnum>=1.18
requests_oauthlib
Expand Down

0 comments on commit cc8e36f

Please sign in to comment.