# -*- coding: utf-8 -*- from odoo import models, fields, api, _ import base64 import os from odoo.modules import get_module_path from datetime import datetime, date from dateutil.relativedelta import relativedelta from odoo.exceptions import UserError class FamilyInfo(models.Model): _name = 'family.infos' _inherit = ['mail.thread'] _description = 'Family Info' _rec_name = 'no_family' house_no = fields.Char('House No') street = fields.Char('No') province_id = fields.Many2one('address.address',domain="[('loc_code', '=', '1')]") district_id = fields.Many2one('address.address',domain="[('loc_code', '=', '2')]") commune_id = fields.Many2one('address.address',domain="[('loc_code', '=', '3')]") village_id = fields.Many2one('address.address',domain="[('loc_code', '=', '4')]") cpp_info = fields.One2many('family.cpp','family_info_id',string="ព័ត៌មានសមាជិកគ្រួសារ") no_family = fields.Char('Family No') rue_field = fields.Char('Rue') date_created = fields.Date('Date Created Book') class youth_and_scholarship(models.Model): _name = 'youth.scholarship' _description = 'UYFC' _rec_name = 'Kname' name = fields.Char(string='Name') Code_id = fields.Char(string='អត្តលេខ៖') Kname = fields.Char(string='គោត្តនាម នាម') Ename = fields.Char(string='ជាឡាតាំង') Gender = fields.Many2one('gender.gender', string='ភេទ') Nationality = fields.Many2one('nationality.nat', 'សញ្ជាតិ') DOB = fields.Date(string='ថ្ងៃខែឆ្នាំកំណើត') POD = fields.One2many('get.add.pod','info_id', string='ទីកន្លែងកំណើត') Job_id = fields.Char(default='Youth', track_visibility='onchange') Address = fields.One2many('get.address','info_id', string='ទីកន្លែងបច្ចុប្បន្ន') Phone = fields.Char(string='លេខទូស័ព្ទ') Emergency_con = fields.Char(string='Emergency Contact') Email = fields.Char(string='អ៊ីម៉ែល') image = fields.Binary(string='រូបថត') Job_work = fields.Many2many('job.work', string='មុខរបរ') department_id = fields.Many2many('departmet.sys', string='ផ្នែក') instituation_id = fields.Many2many('instituation.sys', string='ក្រសួង/ ស្ថាប័ន') position_id = fields.Many2many('position.sys', string='ឋានៈ') organize_id = fields.Many2many('organize.sys', string='អគ្គនាយកដ្ឋាន/ អង្គភាព') youth_kind = fields.Many2one('youth.kind', string='ប្រភេទយុវជន ') member_in = fields.One2many('get.add.member','info_id', string='ចុះនៅ') Skill_id = fields.Integer(string='ជំនាញ') id_unit = fields.Char(string='អត្តលេខអង្គភាព') Alive_id = fields.Many2one('alive.status', string='ស្ថានភាពគ្រួសារ') status = fields.Char(default="input") Input_by = fields.Many2one('res.users', 'បញ្ជូលដោយ', default=lambda self: self.env.user) history_job_id = fields.One2many('history.job','info_id', string='ប្រវត្តិការងារ') history_study_id = fields.One2many('history.studys','info_id', string='ប្រវត្តិសិក្សា') assurance_id = fields.One2many('assurances.youth','info_id', string='អ្នកធានាអះអាង និងអ្នកណែរនាំ') parent_id = fields.One2many('mother.mother','info_id', string='ព័ត៌មានគ្រួសារ') evaluation_id = fields.One2many('evaluation.eval', 'youth_id', string='ការវាយតម្លៃ') id_card = fields.Char(string='លេខអត្តសញ្ញាណប័ណ្ណ ឬលិខិតឆ្លងដែន', size=12) El_Office = fields.One2many('get.add.el','youth_id', string='មណ្ឌលបោះឆ្នោត') al_office = fields.Char('ការិយាល័យបោះឆ្នោត') cpp_no = fields.Char('លេខរៀង') nation_id = fields.Many2one('nation.nat', 'ជនជាតិ') fb = fields.Char('Facebook') gmail = fields.Char('Google+') upload_file = fields.Binary(string="ឯកសារយោង") file_name = fields.Char(string="File Name") praise_pr_id = fields.One2many('praise.pr','info_id') punish_pus_id = fields.One2many('punish.pus','info_id') company_id = fields.Many2one('res.company', default=lambda self: self.env.user.company_id.id) active = fields.Boolean(default=True, help="If the active field is set to False, it will allow you to hide the information without removing it.") Approval_by = fields.Many2one('res.users', default=lambda self: self.env.user, string='ទទួលស្គាល់ដោយ') IsDeleted = fields.Integer(default=1) def action_confirm(self): return self.write({'status': 'disapprove'}) def action_cancel(self): return self.write({'status': 'review'}) def action_approval(self): return self.write({'status': 'approval'}) def action_cancel_review(self): return self.write({'IsDeleted': 0}) class Job_work(models.Model): _name = 'job.work' _description = 'Job' _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] name = fields.Char(string='ឈ្មោះមុខរបរ') class Position_sys(models.Model): _name = 'position.sys' _description = 'Position' _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] name = fields.Char(string='ឋានៈ') class department_sys(models.Model): _name = 'departmet.sys' _description = 'Department' _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] name = fields.Char(string='ឈ្មោះផ្នែក') class instituation_sys(models.Model): _name = 'instituation.sys' _description = 'Instituation' name = fields.Char(string='ឈ្មោះស្ថាប័ន') class Youth_kind(models.Model): _name = 'youth.kind' _description = 'Kind' name = fields.Char(string='ប្រភេទ') parent_id = fields.Many2one('youth.kind', ondelete='cascade', string='ប្រភេទ') child_id = fields.One2many('youth.kind', 'parent_id', string='Child Youth') _parent_name = "parent_id" _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] class alive_status(models.Model): _name = 'alive.status' _description = 'Status' name = fields.Char(string='ស្ថានភាពគ្រួសារ') _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] class organize_sys(models.Model): _name = 'organize.sys' _description = 'system' name = fields.Char(string='ឈ្មោះអង្គភាព') _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] class mother_mother(models.Model): _name = 'mother.mother' _description = 'Mother' _rec_name = "Kname" info_id = fields.Many2one('youth.scholarship') name = fields.Char(string='Name') Kname = fields.Char(string='គោត្តនាម-នាម (ភាសាខ្មែរ)') Ename = fields.Char(string='គោត្តនាម-នាម (ឡាតាំង)') Gender = fields.Many2one('gender.gender', 'ភេទ') situation = fields.Many2one(comodel_name='situation.sys', string='ស្ថានភាព') Email = fields.Char(string='អ៊ីម៉ែល') Dob = fields.Date(string='ថ្ងៃខែឆ្នាំកំណើត') Pod = fields.Many2many('get.add.pod', string='ទីកន្លែងកំនើត') Add = fields.Many2many('get.address', string='អាស័យដ្ឋានបច្ចុប្បន្ន') Age = fields.Char() acc = fields.Many2one(comodel_name='job.work', string='មុខរបរ') Phone = fields.Char(string='លេខទូស័ព្ទ') position_id = fields.Many2one(comodel_name='position.sys', string='ឋានៈ') organize_id = fields.Many2one(comodel_name='organize.sys', string='អង្គភាព') department_id = fields.Many2one(comodel_name='departmet.sys', string='ផ្នែក') instituation_id = fields.Many2one(comodel_name='instituation.sys', string='ស្ថាប័ន') id_card = fields.Char(string='លេខអត្តសញ្ញាណប័ណ្ណសញ្ជាតិខ្មែរ') id_unit = fields.Char(string='អត្តលេខអង្គភាព') type_postion = fields.Selection([('h', 'ប្តី'), ('w', 'ប្រពន្ធ'), ('c', 'កូន'), ('sb', 'បង-ប្អូនបង្កើត'), ('f', 'ឪពុកបង្កើត'), ('m', 'ម្តាយបង្កើត'), ('fd', 'ឪពុកធម៌'), ('md', 'ម្តាយធម៌'), ('g', 'អាណាព្យាបាល')], default='h', string='ទំនាក់ទំនងក្នុងគ្រួសារ') number_child = fields.Integer('ចំនួនកូន') num_d = fields.Integer('ស្រី') class situation_sys(models.Model): _name = 'situation.sys' _description = 'Situation' name = fields.Char(string='ឈ្មោះ') class gender_gender(models.Model): _name = 'gender.gender' _description = 'Gender' name = fields.Char(string='ភេទ', required=True) _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] class nationality_nat(models.Model): _name = 'nationality.nat' _description = 'Nationality' name = fields.Char(string='សញ្ជាតិ') _sql_constraints = [ ('name', 'unique(name)', 'name already exists!'), ] class address_add(models.Model): _name = 'address.add' _inherit = 'address.address' _description = 'Address' # loc_code = fields.Char() class workingDays(models.TransientModel): _name = "wizard.working.days" _description = 'Wizard Form' days = fields.Float(string="Working Days", default=30, required=True) def calc(self): tickets = self.env['youth.scholarship'].browse(self._context.get('active_ids')) tickets.write({'IsDeleted': 0}) def ref_dis(self): tickets = self.env['ref.reference'].browse(self._context.get('active_ids')) tickets.write({'status': 0}) class restore_youth(models.Model): _name = 'restore.youth' _description = 'Restore Data' def rest(self): tickets = self.env['youth.scholarship'].browse(self._context.get('active_ids')) tickets.state='sent' tickets.status = 'review' tickets.write({'IsDeleted': 1}) class uni(models.Model): _name = 'uni.university' _description = 'University' _rec_name = 'Kname' Kname = fields.Char(string="ឈ្មោះសកលវិទ្យាល័យ(ជាភាសាខ្មែរ)") Ename = fields.Char(string="ឈ្មោះសកលវិទ្យាល័យ(ជាឡាតាំង)") Phone = fields.Char(string="លេខទូរស័ព្ទ") Fax = fields.Char(string="លេខទូរសារ") Email = fields.Char(string="អ៊ីម៉ែល") Website = fields.Char(string="វេបសាយ") Address = fields.Many2one('address.address', string="ទីតាំង") class ref(models.Model): _name = 'ref.reference' _description = 'Reference' Kname = fields.Char(string="ឈ្មោះអ្នកធានា(ជាភាសាខ្មែរ)") Ename = fields.Char(string="ឈ្មោះអ្នកធានា(ជាឡាតាំង)") Gender = fields.Many2one('gender.gender', string="ភេទ") DOB = fields.Date(string="ថ្ងៃខែឆ្នាំកំណើត") Email = fields.Char(string="អ៊ីម៉ែល") status = fields.Integer(default=1, string='ស្ថានភាព') class scholarship_sponsor(models.Model): _name = 'scholarship.sponsor' _description = 'Sponsor' _rec_name = 'spKname' spKname = fields.Char(string='ឈ្មោះអ្នកឧបត្ថម(ជាភាសាខ្មែរ)') spEname = fields.Char(string='ឈ្មោះអ្នកឧបត្ថម(ជាឡាតាំង)') class history_study(models.Model): _name = 'history.studys' _description = 'History' info_id = fields.Many2one('youth.scholarship') date_in = fields.Date(string="ថ្ងៃខែឆ្នាំចូល") date_out = fields.Date(string="ថ្ងៃខែឆ្នាំចេញ") degree_level = fields.Many2one('degree.level') kill_id = fields.Many2one('skill.study') university_id = fields.Many2one('uni.university') country = fields.Many2one('country.country') class history_job(models.Model): _name = 'history.job' _description = 'Job' info_id = fields.Many2one('youth.scholarship') # worker_id = fields.Many2one('system.worker') date_in = fields.Date(string="ថ្ងៃខែឆ្នាំចូល") date_out = fields.Date(string="ថ្ងៃខែឆ្នាំចេញ") job_id = fields.Many2one('job.work') depart_id = fields.Many2one('departmet.sys') posit_id = fields.Many2one('position.sys') department_gen = fields.Many2one('organize.sys', string='អង្គភាព') leader = fields.Char('Leader') country_id = fields.Many2one('res.country', string='Country') province_id = fields.Many2one('address.address', string='រាជធានី-ខេត្ដ', domain="[('loc_code', '=', '1')]") other = fields.Char(string="កន្លែងផ្សេងទៀត") organize = fields.Many2one('instituation.sys') @api.model def start_selection(self): end_years = 1992 # replace 2000 with your a start year year_list = [] while end_years != 2031: # replace 2030 with your end year year_list.append((str(end_years), str(end_years))) end_years += 1 return year_list def end_selection(self): end_years = 1992 # replace 2000 with your a start year year_list = [] while end_years != 2031: # replace 2030 with your end year year_list.append((str(end_years), str(end_years))) end_years += 1 return year_list start_dates = fields.Selection(selection='start_selection', string="ឆ្នាំ ចូលសិក្សា", default='2000') end_dates = fields.Selection(selection='end_selection', string="ឆ្នាំ បញ្ចប់សិក្សា", default='2000') class skill(models.Model): _name = 'skill.study' _description = 'Skill' name = fields.Char() class degree_level(models.Model): _name = 'degree.level' _description = 'Level' name = fields.Char() class country(models.Model): _name = 'country.country' _description = 'Country' name = fields.Char() class assurance(models.Model): _name = 'assurances.youth' _description = 'assurance' _rec_name = 'askname' info_id = fields.Many2one('youth.scholarship') askname = fields.Char(string="គោត្ដនាម និងនាម") asename = fields.Char(string="ជាអក្សឡាតាំង") gender = fields.Many2one('gender.gender',string="ភេទ") dob = fields.Date(string="ថ្ងៃខែឆ្នាំកំណើត") email = fields.Char(string="អ៊ីម៉ែល") phone = fields.Char(string="លេខទូរស័ព្ទ") pod = fields.One2many('assurance.pod','assurance_id',string="ទីកន្លែងកំណើត") address = fields.One2many('assurance.address','assurance_id',string="ទីកន្លែងបច្ចុប្បន្ន") job = fields.Many2one('job.work',string="មុខរបរ") position = fields.Many2one('position.sys',string="ជំនាញ") department = fields.Many2one('departmet.sys',string="ការិយាល័យ") organization = fields.Many2one('organize.sys',string="អង្គការ") insituation = fields.Many2one('instituation.sys',string="អង្គភាព/ស្ថាប័ន") card_id = fields.Char(string="អត្ដសញ្ញាណបណ្ណ") code_id = fields.Char(string="អត្ដលេខ") date_signal = fields.Date(string="ថ្ងៃចុះហត្ថលេខខា") type_postion = fields.Selection([('as', 'អ្នកធានាអះអាង'), ('f', 'អ្នកណែរនាំ'), ('b', 'អ្នកធានាអះអាង និងណែរនាំ')], default='as', string='អ្នកធានាអះអាង និងណែរនាំ') class AssurancePod(models.Model): _name = 'assurance.pod' _description = 'Add Pod' assurance_id = fields.Many2one('assurances.youth') province_id = fields.Many2one('address.address', 'ខេត្ត/ ក្រុង', domain="[('loc_code', '=', '1')]") district_id = fields.Many2one('address.address', 'ស្រុក/ ខណ្ឌ', domain="[('parent_location', '=', province_id)]") commune_id = fields.Many2one('address.address', 'ឃុំ/ សង្កាត់', domain="[('parent_location', '=', district_id)]") village_id = fields.Many2one('address.address', 'ភូមិ', domain="[('parent_location', '=', commune_id)]") class AssuranceAddress(models.Model): _name = 'assurance.address' _description = 'assurance address' assurance_id = fields.Many2one('assurances.youth') province_id = fields.Many2one('address.address', 'ខេត្ត/ ក្រុង', domain="[('loc_code', '=', '1')]") district_id = fields.Many2one('address.address', 'ស្រុក/ ខណ្ឌ', domain="[('parent_location', '=', province_id)]") commune_id = fields.Many2one('address.address', 'ឃុំ/ សង្កាត់', domain="[('parent_location', '=', district_id)]") village_id = fields.Many2one('address.address', 'ភូមិ', domain="[('parent_location', '=', commune_id)]") street = fields.Char(string='ផ្លូវលេខ') No = fields.Char(string='ផ្ទះលេខ') group = fields.Char(string='ក្រុម') class get_address(models.Model): _name = 'get.address' _description = 'get Address' info_id = fields.Many2one('youth.scholarship') member_id = fields.Many2one('family.cpp') # worker_id = fields.Many2one('system.worker') province_id = fields.Many2one('address.address', 'ខេត្ត/ ក្រុង', domain="[('loc_code', '=', '1')]") district_id = fields.Many2one('address.address', 'ស្រុក/ ខណ្ឌ', domain="[('parent_location', '=', province_id)]") commune_id = fields.Many2one('address.address', 'ឃុំ/ សង្កាត់', domain="[('parent_location', '=', district_id)]") village_id = fields.Many2one('address.address', 'ភូមិ', domain="[('parent_location', '=', commune_id)]") street = fields.Char(string='ផ្លូវលេខ') No = fields.Char(string='ផ្ទះលេខ') group = fields.Char(string='ក្រុម') class get_add_pod(models.Model): _name = 'get.add.pod' _description = 'Get add POD' info_id = fields.Many2one('youth.scholarship',string="ព័ត៌មាន") cpp_member_id = fields.Many2one('family.cpp') # worker_id = fields.Many2one('system.worker') province_id = fields.Many2one('address.address', 'ខេត្ត/ ក្រុង', index=True, domain="[('loc_code', '=', '1')]") district_id = fields.Many2one('address.address', 'ស្រុក/ ខណ្ឌ', index=True, domain="[('parent_location', '=', province_id)]") commune_id = fields.Many2one('address.address', 'ឃុំ/ សង្កាត់', index=True, domain="[('parent_location', '=', district_id)]") village_id = fields.Many2one('address.address', 'ភូមិ', index=True, domain="[('parent_location', '=', commune_id)]") street = fields.Char(string='ផ្លូវលេខ') No = fields.Char(string='ផ្ទះលេខ') group = fields.Char(string='ក្រុម') class get_add_el(models.Model): _name = 'get.add.el' _description = 'get Add El' youth_id = fields.Many2one('youth.scholarship') province_id = fields.Many2one('address.address', 'ខេត្ត/ ក្រុង', index=True, domain="[('loc_code', '=', '1')]") district_id = fields.Many2one('address.address', 'ស្រុក/ ខណ្ឌ', index=True, domain="[('parent_location', '=', province_id)]") commune_id = fields.Many2one('address.address', 'ឃុំ/ សង្កាត់', index=True, domain="[('parent_location', '=', district_id)]") village_id = fields.Many2one('address.address', 'ភូមិ', index=True, domain="[('parent_location', '=', commune_id)]") street = fields.Char(string='ផ្លូវលេខ') No = fields.Char(string='ផ្ទះលេខ') group = fields.Char(string='ក្រុម') class get_add_member(models.Model): _name = 'get.add.member' _description = 'Get add member' info_id = fields.Many2one('youth.scholarship') province_id = fields.Many2one('address.address', 'ខេត្ត/ ក្រុង', index=True, domain="[('loc_code', '=', '1')]") district_id = fields.Many2one('address.address', 'ស្រុក/ ខណ្ឌ', index=True, domain="[('parent_location', '=', province_id)]") commune_id = fields.Many2one('address.address', 'ឃុំ/ សង្កាត់', index=True, domain="[('parent_location', '=', district_id)]") village_id = fields.Many2one('address.address', 'ភូមិ', index=True, domain="[('parent_location', '=', commune_id)]") street = fields.Char(string='ផ្លូវលេខ') No = fields.Char(string='ផ្ទះលេខ') group = fields.Char(string='ក្រុម') class evaluation(models.Model): _name = 'evaluation.eval' _description = 'evaluation' name = fields.Many2one('res.users', 'បញ្ជូលដោយ', default=lambda self: self.env.user) youth_id = fields.Many2one('youth.scholarship', 'ឈ្មោះសមាជិក') display_name = fields.Char('ឈ្មោះសមាជិក', related='youth_id.Kname', readonly=True, store=True) display_Gender = fields.Many2one(string='Gender', related='youth_id.Gender', readonly=True, store=True) display_DOB = fields.Date(string='DOB', related='youth_id.DOB', readonly=True, store=True) # display_member_in = fields.One2many(string='Address', related='youth_id.member_in', readonly=True, store=True) hit_value = fields.Char() date = fields.Date('កាលបរិច្ឆេទចូលរួមសកម្មភាព') gender = fields.Many2one('gender.gender') position = fields.Many2one('position.sys') department = fields.Many2one('departmet.sys') part_of_point = fields.Many2many('candidate.eval') Date_of_hit = fields.Date() hour = fields.Selection([ ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12'), ('13', '13'), ('14', '14'), ('15', '15'), ('16', '16'), ('17', '17'), ('18', '18'), ('19', '19'), ('20', '20'), ('21', '21'), ('22', '22'), ('23', '23'), ('24', '24')], string='ម៉ោង') sec = fields.Char() condition_eval_id = fields.Many2many('condition.eval') condition_write_id = fields.Many2many('condition.write') self_id = fields.Many2many('condition.self') update = fields.Text() studying = fields.Text() class candidate_eval(models.Model): _name = 'candidate.eval' _description = 'eval' _rec_name = 'score' score = fields.Integer() rank = fields.Char() detail = fields.Char() class condition_eval(models.Model): _name = 'condition.eval' _description = 'Condition' conditions = fields.Many2one('con.eval') commen = fields.Char() score = fields.Many2one('candidate.eval') class con_eval(models.Model): _name = 'con.eval' _description = 'evaluation' _rec_name = 'commen' commen = fields.Char() class con_self(models.Model): _name = 'con.self' _description = 'Self' _rec_name = 'commen' commen = fields.Char() class con_write(models.Model): _name = 'con.write' _description = 'Write' _rec_name = 'commen' commen = fields.Char() class condition_self(models.Model): _name = 'condition.self' _description = 'Writes' con_self = fields.Many2one('con.self') commen = fields.Char() score = fields.Many2one('candidate.eval') class condition_write(models.Model): _name = 'condition.write' _description = 'condition Writes' con_write = fields.Many2one('con.write') commen = fields.Char() score = fields.Many2one('candidate.eval') class config_sys(models.Model): _name = 'config.sys' _description = 'config Write' size = fields.Integer() class nation(models.Model): _name = 'nation.nat' _description = 'nation Write' name = fields.Char('ជនជាតិ') class as_for(models.Model): _name = 'as.for' _description = 'as Write' name = fields.Char() class praise_pr(models.Model): _name = 'praise.pr' _description = 'praise_pr' info_id = fields.Many2one('youth.scholarship') name = fields.Char() date = fields.Date('ថ្ងៃ ខែ ឆ្នាំ') pr_kind = fields.Char('ប្រភេទនៃការសរសើរ') lavels = fields.Char('កំរិតនៃការសរសើរ') upload_file = fields.Binary(string="ឯកសារបញ្ជាក់") file_name = fields.Char(string="File Name") country = fields.Many2one('country.country', 'ប្រទេស') class punish_pus(models.Model): _name = 'punish.pus' _description = 'punish_pus' info_id = fields.Many2one('youth.scholarship') name = fields.Char() date = fields.Date('ថ្ងៃ ខែ ឆ្នាំ') pun_kind = fields.Char('ប្រភេទនៃការដាក់ពិន័យ') lavels = fields.Char('កំរិតនៃការដាក់ពិន័យ') upload_file = fields.Binary(string="ឯកសារបញ្ជាក់") file_name = fields.Char(string="File Name") country = fields.Many2one('country.country', 'ប្រទេស') class cpp_parent(models.Model): _name = 'cpp.parent' _description = 'cpp_parent' _rec_name = 'district' child_cpp_id = fields.One2many('family.cpp', 'cpp_parent_id',string="ព័ត៌មានគ្រួសារ") group = fields.Char(string="ក្រុមបក្សទី") no = fields.Char() street = fields.Char() num_man = fields.Char() num_woman = fields.Char() image_default = fields.Image(string='រូបថត', default=lambda self: self._get_default_image()) district = fields.Many2one('address.address', 'ស្រុក', domain="[('loc_code', '=', '2'),('location_name', '=', 'ទ្រាំង')]") commune = fields.Many2one('address.address', 'គណៈកម្មាធិការគណបក្សឃុំ', domain="[('parent_location','=', district)]") village = fields.Many2one('address.address', 'ភូមិ', domain="[('loc_code','=', '4'),('parent_location','=', commune)]") groups_id = fields.Many2many('res.groups') company_id = fields.Many2one('res.company', default=lambda self: self.env.user.company_id.id) status = fields.Char(default='input') is_delete = fields.Integer(default=1) state = fields.Selection([ ('draft', 'ការបញ្ចូលទិន្នន័យ'), ('sent', 'បញ្ជួនទៅត្រួតពិនិត្យ'), ('app', 'ការអនុម័តជាសមាជិកប្ស'), ('done', 'បញ្ជីសមាជិកបក្ស'), ], string='Status', readonly=True, copy=False, index=True, track_visibility='onchange', default='draft') active = fields.Boolean(default=True, help="If the active field is set to False, it will allow you to hide the information without removing it.") def action_restore(self): self.state = 'sent' self.is_delete = 1 self.status = 'review' return self.write({'status': 'review'}) def action_to_review(self): self.state = 'sent' return self.write({'status': 'review'}) def action_confirm(self): self.state = 'app' return self.write({'status': 'disapprove'}) def action_confirm_cpp(self): self.state = 'done' return self.write({'status': 'approve'}) def action_cancel(self): self.state = 'draft' return self.write({'status': 'input'}) def action_delete(self): return self.write({'is_delete': 0}) def _get_default_image(self): module_path = get_module_path('youth_and_scholarship') if module_path: # 2. Safely join the path segments image_path = os.path.join(module_path, 'static', 'src', 'img', 'photo_frame.png') # 3. Verify the file exists before reading if os.path.isfile(image_path): with open(image_path, 'rb') as f: return base64.b64encode(f.read()) return False def _get_count(self): count_m = self.env['family.cpp'].search([('Gender', '=', 21), ('cpp_parent_id', '=', self.id)]) count_f = self.env['family.cpp'].search([('Gender', '=', 22), ('cpp_parent_id', '=', self.id)]) self.field_count_m = len(count_m) self.field_count_f = len(count_f) self.totals_member = len(count_m) + len(count_f) totals_member = fields.Char(compute='_get_count') field_count_m = fields.Integer(compute='_get_count') field_count_f = fields.Integer(compute='_get_count') class family_cpp(models.Model): _name = 'family.cpp' _description = 'family_cpp' _rec_name = 'kname' image = fields.Binary(string='រូបថត', default=lambda self: self._get_default_image()) name = fields.Char(string="អក្សឡាតាំង") kname = fields.Char('គោត្តនាម-នាម') no_card = fields.Char('លេខប័ណ្ណសមាជិកបក្ស') group = fields.Integer('ក្រុមបក្សទី') pod = fields.One2many('get.add.pod','cpp_member_id', string='ទីកន្លែងកំណើត') Job_work = fields.Many2one('job.work', 'មុខរបរ') date_in = fields.Date('ថ្ងៃ ខែ ឆ្នាំ ចូលបក្ស') other = fields.Char('ផ្សេងៗ') type_postion = fields.Many2one('as.for', string='ទំនាក់ទំនងក្នុងគ្រួសារបក្ស') status = fields.Char(string="ស្ថានភាពក្នុងសៀវភៅគ្រួសារបក្ស") parent_id = fields.Many2one('family.cpp', string='ព័ត៌មានមេគ្រួសារ') child_id = fields.One2many('family.cpp','parent_id', string='ព័ត៌មានសមាជិកគ្រួសារ') id_card = fields.Char(string='លេខអត្តសញ្ញាណប័ណ្ណ') status_family = fields.Selection([('1','នៅលីវ'),('2','មានគ្រួសារ'),('3','លែងលះ')],string='ស្ថានភាពផ្ទាល់ខ្លួន') Gender = fields.Many2one('gender.gender', string='ភេទ', required=True) dob = fields.Date('ថ្ងៃ ខែ ឆ្នាំកំណើត') years = fields.Char('អាយុ') @api.onchange('dob') def set_date(self): for rec in self: if rec.dob: dt = rec.dob d1 = datetime.strptime(str(dt), "%Y-%m-%d").date() d2 = date.today() rd = relativedelta(d2, d1) rec.years = str(rd.years) + ' ឆ្នាំ' parent_record = fields.Selection([('1', 'មេ'), ('2', 'កូន') ], 'មេគ្រួសារ/កូន') post_in_family = fields.Selection([('1','មេគ្រួសារ'),('2','ប្រពន្ធ'),('3','ប្ដី'),('4','កូន')],string="តួនាទីក្នុងគ្រួសារ") ps_id = fields.Char(string='ការិយាល័យបោះឆ្នោត') no_ps = fields.Char(string='លេខរៀង') el_Office = fields.One2many('get.address','member_id', string='មណ្ឌលបោះឆ្នោត') position_id = fields.Many2many('position.sys') organize_id = fields.Many2many('organize.sys') instite_id = fields.Many2many('instituation.sys') phone_id = fields.Char(string="លេខទូរស័ព្ទ") email_id = fields.Char() facebook = fields.Char() telegram = fields.Char() time = fields.Char() family_info_id = fields.Many2one('family.infos', string='សៀវភៅគ្រួសារ') status_now = fields.Selection([('1', 'ស្លាប់'),('2', 'ផ្លាស់ប្ដូទីលំនៅ'),('3', 'សំណាកស្រុក'),('4', 'ផ្សេងៗ')],string="បច្ចុប្បន្នភាពសមាជិក") other_status = fields.Char(string="ស្ថានភាពបច្ចុប្បន្នរបស់សមាជិកផ្សេងៗ") @api.constrains('id_card') # Time is Many2one def _check_existing(self): if self.id_card != False: counts = self.env['family.cpp'].search_count([('id_card', '=', self.id_card)]) # counts_null = self.env['family.cpp'].search_count([('id_card', '=', False)]) if counts >= 2: raise UserError(_("លេខអត្តសញ្ញាណប័ណ្ឌនេះមានរួចហើយ: %s" % self.id_card)) def dup_line(self): self.copy(default={'cpp_parent_id': self.cpp_parent_id.id}) def _get_default_image(self): module_path = get_module_path('youth_and_scholarship') if module_path: # 2. Safely join the path segments image_path = os.path.join(module_path, 'static', 'src', 'img', 'photo_frame.png') # 3. Verify the file exists before reading if os.path.isfile(image_path): with open(image_path, 'rb') as f: return base64.b64encode(f.read()) return False status_id_card = fields.Selection([('1', 'បាត់'), ('2', 'ខូច')], string="ស្ថានភាពលេខអត្តសញ្ញាណប័ណ្ណសញ្ជាតិខ្មែរ") id_card_ex = fields.Date(string='មានសុពលភាពដល់ថ្ងៃទី') cpp_parent_id = fields.Many2one('cpp.parent', store=True) id_parent = fields.Integer(related='cpp_parent_id.id', readonly=True, store=True, string="លេខសម្គាល់") district_id = fields.Many2one(related='cpp_parent_id.district', readonly=True, store=True) commune_id = fields.Many2one(related='cpp_parent_id.commune', readonly=True, store=True) village_id = fields.Many2one(related='cpp_parent_id.village', readonly=True, store=True) status_id = fields.Char(related='cpp_parent_id.status', readonly=True, store=True) is_delete_id = fields.Integer(related='cpp_parent_id.is_delete', readonly=True, store=True) active = fields.Boolean(default=True, help="If the active field is set to False, it will allow you to hide the information without removing it.") state_id = fields.Selection(related='cpp_parent_id.state', readonly=True, store=True) group_id = fields.Char(related='cpp_parent_id.group', readonly=True, store=True) status_member = fields.Selection([('1', 'ស'), ('2', 'ប្រផេះ'), ('3', 'លឿង')], string="ស្ថានភាពសមាជិក", default='1') old = fields.Many2many('old.old', string="ព័ត៌មានបោះឆ្នោត") def Removes(self): self.status = 'remove' class disable_data(models.Model): _name = 'disable.data' _description = 'disable_data' def disable(self, context=None): for emp in self.env['cpp.parent'].search: return self.write([emp.ids], {"is_delete": 0}) return True class restore_data(models.Model): _name = 'restore.data' _description = 'restore_data' def restore(self): cpp_data = self.env['cpp.parent'] for emps in cpp_data.browse(self.ids): cpp_data.write({"is_delete": 1}) return True class VillageResult(models.Model): _name = 'village.result' _rec_name = 'position' _description = 'VillageResult' province = fields.Many2one('address.address', 'ខេត្ត', domain="[('loc_code', '=', '1')]", default=lambda self: self.env['address.address'].search([('location_name', '=', 'តាកែវ')])) district = fields.Many2one('address.address', 'ស្រុក', domain="[('parent_location', '=', province)]", default=lambda self: self.env['address.address'].search([('location_name', '=', 'ទ្រាំង')])) commune = fields.Many2one('address.address', 'ឃុំ', domain="[('parent_location','=', district)]") village = fields.Many2one('address.address', 'ភូមិ', domain="[('parent_location','=',commune)]") sub_result = fields.One2many('sub.result', 'main_id') position = fields.Char(default="ឃុំ") years = fields.Many2one('khmer.years', 'ឆ្នាំ', required=True) class SubResult(models.Model): _name = 'sub.result' _description = 'SubResult' main_id = fields.Many2one('village.result') district_id = fields.Many2one(related='main_id.district', readyonly=True, store=True) commune_id = fields.Many2one(related='main_id.commune', readonly=True, store=True) village_id = fields.Many2one(related='main_id.village', readonly=True, store=True) year_name = fields.Many2one(related='main_id.years', readonly=True, store=True) no = fields.Char(string='ល.រ') ps_id = fields.Char('ការិយាល័យបោះឆ្នោត') party_name = fields.Many2one('party.name', 'ឈ្មោះគណបក្ស') result = fields.Integer('លទ្ធផល') member_cpp = fields.Integer("សមាជិកបក្ស") class PartyName(models.Model): _name = 'party.name' _description = 'PartyName' name = fields.Char() year_id = fields.Many2one("khmer.years") class KhmerYears(models.Model): _name = 'khmer.years' _description = 'khmer Write' name = fields.Char(string='ឆ្នាំ') party = fields.One2many("party.name", 'year_id') # party = fields.Char('អង្គបោះឆ្នោត') class OLD(models.Model): _name = 'old.old' ps_id = fields.Char(string="លេខការិយាល័យបោះឆ្នោត") no_ps = fields.Char(string="លេខរៀង") time = fields.Many2many('time.time',string="បោះឆ្នោតបានចំនួន") class time_time(models.Model): _name = 'time.time' _description = 'Number of vote' name = fields.Integer(string='Number')