[NEW] Add State field and buttons to manipulate its value

This commit is contained in:
Stéphan Sainléger
2022-03-05 17:23:14 +01:00
parent 6a9535ee5c
commit 3dd1f5df6e
2 changed files with 21 additions and 0 deletions

View File

@@ -15,3 +15,19 @@ class MajorityJudgementVote(models.Model):
grade_ids = fields.One2many("grade", "vote_id", string=_("Grades")) grade_ids = fields.One2many("grade", "vote_id", string=_("Grades"))
candidate_ids = fields.One2many("candidate", "vote_id", string=_("Candidate")) candidate_ids = fields.One2many("candidate", "vote_id", string=_("Candidate"))
voter_ids = fields.One2many("voter", "vote_id", string=_("Voters")) voter_ids = fields.One2many("voter", "vote_id", string=_("Voters"))
state = fields.Selection(
[("draft", "Draft"), ("opened", "Opened"), ("closed", "Closed")],
string=_("Status"),
index=True,
readonly=True,
default="draft",
track_visibility="onchange",
copy=False,
)
def action_open_vote(self):
self.state = "opened"
def action_close_vote(self):
self.state = "closed"

View File

@@ -20,6 +20,11 @@
<field name="priority">0</field> <field name="priority">0</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Majority Judgement Vote"> <form string="Majority Judgement Vote">
<header>
<button name="action_open_vote" string="Open vote" type="object" attrs="{'invisible':[('state','!=','draft')]}" class="oe_highlight" />
<button name="action_close_vote" string="Close vote" type="object" attrs="{'invisible':[('state','!=','opened')]}" class="oe_highlight" />
<field name="state" widget="statusbar" nolabel="1" statusbar_visible="draft,opened,closed" />
</header>
<sheet string="Majority Judgement Vote"> <sheet string="Majority Judgement Vote">
<group name="general_info"> <group name="general_info">
<field name="name" /> <field name="name" />