Skip to content

Commit 75e9fb8

Browse files
committed
[IMP] vcp_* : improve naming of field, renaming branch_update into scheduled_branch_update for vcp.repository model.
Add helpers. explicit limit in cron python code.
1 parent 54d2275 commit 75e9fb8

6 files changed

Lines changed: 36 additions & 8 deletions

File tree

vcp_management/data/ir_cron.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<field name="name">VCP: Branch Update</field>
2525
<field name="model_id" ref="model_vcp_repository" />
2626
<field name="state">code</field>
27-
<field name="code">model._cron_update_branches()</field>
27+
<field name="code">model._cron_update_branches(limit=1)</field>
2828
<field name="interval_number">1</field>
2929
<field name="interval_type">days</field>
3030
<field name="active">False</field>

vcp_management/models/vcp_platform.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class VcpPlatform(models.Model):
5252
help="If checked, the cron that update repositories"
5353
" will look for up to date information, for this repository.",
5454
)
55+
default_repository_scheduled_branch_update = fields.Boolean(
56+
help="If checked, the cron that update repository branches"
57+
" will look for up to date branches, for this repository.",
58+
)
5559
scheduled_information_update = fields.Boolean(
5660
default=True,
5761
help="If checked, the cron that update platform informations"

vcp_management/models/vcp_repository.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ class VcpRepository(models.Model):
4444
" will look for up to date information, for this repository."
4545
" This update include the recovery of requests, comments and reviews.",
4646
)
47-
branch_update = fields.Boolean(default=False)
47+
scheduled_branch_update = fields.Boolean(
48+
compute="_compute_scheduled_branch_update",
49+
store=True,
50+
readonly=False,
51+
help="If checked, the cron that update repository branches"
52+
" will look for up to date branches, for this repository.",
53+
)
4854
branch_update_date = fields.Datetime(
4955
readonly=True, required=True, default=fields.Datetime.now
5056
)
@@ -82,6 +88,13 @@ def _compute_scheduled_information_update(self):
8288
record.platform_id.default_repository_scheduled_information_update
8389
)
8490

91+
@api.depends("platform_id")
92+
def _compute_scheduled_branch_update(self):
93+
for record in self:
94+
record.scheduled_branch_update = (
95+
record.platform_id.default_repository_scheduled_branch_update
96+
)
97+
8598
@api.depends("request_ids")
8699
def _compute_request_count(self):
87100
for record in self:
@@ -116,9 +129,11 @@ def _cron_update_repositories(self, limit):
116129
for repository in repositories:
117130
repository.update_information()
118131

119-
def _cron_update_branches(self, limit=1):
132+
def _cron_update_branches(self, limit):
120133
repositories = self.search(
121-
[("branch_update", "=", True)], limit=limit, order="branch_update_date ASC"
134+
[("scheduled_branch_update", "=", True)],
135+
limit=limit,
136+
order="branch_update_date ASC",
122137
)
123138
for repository in repositories:
124139
repository.update_branches()

vcp_management/tests/test_vcp_crons.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def setUpClass(cls):
3636
{"scheduled_information_update": False}
3737
)
3838
cls.env["vcp.repository"].search([]).write(
39-
{"scheduled_information_update": False, "branch_update": False}
39+
{"scheduled_information_update": False, "scheduled_branch_update": False}
4040
)
4141
# be sure some expected values are set otherwise homepage may fail
4242
cls.platform = cls.env["vcp.platform"].create(
@@ -71,7 +71,7 @@ def test_platform_branch_update_no_definition(self):
7171
"name": "test_repo",
7272
"description": "Test Repository",
7373
"platform_id": self.platform.id,
74-
"branch_update": True,
74+
"scheduled_branch_update": True,
7575
"from_date": Date.today(),
7676
}
7777
)
@@ -98,7 +98,7 @@ def dummy_update_information(oself, *args, **kwargs):
9898
"description": "Test Repository",
9999
"platform_id": oself.id,
100100
"scheduled_information_update": True,
101-
"branch_update": True,
101+
"scheduled_branch_update": True,
102102
"from_date": Date.today(),
103103
}
104104
)

vcp_management/views/vcp_platform.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@
6060
name="default_repository_scheduled_information_update"
6161
widget="boolean_toggle"
6262
/>
63+
<field
64+
name="default_repository_scheduled_branch_update"
65+
widget="boolean_toggle"
66+
/>
6367
<field name="rule_ids" widget="many2many_tags" />
6468
</group>
6569
<notebook>

vcp_management/views/vcp_repository.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
name="scheduled_information_update"
8585
widget="boolean_toggle"
8686
/>
87-
<field name="branch_update" />
87+
<field name="scheduled_branch_update" widget="boolean_toggle" />
8888
<field name="rule_ids" widget="many2many_tags" />
8989
<field name="override_parent_rules" />
9090
<field name="from_date" />
@@ -146,6 +146,11 @@
146146
widget="boolean_toggle"
147147
optional="hide"
148148
/>
149+
<field
150+
name="scheduled_branch_update"
151+
widget="boolean_toggle"
152+
optional="hide"
153+
/>
149154
</list>
150155
</field>
151156
</record>

0 commit comments

Comments
 (0)