|
| 1 | +import logging |
| 2 | + |
| 3 | +from odoo import Command, api, models |
| 4 | + |
| 5 | +_logger = logging.getLogger(__name__) |
| 6 | + |
| 7 | + |
| 8 | +class ChangeRequestBaseCustomDemo(models.Model): |
| 9 | + _inherit = "spp.change.request" |
| 10 | + |
| 11 | + def create_request_detail_demo(self): |
| 12 | + """ |
| 13 | + A version of spp.change.request create_request_detail function |
| 14 | + that does not check the applicant's phone number and |
| 15 | + does not load the CR details form |
| 16 | + :return: |
| 17 | + """ |
| 18 | + for rec in self: |
| 19 | + if rec.state in ("draft", "pending"): |
| 20 | + # Set the request_type_ref_id |
| 21 | + res_model = rec.request_type |
| 22 | + # Set the dms directory |
| 23 | + _logger.debug("Change Request: DMS Directory Creation (%s)" % len(self.dms_directory_ids)) |
| 24 | + self.env.ref(self.env[res_model].DMS_STORAGE) |
| 25 | + dmsval = { |
| 26 | + "is_root_directory": True, |
| 27 | + "name": rec.name, |
| 28 | + } |
| 29 | + |
| 30 | + # Prepare CR type model data |
| 31 | + cr_type_vals = { |
| 32 | + "registrant_id": rec.registrant_id.id, |
| 33 | + "applicant_id": rec.applicant_id.id, |
| 34 | + "change_request_id": rec.id, |
| 35 | + "dms_directory_ids": [(Command.create(dmsval))], |
| 36 | + } |
| 37 | + |
| 38 | + # Create the change request detail record |
| 39 | + ref_id = self.env[res_model].create(cr_type_vals) |
| 40 | + directory_id = ref_id.dms_directory_ids[0].id |
| 41 | + |
| 42 | + self.env["spp.dms.directory"].create( |
| 43 | + { |
| 44 | + "name": "Applicant", |
| 45 | + "parent_id": directory_id, |
| 46 | + "is_root_directory": False, |
| 47 | + } |
| 48 | + ) |
| 49 | + |
| 50 | + # Upload Scanned IDs to DMS |
| 51 | + dms_file_ids = [] |
| 52 | + for id_fld in ["id_document_details", "qr_code_details"]: |
| 53 | + if rec[id_fld]: |
| 54 | + dms_id_doc = rec._get_id_doc_vals(directory_id, id_fld) |
| 55 | + if dms_id_doc: |
| 56 | + dms_file_ids.append(Command.create(dms_id_doc)) |
| 57 | + if dms_file_ids: |
| 58 | + ref_id.update({"dms_file_ids": dms_file_ids}) |
| 59 | + |
| 60 | + ref_id._onchange_registrant_id() |
| 61 | + request_type_ref_id = f"{res_model},{ref_id.id}" |
| 62 | + _logger.debug("DEBUG! request_type_ref_id: %s", request_type_ref_id) |
| 63 | + rec.update( |
| 64 | + { |
| 65 | + "request_type_ref_id": request_type_ref_id, |
| 66 | + "id_document_details": "", |
| 67 | + } |
| 68 | + ) |
| 69 | + |
| 70 | + # Temporary solution to phone number fo |
| 71 | + # def _check_phone_exist(self): |
| 72 | + # pass |
| 73 | + |
| 74 | + @api.constrains("registrant_id", "applicant_phone") |
| 75 | + def _check_applicant_phone(self): |
| 76 | + # Temporary solution to phone number format error |
| 77 | + pass |
0 commit comments