@@ -1,7 +1,11 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from odoo import models, fields, api, exceptions, _
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
from datetime import datetime, timedelta
|
||||
import logging
|
||||
from odoo.osv import expression
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
class PropertyBankStatements(models.Model):
|
||||
_name = 'property.bank.statements'
|
||||
@@ -11,6 +15,7 @@ class PropertyBankStatements(models.Model):
|
||||
company_id = fields.Many2one('yuthon.property.company', string="收款账户")
|
||||
sequence_number = fields.Char('顺序号')
|
||||
your_own_account = fields.Char('本方账号')
|
||||
your_own_unit = fields.Char('账号单位')
|
||||
name_account = fields.Char('对方户名')
|
||||
bank_branch = fields.Char('对方开户机构')
|
||||
bank_number = fields.Char('对方行号')
|
||||
@@ -29,8 +34,45 @@ class PropertyBankStatements(models.Model):
|
||||
voucher_type = fields.Selection([('electronic_transfer', '电子转账凭证'), ('telegraphic_transfer', '电汇凭证')], string='凭证种类')
|
||||
remake = fields.Text('备注')
|
||||
registered = fields.Float('挂账')
|
||||
company_select = fields.Selection([('jhtz', '天河投资'), ('thwg', '天河物管'), ('thcj', '天河城建')])
|
||||
property_ids = fields.Many2many('yuthon.property', string='物业地址')
|
||||
bank_state = fields.Selection([('not_reconciled', '未对账'), ('reconciled', '已对账'), ('other', '其他')], string='状态', default='not_reconciled')
|
||||
is_company = fields.Boolean(compute='_compute_is_company', search='_search_part_of_company')
|
||||
|
||||
@api.depends_context('uid', 'company')
|
||||
@api.depends('your_own_account')
|
||||
def _compute_is_company(self):
|
||||
user_companies = self.env['res.company'].browse(self.env.companies.ids)
|
||||
user_company_names = set(user_companies.mapped('name'))
|
||||
# 预定义账号映射关系
|
||||
account_mapping = {
|
||||
'集团本部': ['天河投资', '天投城建'],
|
||||
'天河物管': ['天河物管']
|
||||
}
|
||||
for record in self:
|
||||
# 默认不可见
|
||||
record.is_company = False
|
||||
# 检查账号是否符合规则
|
||||
for company_name, allowed_accounts in account_mapping.items():
|
||||
if company_name in user_company_names:
|
||||
if record.your_own_unit in allowed_accounts:
|
||||
record.is_company = True
|
||||
break
|
||||
|
||||
def _search_part_of_company(self, operator, value):
|
||||
if operator not in ('=', '!=') or not isinstance(value, bool):
|
||||
raise UserError(_('操作不支持'))
|
||||
user_companies = self.env['res.company'].browse(self.env.companies.ids)
|
||||
company_names = user_companies.mapped('name')
|
||||
visible_accounts = []
|
||||
if "集团本部" in company_names:
|
||||
visible_accounts.extend(['天河投资', '天投城建'])
|
||||
if "天河物管" in company_names:
|
||||
visible_accounts.append('天河物管')
|
||||
if not value:
|
||||
operator = '!=' if operator == '=' else '='
|
||||
domain = [('your_own_unit', 'in', visible_accounts)] if operator == '=' and visible_accounts else []
|
||||
return domain or [('id', '=', 0)]
|
||||
|
||||
def other(self):
|
||||
for rec in self:
|
||||
|
||||
@@ -44,8 +44,8 @@ class PropertyRentList(models.Model):
|
||||
vals['last_update_time'] = fields.Datetime.now()
|
||||
return super(PropertyRentList, self).write(vals)
|
||||
|
||||
def unlink(self):
|
||||
def receivable_unlink(self):
|
||||
receivable_ids = self.env['property.accounts.receivable'].search([('lessee_id', '=', self.lessee_id.id)])
|
||||
for receivable in receivable_ids:
|
||||
receivable.write({'receivable_log': f'当前登录人{self.env.user.name}于{fields.Datetime.now()}将物业为 {self.property_id.name} 的租金列表进行删除'})
|
||||
return super().unlink()
|
||||
receivable.unlink()
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<tree string="银行流水" editable="bottom" js_class="custom_bank_statements_button" limit="20">
|
||||
<field name="sequence_number"/>
|
||||
<field name="your_own_account"/>
|
||||
<field name="your_own_account" optional="hide"/>
|
||||
<field name="your_own_unit" optional="hide"/>
|
||||
<!--
|
||||
<field name="name_account"/> <header>-->
|
||||
<!-- <button name="handle_contract_penalty" type="object" class="oe_highlight" string="ce"/>-->
|
||||
@@ -52,6 +53,7 @@
|
||||
<field name="bank_branch" optional="hide"/>
|
||||
<field name="extract" optional="hide"/>
|
||||
<field name="account_code" optional="hide"/>
|
||||
<field name="is_company" column_invisible="1"/>
|
||||
<field name="remake"/>
|
||||
<field name="original_amount"/>
|
||||
<field name="contract_account" optional="hide"/>
|
||||
@@ -78,6 +80,7 @@
|
||||
<field name="name">银行流水</field>
|
||||
<field name="res_model">property.bank.statements</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="domain">[('is_company', '=', True)]</field>
|
||||
<field name="context">{'group_by': 'bank_state'}</field>
|
||||
<field name="view_ids" eval="[(5, 0, 0),
|
||||
(0, 0, {'view_mode': 'tree', 'view_id': ref('yuthon_property.view_property_bank_statements_tree1')})]"/>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
<field name="last_update_time" optional="hide"/>
|
||||
<field name="is_billing" column_invisible="1"/>
|
||||
<field name="is_reconciliation" column_invisible="1"/>
|
||||
<button name="unlink" type="object" class="btn-primary" string="删除"/>
|
||||
<button name="receivable_unlink" type="object" class="btn-primary" string="删除"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -42,9 +42,11 @@ class PropertyStatementsWizard(models.Model):
|
||||
your_own_account = row[6].value
|
||||
cleaned_amount = original_amount.replace(',', '') # 移除逗号
|
||||
float_amount = float(cleaned_amount)
|
||||
your_own_unit = self.classify_by_last_four(your_own_account)
|
||||
sequence_number = row[5].value
|
||||
bank_data = {
|
||||
'name': name,
|
||||
'your_own_unit':your_own_unit,
|
||||
'original_amount': float_amount,
|
||||
'sequence_number': sequence_number,
|
||||
'start_time': start_time,
|
||||
@@ -64,8 +66,10 @@ class PropertyStatementsWizard(models.Model):
|
||||
name_account = row[3].value
|
||||
name = row[4].value
|
||||
remake = row[5].value
|
||||
your_own_unit = self.classify_by_last_four(your_own_account)
|
||||
bank_data = {
|
||||
'name': name,
|
||||
'your_own_unit':your_own_unit,
|
||||
'original_amount': original_amount,
|
||||
'start_time': start_time,
|
||||
'your_own_account': your_own_account,
|
||||
@@ -99,4 +103,17 @@ class PropertyStatementsWizard(models.Model):
|
||||
'original_amount': original_amount
|
||||
})
|
||||
receivable_id.write({'penalty':original_amount})
|
||||
receivable_id.is_reconciliation = True
|
||||
receivable_id.is_reconciliation = True
|
||||
|
||||
def classify_by_last_four(self, input_str):
|
||||
if not isinstance(input_str, str) or len(input_str) < 4:
|
||||
return "天投城建" # 输入不是字符串或长度不足4,默认为天投城建
|
||||
|
||||
last_four = input_str[-4:] # 获取后四位字符
|
||||
|
||||
if last_four == "3619":
|
||||
return "天河物管"
|
||||
elif last_four == "0222":
|
||||
return "天河投资"
|
||||
else:
|
||||
return "天投城建"
|
||||
@@ -382,11 +382,9 @@ class PropertyDepositList(models.Model):
|
||||
_inherit = 'property.deposit.list'
|
||||
|
||||
contract_id = fields.Many2one('property.lease.contract', string="关联租赁合同审批")
|
||||
deposit = fields.Float(related='contract_id.deposit', string="押金/履约保证金", store=True)
|
||||
performance_bonds = fields.Float(related='contract_id.performance_bonds', string="经营履约保证金")
|
||||
utility_bills = fields.Float(related='contract_id.utility_bills', string="水电费押金")
|
||||
renovation_deposit = fields.Float(related='contract_id.renovation_deposit', string="装修押金")
|
||||
original_amount = fields.Float(string="合计", store=True, compute='_compute_original_amount')
|
||||
posit_type = fields.Selection([('deposit', '押金'), ('performance_bonds', '经营履约保证金'),
|
||||
('utility_bills', '水电费'), ('decorate', '装修')], string="保证金类型")
|
||||
original_amount = fields.Float(string="金额")
|
||||
|
||||
def push_deposit(self):
|
||||
for rec in self:
|
||||
@@ -418,11 +416,6 @@ class PropertyDepositList(models.Model):
|
||||
})
|
||||
rec.is_push = True
|
||||
|
||||
@api.depends('deposit', 'performance_bonds', 'utility_bills', 'renovation_deposit')
|
||||
def _compute_original_amount(self):
|
||||
for rec in self:
|
||||
rec.original_amount = rec.deposit + rec.performance_bonds + rec.utility_bills + rec.renovation_deposit
|
||||
|
||||
# 管理费
|
||||
class PropertyManagementList(models.Model):
|
||||
_inherit = 'property.management.list'
|
||||
|
||||
@@ -67,10 +67,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='property_id']" position="after">
|
||||
<field name="contract_id" string="合同"/>
|
||||
<field name="deposit"/>
|
||||
<field name="performance_bonds"/>
|
||||
<field name="utility_bills"/>
|
||||
<field name="renovation_deposit"/>
|
||||
<field name="posit_type"/>
|
||||
<field name="original_amount"/>
|
||||
</xpath>
|
||||
<xpath expr="//tree/field[@name='lessee_id']" position="after">
|
||||
|
||||
@@ -48,13 +48,27 @@ class PropertyRentalWizard(models.Model):
|
||||
})
|
||||
|
||||
def create_deposit_list(self, record):
|
||||
"""封装创建押金记录的逻辑"""
|
||||
"""封装创建押金记录的逻辑 - 根据合同中的多种押金类型创建多条记录"""
|
||||
property_id = record.lease_ids[0].address_id.id if record.lease_ids else None
|
||||
self.sudo().env["property.deposit.list"].create({
|
||||
"contract_id": record.id,
|
||||
"property_id": property_id,
|
||||
"lessee_id": record.lessee_id.id,
|
||||
})
|
||||
lessee_id = record.lessee_id.id
|
||||
deposit_types = [
|
||||
('deposit', 'deposit'),
|
||||
('performance_bonds', 'performance_bonds'),
|
||||
('utility_bills', 'utility_bills'),
|
||||
('renovation_deposit', 'decorate'),
|
||||
# 可以根据需要添加更多押金类型
|
||||
]
|
||||
# 遍历每种押金类型,创建对应的押金记录(值不为0时)
|
||||
for field_name, deposit_type in deposit_types:
|
||||
amount = getattr(record, field_name, 0)
|
||||
if amount > 0: # 只创建金额大于0的押金记录
|
||||
self.sudo().env["property.deposit.list"].create({
|
||||
"contract_id": record.id,
|
||||
"property_id": property_id,
|
||||
"lessee_id": lessee_id,
|
||||
"posit_type": deposit_type,
|
||||
"original_amount": amount,
|
||||
})
|
||||
|
||||
def create_management_list(self, record,start_date):
|
||||
"""封装创建管理费记录的逻辑"""
|
||||
|
||||
Reference in New Issue
Block a user