first push message
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
# cpp_entry/models/cpp_entry.py
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class CppEntry(models.Model):
|
||||
_name = 'cpp.entry'
|
||||
_description = 'CPP Patient Treatment Entry'
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
_order = 'create_date desc'
|
||||
|
||||
active = fields.Boolean(default=True, string="សកម្ម")
|
||||
|
||||
# Location fields (adjust model names to match your address module)
|
||||
province_id = fields.Many2one('address.address', string="ខេត្ត/ក្រុង (Province)")
|
||||
district_id = fields.Many2one('address.address', string="ស្រុក/ខណ្ឌ (District)")
|
||||
commune_id = fields.Many2one('address.address', string="ឃុំ/សង្កាត់ (Commune)")
|
||||
al_office = fields.Char(string="ការិយាល័យបោះឆ្នោត")
|
||||
company_id = fields.Many2one('res.company', string="Company")
|
||||
|
||||
# One2many to voters - note: field name ends with _ids per Odoo convention
|
||||
info_ids = fields.One2many(
|
||||
'info.voter',
|
||||
'cpp_entry',
|
||||
string="បញ្ជីឈ្មោះអ្នកមិនទាន់បោះឆ្នោត"
|
||||
)
|
||||
|
||||
# Computed fields for display
|
||||
voter_count = fields.Integer(
|
||||
string="ចំនួនអ្នកបោះឆ្នោត",
|
||||
compute='_compute_voter_counts',
|
||||
store=False
|
||||
)
|
||||
non_voter_count = fields.Integer(
|
||||
string="ចំនួនអ្នកមិនទាន់បោះឆ្នោត",
|
||||
compute='_compute_voter_counts',
|
||||
store=False
|
||||
)
|
||||
|
||||
@api.depends('info_ids', 'info_ids.status_vote')
|
||||
def _compute_voter_counts(self):
|
||||
for record in self:
|
||||
record.voter_count = len(record.info_ids.filtered(lambda r: r.status_vote))
|
||||
record.non_voter_count = len(record.info_ids.filtered(lambda r: not r.status_vote))
|
||||
|
||||
class MemberCpp(models.Model):
|
||||
_name = 'person.member'
|
||||
_inherit = ['mail.thread', 'mail.activity.mixin']
|
||||
_description = 'CPP Patient Treatment Entry'
|
||||
|
||||
name = fields.Char(string="ឈ្មោះគណបក្ស")
|
||||
short_name = fields.Char(string="ឈ្មោះខ្លី")
|
||||
|
||||
class InfoVoter(models.Model):
|
||||
_name = 'info.voter'
|
||||
_description = 'Voter Information'
|
||||
_order = 'name'
|
||||
|
||||
cpp_entry = fields.Many2one(
|
||||
'cpp.entry',
|
||||
string="CPP Entry",
|
||||
)
|
||||
|
||||
# Personal Info
|
||||
photo = fields.Binary(string="រូបថត", attachment=True)
|
||||
name = fields.Char(string="ឈ្មោះ", required=True, index=True)
|
||||
gender = fields.Many2one('gender.gender', string="ភេទ")
|
||||
dob = fields.Date(string="ថ្ងៃខែឆ្នាំកំណើត")
|
||||
phone = fields.Char(string="លេខទូរស័ព្ទ")
|
||||
address = fields.Char(string="អាសយដ្ឋាន")
|
||||
status = fields.Selection([('1','សមាជិក'),('2','មិនមែនសមាជិក')],string="ស្ថានភាពសមាជិក")
|
||||
cpp_member=fields.Many2one('person.member',string="សមាជិកគណបក្ស")
|
||||
current_time = fields.Datetime(string="Date Checked")
|
||||
# Voting Status
|
||||
status_vote = fields.Boolean(
|
||||
string="បានបោះឆ្នោត",
|
||||
default=False,
|
||||
help="Check if this person has already voted"
|
||||
)
|
||||
|
||||
# Metadata
|
||||
create_date = fields.Datetime(string="ថ្ងៃបង្កើត", readonly=True)
|
||||
|
||||
@api.constrains('name')
|
||||
def _check_name(self):
|
||||
for record in self:
|
||||
if record.name and len(record.name.strip()) < 2:
|
||||
raise ValidationError(_('ឈ្មោះត្រូវមានយ៉ាងតិច ២ តួអក្សរ'))
|
||||
Reference in New Issue
Block a user