From abc2943e737a65eddef7af95d617d45c1af2c85d Mon Sep 17 00:00:00 2001
From: zhou <123@>
Date: Wed, 5 Mar 2025 11:21:32 +0800
Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../models/property_bank_statements.py | 25 ++++++++-
.../views/property_bank_statements_views.xml | 6 +--
.../wizard/property_statements_wizard.py | 11 ++--
yuthon_property_approval/__manifest__.py | 1 -
.../models/inherit_yuthon_property.py | 52 ++++++++++++++-----
.../security/ir.model.access.csv | 1 -
.../views/inherit_yuthon_property_views.xml | 9 +++-
yuthon_property_approval/wizard/__init__.py | 1 -
.../wizard/property_penalty_wizard.py | 28 ----------
.../wizard/property_penalty_wizard_views.xml | 21 --------
10 files changed, 83 insertions(+), 72 deletions(-)
delete mode 100644 yuthon_property_approval/wizard/property_penalty_wizard.py
delete mode 100644 yuthon_property_approval/wizard/property_penalty_wizard_views.xml
diff --git a/yuthon_property/models/property_bank_statements.py b/yuthon_property/models/property_bank_statements.py
index 79e773fd7..a6994edb6 100644
--- a/yuthon_property/models/property_bank_statements.py
+++ b/yuthon_property/models/property_bank_statements.py
@@ -11,7 +11,7 @@ class PropertyBankStatements(models.Model):
name = fields.Char('账户卡号')
company_id = fields.Many2one('yuthon.property.company', string="收款账户")
name_account = fields.Char('户名')
- start_time = fields.Date('交易时间')
+ start_time = fields.Datetime('交易时间')
contract_account = fields.Char(string="合同累计应收")
contract_penalty = fields.Char(string="合同累计违约金")
original_amount = fields.Float(string='交易金额')
@@ -65,3 +65,26 @@ class PropertyBankStatements(models.Model):
property_ids.append(lease_id.id)
self.property_ids = [(6, 0, property_ids)]
self.contract_ids = [(6, 0, contract_ids.ids)] if contract_ids else []
+
+ @api.model
+ def create(self, vals):
+ record = super(PropertyBankStatements, self).create(vals)
+ record._update_related_fields()
+ return record
+
+ def _update_related_fields(self):
+ contract_ids = self.env['property.lease.contract']
+ property_ids = []
+ if self.name:
+ bank_id = self.env['property.bank.line'].search([('bank', '=', self.name)])
+ if bank_id:
+ tenant_id = bank_id.tenant_id
+ if tenant_id:
+ contract_ids = self.env['property.lease.contract'].search([('lessee_id', '=', tenant_id.id)])
+ for contract in contract_ids:
+ if contract.lease_ids:
+ lease_id = contract.lease_ids[0].address_id
+ if lease_id:
+ property_ids.append(lease_id.id)
+ self.property_ids = [(6, 0, property_ids)]
+ self.contract_ids = [(6, 0, contract_ids.ids)] if contract_ids else []
\ No newline at end of file
diff --git a/yuthon_property/views/property_bank_statements_views.xml b/yuthon_property/views/property_bank_statements_views.xml
index 7e791e5ae..c71653b2a 100644
--- a/yuthon_property/views/property_bank_statements_views.xml
+++ b/yuthon_property/views/property_bank_statements_views.xml
@@ -9,11 +9,11 @@
-
-
+
+
-
+
diff --git a/yuthon_property/wizard/property_statements_wizard.py b/yuthon_property/wizard/property_statements_wizard.py
index 961229812..5be0cdd85 100644
--- a/yuthon_property/wizard/property_statements_wizard.py
+++ b/yuthon_property/wizard/property_statements_wizard.py
@@ -5,7 +5,7 @@ from datetime import datetime, time, timedelta
import xlrd
import base64
import pandas as pd
-
+import re
class PropertyStatementsWizard(models.Model):
_name = 'property.statements.wizard'
@@ -29,7 +29,10 @@ class PropertyStatementsWizard(models.Model):
def property_bank_statements_data(self, row):
contract_ids = self.env['property.lease.contract']
if row[2].value:
- start_time = pd.to_datetime(row[2].value, unit='d', origin='1899-12-30')
+ # 先转换日期格式
+ formatted_date = self.convert_date_format(row[2].value)
+ # 再将转换后的日期字符串转换为 pandas 的 datetime 对象
+ start_time = pd.to_datetime(formatted_date)
else:
start_time = None
name = row[0].value
@@ -61,4 +64,6 @@ class PropertyStatementsWizard(models.Model):
}
self.env['property.bank.statements'].create(bank_data)
-
+ def convert_date_format(self,date_str):
+ pattern = r'(\d{4})(\d{2})(\d{2}) (\d{2}:\d{2}:\d{2})'
+ return re.sub(pattern, r'\1/\2/\3 \4', date_str)
diff --git a/yuthon_property_approval/__manifest__.py b/yuthon_property_approval/__manifest__.py
index a6b5e3411..6c8e73648 100644
--- a/yuthon_property_approval/__manifest__.py
+++ b/yuthon_property_approval/__manifest__.py
@@ -69,7 +69,6 @@
'wizard/choose_contract_wizard_views.xml',
'wizard/property_reconciliation_wizard_views.xml',
'wizard/property_rental_wizard_views.xml',
- 'wizard/property_penalty_wizard_views.xml',
'views/property_menu_all.xml',
],
'demo': [],
diff --git a/yuthon_property_approval/models/inherit_yuthon_property.py b/yuthon_property_approval/models/inherit_yuthon_property.py
index 8fb080a46..6d6c35d58 100644
--- a/yuthon_property_approval/models/inherit_yuthon_property.py
+++ b/yuthon_property_approval/models/inherit_yuthon_property.py
@@ -25,7 +25,7 @@ class PropertyBankStatements(models.Model):
for contract_id in record.contract_ids:
receivable_id = self.env['property.accounts.receivable'].search([('contract_id', '=', contract_id.id)])
if receivable_id:
- dt = datetime.strptime(str(record.start_time), '%Y-%m-%d').date()
+ dt = datetime.strptime(str(record.start_time), '%Y-%m-%d %H:%M:%S').date()
due = datetime.strptime(str(receivable_id.due_date), '%Y-%m-%d').date()
# 判断是否违约
if receivable_id.due_date > record.start_time and receivable_id.is_reconciliation == False:
@@ -60,18 +60,46 @@ class PropertyAccountsReceivable(models.Model):
contract_id = fields.Many2one('property.lease.contract', string="关联租赁合同审批")
penalty = fields.Float(string="违约金")
+ penalty_date = fields.Date(string="违约金日期")
+
+ @api.onchange('penalty_date')
+ def _onchange_penalty_date(self):
+ for record in self:
+ if record.create_time and record.penalty_date:
+ create_time = record.create_time
+ dt = datetime.strptime(str(create_time), '%Y-%m-%d').date()
+ new_month = dt.month + 1
+ new_year = dt.year
+ if new_month > 12:
+ new_month = 1
+ new_year += 1
+ new_date = dt.replace(year=new_year, month=new_month, day=1)
+ penalty_date = datetime.strptime(str(record.penalty_date), '%Y-%m-%d').date()
+ if penalty_date.year == datetime.now().year - 1:
+ raise UserWarning("选择的日期为去年的年份,请重新选择!")
+ days_difference = (penalty_date - new_date).days
+ penalty = days_difference * record.difference_amount
+ record.write({'penalty': penalty})
+
+ def all_penalty_date(self):
+ receivable_ids= self.env["property.accounts.receivable"].browse(self._context.get('active_ids', self._context.get('active_id')))
+ for receivable in receivable_ids:
+ if receivable.receivable_id.create_time and receivable.penalty_date:
+ create_time = receivable.receivable_id.create_time
+ dt = datetime.strptime(str(create_time), '%Y-%m-%d').date()
+ new_month = dt.month + 1
+ new_year = dt.year
+ if new_month > 12:
+ new_month = 1
+ new_year += 1
+ new_date = dt.replace(year=new_year, month=new_month, day=1)
+ penalty_date = datetime.strptime(str(receivable.penalty_date), '%Y-%m-%d').date()
+ if penalty_date.year == datetime.now().year - 1:
+ raise UserWarning("选择的日期为去年的年份,请重新选择!")
+ days_difference = (penalty_date - new_date).days
+ penalty = days_difference * receivable.receivable_id.difference_amount
+ receivable.receivable_id.write({'penalty': penalty})
- def button_penalty(self):
- return {
- "type": "ir.actions.act_window",
- "name": "违约金弹窗",
- "res_model": "property.penalty.wizard",
- "view_mode": "form",
- "target": "new",
- "context": {
- 'default_receivable_id': self.id,
- }
- }
def receivable_return(self):
model_type_data = {
diff --git a/yuthon_property_approval/security/ir.model.access.csv b/yuthon_property_approval/security/ir.model.access.csv
index c3ad5bfa1..00c56083a 100644
--- a/yuthon_property_approval/security/ir.model.access.csv
+++ b/yuthon_property_approval/security/ir.model.access.csv
@@ -88,7 +88,6 @@ access_property_borrowing_approval,property_borrowing_approval,model_property_bo
access_yuthon_borrowing_line,yuthon_borrowing_line,model_yuthon_borrowing_line,base.group_user,1,1,1,1
access_property_claim_approval,property_claim_approval,model_property_claim_approval,base.group_user,1,1,1,1
access_property_claim_line,property_claim_line,model_property_claim_line,base.group_user,1,1,1,1
-access_property_penalty_wizard,property_penalty_wizard,model_property_penalty_wizard,base.group_user,1,1,1,1
access_property_reconciliation_wizard,property_reconciliation_wizard,model_property_reconciliation_wizard,base.group_user,1,1,1,1
access_property_reconciliation_line,property_reconciliation_line,model_property_reconciliation_line,base.group_user,1,1,1,1
diff --git a/yuthon_property_approval/views/inherit_yuthon_property_views.xml b/yuthon_property_approval/views/inherit_yuthon_property_views.xml
index 3ad4fb9c9..bfa8f2884 100644
--- a/yuthon_property_approval/views/inherit_yuthon_property_views.xml
+++ b/yuthon_property_approval/views/inherit_yuthon_property_views.xml
@@ -314,11 +314,18 @@
-
+
+
+ 批量生成违约金
+
+
+ code
+ action = model.all_penalty_date()
+
批量退回
diff --git a/yuthon_property_approval/wizard/__init__.py b/yuthon_property_approval/wizard/__init__.py
index 1e341b847..4433e3a40 100644
--- a/yuthon_property_approval/wizard/__init__.py
+++ b/yuthon_property_approval/wizard/__init__.py
@@ -3,5 +3,4 @@ from . import choose_property_wizard
from . import property_rental_wizard
from . import property_add_wizard
from . import property_physical_wizard
-from . import property_penalty_wizard
from . import property_reconciliation_wizard
\ No newline at end of file
diff --git a/yuthon_property_approval/wizard/property_penalty_wizard.py b/yuthon_property_approval/wizard/property_penalty_wizard.py
deleted file mode 100644
index b0bf3aac7..000000000
--- a/yuthon_property_approval/wizard/property_penalty_wizard.py
+++ /dev/null
@@ -1,28 +0,0 @@
-from odoo import models, fields, api, _, SUPERUSER_ID
-from datetime import datetime, timedelta
-
-
-class PropertyPenaltyWizard(models.Model):
- _name = 'property.penalty.wizard'
- _description = '违约金弹窗'
-
- select_time_date = fields.Date(string='选择日期')
- receivable_id = fields.Many2one('property.accounts.receivable', string='关联应收列表')
-
- def confirm(self):
- for record in self:
- if record.receivable_id.create_time:
- create_time = record.receivable_id.create_time
- dt = datetime.strptime(str(create_time), '%Y-%m-%d').date()
- new_month = dt.month + 1
- new_year = dt.year
- if new_month > 12:
- new_month = 1
- new_year += 1
- new_date = dt.replace(year=new_year, month=new_month, day=1)
- select_date = datetime.strptime(str(record.select_time_date), '%Y-%m-%d').date()
- if select_date.year == datetime.now().year - 1:
- raise UserWarning("选择的日期为去年的年份,请重新选择!")
- days_difference = (select_date - new_date).days
- penalty = days_difference * record.receivable_id.difference_amount
- record.receivable_id.write({'penalty': penalty})
\ No newline at end of file
diff --git a/yuthon_property_approval/wizard/property_penalty_wizard_views.xml b/yuthon_property_approval/wizard/property_penalty_wizard_views.xml
deleted file mode 100644
index 3945ae420..000000000
--- a/yuthon_property_approval/wizard/property_penalty_wizard_views.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- property.penalty.wizard.form
- property.penalty.wizard
-
-
-
-
-
\ No newline at end of file
From 0e885e613e8b0c88dd8eaf7579532549035b0d1c Mon Sep 17 00:00:00 2001
From: zhou <123@>
Date: Wed, 5 Mar 2025 11:25:50 +0800
Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
yuthon_property/wizard/property_statements_wizard.py | 3 +--
yuthon_property/wizard/property_statements_wizard_views.xml | 1 +
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/yuthon_property/wizard/property_statements_wizard.py b/yuthon_property/wizard/property_statements_wizard.py
index 5be0cdd85..d6f0821c3 100644
--- a/yuthon_property/wizard/property_statements_wizard.py
+++ b/yuthon_property/wizard/property_statements_wizard.py
@@ -11,6 +11,7 @@ class PropertyStatementsWizard(models.Model):
_name = 'property.statements.wizard'
_description = '银行流水向导弹窗'
+ selection_bank = fields.Select(string="选择银行", selection=[('js', '建设银行'), ('gs', '工商银行')])
excel_file = fields.Binary(string="上传Excel表")
excel_name = fields.Char(string="文件名")
@@ -29,9 +30,7 @@ class PropertyStatementsWizard(models.Model):
def property_bank_statements_data(self, row):
contract_ids = self.env['property.lease.contract']
if row[2].value:
- # 先转换日期格式
formatted_date = self.convert_date_format(row[2].value)
- # 再将转换后的日期字符串转换为 pandas 的 datetime 对象
start_time = pd.to_datetime(formatted_date)
else:
start_time = None
diff --git a/yuthon_property/wizard/property_statements_wizard_views.xml b/yuthon_property/wizard/property_statements_wizard_views.xml
index fcdac6b3d..8f4b7ca69 100644
--- a/yuthon_property/wizard/property_statements_wizard_views.xml
+++ b/yuthon_property/wizard/property_statements_wizard_views.xml
@@ -17,6 +17,7 @@
+