diff --git a/yuthon_property_approval/wizard/property_rental_wizard.py b/yuthon_property_approval/wizard/property_rental_wizard.py index c16d0d28a..3fc1db4f6 100644 --- a/yuthon_property_approval/wizard/property_rental_wizard.py +++ b/yuthon_property_approval/wizard/property_rental_wizard.py @@ -22,7 +22,6 @@ class PropertyRentalWizard(models.Model): '生成租金明细‘ :return: """ - rent_monthly = 0 monthly_records = self.env['property.lease.contract'].search([('cycle_dict', '=', 'monthly')]) year = int(self.select_year) month = int(self.select_month) @@ -36,12 +35,54 @@ class PropertyRentalWizard(models.Model): date_field_year_month = date_field.strftime('%Y-%m') if start_date_year_month <= date_field_year_month < end_date_year_month: rent_monthly = rent_id.monthly_amount + start_date = rent_id.start_data + if record.lease_ids: + property_id = record.lease_ids[0].address_id.id + else: + property_id = None + self.sudo().env["property.rent.list"].create({ + "contract_id": record.id, + "contract_code": record.code, + "due_date": start_date, + "property_id":property_id, + "lessee_id":record.lessee_id.id, + "original_amount": rent_monthly, + "year": self.select_year, + 'month': self.select_month, + }) elif start_date_year_month <= date_field_year_month <= end_date_year_month: end_days = rent_id.end_data.day if end_days < days: + if record.lease_ids: + property_id = record.lease_ids[0].address_id.id + else: + property_id = None rent_monthly = rent_id.monthly_amount + start_date = rent_id.start_data + self.sudo().env["property.rent.list"].create({ + "contract_id": record.id, + "contract_code": record.code, + "property_id":property_id, + "due_date": start_date, + "lessee_id": record.lessee_id.id, + "original_amount": rent_monthly, + "year": self.select_year, + 'month': self.select_month, + }) try: + property_id = record.lease_ids[0].address_id.id rent_monthly = rent_id[+1].monthly_amount + start_date = rent_id[+1].start_data + self.sudo().env["property.rent.list"].create({ + "contract_id": record.id, + "property_id": property_id, + "contract_code": record.code, + "due_date": start_date, + "lessee_id": record.lessee_id.id, + "original_amount": rent_monthly, + "year": self.select_year, + 'month': self.select_month, + }) except IndexError: continue else: @@ -54,38 +95,58 @@ class PropertyRentalWizard(models.Model): date_field_year_month = date_field.strftime('%Y-%m') if start_date_year_month <= date_field_year_month < end_date_year_month: rent_monthly = rent_id.monthly_amount + start_date = rent_id.start_data + if record.lease_ids: + property_id = record.lease_ids[0].address_id.id + else: + property_id = None + self.sudo().env["property.rent.list"].create({ + "contract_id": record.id, + "contract_code": record.code, + "due_date": start_date, + "lessee_id": record.lessee_id.id, + "property_id":property_id, + "original_amount": rent_monthly, + "year": self.select_year, + 'month': self.select_month, + }) elif start_date_year_month <= date_field_year_month <= end_date_year_month: end_days = rent_id.end_data.day if end_days < days: + if record.lease_ids: + property_id = record.lease_ids[0].address_id.id + else: + property_id = None rent_monthly = rent_id.monthly_amount + start_date = rent_id.start_data + self.sudo().env["property.rent.list"].create({ + "contract_id": record.id, + "contract_code": record.code, + "due_date": start_date, + "lessee_id": record.lessee_id.id, + "property_id":property_id, + "original_amount": rent_monthly, + "year": self.select_year, + 'month': self.select_month, + }) try: rent_monthly = rent_id[+1].monthly_amount + start_date = rent_id[+1].start_data + if record.lease_ids : + property_id = record.lease_ids[0].address_id.id + else: + property_id = None + self.sudo().env["property.rent.list"].create({ + "contract_id": record.id, + "contract_code": record.code, + "property_id": property_id, + "due_date": start_date, + "original_amount": rent_monthly, + "year": self.select_year, + 'month': self.select_month, + }) except IndexError: continue else: pass - if rent_monthly: - if not record.term_start_time: - raise UserError(_("请填写租期开始时间!")) - if not record.term_end_time: - raise UserError(_("请填写租期结束时间!")) - rent_id = self.sudo().env["property.rent.list"].search([("contract_id", "=", record.id)]) - start_date = record.term_start_time - if not rent_id: - self.sudo().env["property.rent.list"].create({ - "contract_id": record.id, - "contract_code": record.code, - "due_date": start_date, - "original_amount": rent_monthly, - "year": self.select_year, - 'month': self.select_month, - }) - else: - rent_id.write({ - "contract_id": record.id, - "contract_code": record.code, - "due_date": start_date, - "original_amount": rent_monthly, - "year": self.select_year, - 'month': self.select_month, - }) \ No newline at end of file +