diff --git a/yuthon_property_approval/models/property_lease_contract.py b/yuthon_property_approval/models/property_lease_contract.py index b49e20b65..5532c7f9a 100644 --- a/yuthon_property_approval/models/property_lease_contract.py +++ b/yuthon_property_approval/models/property_lease_contract.py @@ -66,6 +66,7 @@ class PropertyLeaseContract(models.Model): tax_number = fields.Char(related='lessee_id.tax_number', string="税号") industry_id = fields.Many2one(related='lessee_id.industry_id', string="行业") address_for_delivery = fields.Char(string="送达地址") + precinct_id = fields.Many2one('yuthon.precinct.message', string="所属片区") lease_term = fields.Float(string="租期") lease_term_year = fields.Integer(string="租期(年)") @@ -128,7 +129,7 @@ class PropertyLeaseContract(models.Model): actual_receivable = fields.Float(string="实际应收") now_receivable = fields.Float(string="当期应收") total_receivable = fields.Float(string="总已收") - comparison = fields.Selection([('outweigh', '大于'), ('equal', '等于'), ('less', '小于')], string="对比", compute='_compute_comparison', store=True) + comparison = fields.Selection([('outweigh', '大于'), ('equal', '等于'), ('less', '小于')], string="对比", compute='_compute_comparison') progress_percentage = fields.Float(string="合同进度", compute="_compute_progress_percentage") condition = fields.Selection([('new', '新建'), ('approval', '审批中'), ('cancel', '作废'), ('be_executed', '待执行'), ('executed', '已执行'), ('expired', '已终止'), ('advance', '提前终止')], string="状态", default='new') contract_type = fields.Selection([('lease_renewal', '续租'), ('interim', '临租'), ('new', '补充协议'), ('first', '首租')], string="合同类型", default='first') @@ -144,7 +145,6 @@ class PropertyLeaseContract(models.Model): other_ids = fields.One2many('property.other.fee.line', 'other_id', string="其他费用明细行") rent_list_ids = fields.One2many('property.rent.list', 'contract_id', string="租金明细行") management_list_ids = fields.One2many('property.management.list', 'contract_id', string="管理费用明细行") - # 附件 license_id = fields.Many2one('ir.attachment', string="营业执照") card_id = fields.Many2one('ir.attachment', string="经办人身份证") @@ -155,6 +155,49 @@ class PropertyLeaseContract(models.Model): responsibility_book_id = fields.Many2one('ir.attachment', string="安全生产责任书") handover_time = fields.Date(string="交接日期") + def get_breakdown_rent(self, select_month, select_year): + rent_monthly = 0 + monthly_records = self.env['property.lease.contract'].search([('cycle_dict', '=', 'monthly')]) + year = int(select_year) + month = int(select_month) + date_field = datetime(year, month, 1).date() + for record in monthly_records: + days = record.date_payment_month + if not record.rent_free_period_month: + for rent_id in record.breakdown_ids: + start_date_year_month = rent_id.start_date.strftime('%Y-%m') + end_date_year_month = rent_id.end_date.strftime('%Y-%m') + 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 + elif start_date_year_month <= date_field_year_month <= end_date_year_month: + end_days = rent_id.end_date.day + if end_days < days: + rent_monthly = rent_id.monthly_amount + else: + rent_monthly = rent_id[+1].monthly_amount + else: + pass + else: + period_month = record.rent_free_period_month + for rent_id in record.breakdown_ids: + start_date_year_month = (rent_id.start_date + relativedelta(months=period_month)).strftime('%Y-%m') + end_date_year_month = rent_id.end_date.strftime('%Y-%m') + 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 + elif start_date_year_month <= date_field_year_month <= end_date_year_month: + end_days = rent_id.end_date.day + if end_days < days: + rent_monthly = rent_id.monthly_amount + else: + rent_monthly = rent_id[+1].monthly_amount + else: + pass + + return rent_monthly + + @api.depends('not_received', 'now_receivable') def _compute_comparison(self): for record in self: @@ -165,6 +208,8 @@ class PropertyLeaseContract(models.Model): record.comparison = 'less' else: record.comparison = 'equal' + else: + record.comparison = None @api.depends('term_end_time', 'actual_end_time', 'term_start_time') def _compute_end_comparison(self): @@ -416,7 +461,7 @@ class PropertyLeaseContract(models.Model): all_period_rent = record.do_generate_details_core(start_date, first_year_end_date, False) record.first_year_rent = all_period_rent - def do_generate_details_core(self, start_date=None, end_date=None, write_db=False): + def do_generate_details_core(self, start_date, end_date, write_db=False): all_period_rent = 0 unit_price = self.unit_price # 单价 @@ -823,7 +868,7 @@ class PropertyLeaseContract(models.Model): rec.is_electricity = True for electricity_id in property_id.energy_meter_ids: electricity_list.append([0, 0, { - 'fees_id': property_id.electricity_id.id, + 'fees_id': electricity_id.id, 'proportional':electricity_id.rate, }]) else: @@ -840,7 +885,8 @@ class PropertyLeaseContract(models.Model): rec.electricity_fee_ids = [(5, 0, 0)] rec.mange_fee_ids = [(5, 0, 0)] rec.admin_id = rec.lease_ids[0].admin_id.id if rec.lease_ids else '' - rec.company_id =rec.lease_ids[0].address_id.company_id.id if rec.lease_ids else '' + rec.company_id = rec.lease_ids[0].address_id.company_id.id if rec.lease_ids else '' + rec.precinct_id = rec.lease_ids[0].address_id.precinct_id.id if rec.lease_ids else '' rec.electricity_fee_ids = electricity_list rec.mange_fee_ids = fee_list @@ -851,7 +897,8 @@ class PropertyLeaseContract(models.Model): admin_id = record.lease_ids[0].admin_id.id if record.lease_ids else '' record.write({'company_id': company_id, 'admin_id': admin_id, - 'actual_end_time': datetime.now()}) + 'actual_end_time': datetime.now(), + 'precinct_id': record.lease_ids[0].address_id.precinct_id.id if record.lease_ids else ''}) def action_yuthon_property_contract_wizard(self): return { diff --git a/yuthon_property_approval/views/property_lease_contract.xml b/yuthon_property_approval/views/property_lease_contract.xml index 789e832e1..94ea5bdc0 100644 --- a/yuthon_property_approval/views/property_lease_contract.xml +++ b/yuthon_property_approval/views/property_lease_contract.xml @@ -310,7 +310,7 @@ - + @@ -379,7 +379,7 @@ - + @@ -423,6 +423,7 @@ + @@ -624,6 +625,7 @@ + @@ -637,7 +639,7 @@ 我的合同 property.lease.contract tree,form,search - [('admin_id','=',uid)] + [('admin_id', '=', uid)] {'search_default_group_by_condition':1} 全部合同 property.lease.contract + [('condition', 'in', ['be_executed', 'executed', 'expired' ,'advance'])] tree,form,search 合同审批 property.lease.contract tree,form,search + [('condition', 'in', ['new', 'approval', 'cancel'])] {'search_default_group_by_condition':1}