添加功能
This commit is contained in:
@@ -22,6 +22,7 @@ class PropertyAccountsReceivable(models.Model):
|
||||
('12', '十二月')], string='选择月份')
|
||||
original_amount = fields.Float(string='当期金额')
|
||||
discount_amount = fields.Float(string='减免金额')
|
||||
discount_date = fields.Date(string='减免日期')
|
||||
multiplier = fields.Integer(string='季度')
|
||||
remark = fields.Text(string='备注')
|
||||
red_date = fields.Date(string='红冲日期')
|
||||
@@ -50,6 +51,21 @@ class PropertyAccountsReceivable(models.Model):
|
||||
receivable_log = fields.Text(string='应收日志')
|
||||
|
||||
|
||||
@api.onchange('is_invalid')
|
||||
def _onchange_is_invalid(self):
|
||||
if self.is_invalid:
|
||||
self.void_date = fields.Date.today()
|
||||
else:
|
||||
self.void_date = False
|
||||
|
||||
@api.depends('discount_amount')
|
||||
def _onchange_discount_amount(self):
|
||||
for record in self:
|
||||
if record.discount_amount:
|
||||
record.discount_date = fields.Date.today()
|
||||
else:
|
||||
record.discount_date = False
|
||||
|
||||
def update_submitted(self):
|
||||
record_ids = self.env["property.accounts.receivable"].browse(
|
||||
self._context.get("active_ids", self._context.get("active_id"))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from odoo import models, fields, api
|
||||
from datetime import datetime, timedelta, date
|
||||
import json
|
||||
|
||||
|
||||
@@ -10,6 +11,7 @@ class ContractAccountsReceivable(models.Model):
|
||||
lessee_id = fields.Many2one(related="contract_id.lessee_id", string='承租方')
|
||||
property_name = fields.Char(related="contract_id.property_name", string='物业信息')
|
||||
contract_accounts_ids = fields.One2many('property.accounts.receivable', 'contract_accounts_id', string='关联应收账单')
|
||||
contract_date = fields.Date(string="日期")
|
||||
is_print = fields.Boolean(string="打印")
|
||||
|
||||
json_display = fields.Char(
|
||||
@@ -18,26 +20,72 @@ class ContractAccountsReceivable(models.Model):
|
||||
store=True
|
||||
)
|
||||
|
||||
# @api.onchange('contract_id')
|
||||
# def onchange_contract_id(self):
|
||||
# accounts = self.env['property.accounts.receivable'].search([('contract_id', '=', self.contract_id.id)])
|
||||
# receivable_list = []
|
||||
# for account in accounts:
|
||||
# receivable_list.append([0, 0, {
|
||||
# 'contract_accounts_id': account.id,
|
||||
# 'management_type_id': account.management_type_id.id,
|
||||
# 'last_month_table': account.last_month_table,
|
||||
# 'this_month_table': account.this_month_table,
|
||||
# 'ratio': account.ratio,
|
||||
# 'billable_quantity': account.billable_quantity,
|
||||
# 'due_date': account.due_date,
|
||||
# 'due_date_end': account.due_date_end,
|
||||
# 'original_amount': account.original_amount,
|
||||
# 'pre_collection': account.pre_collection,
|
||||
# 'remark': account.remark,
|
||||
# }])
|
||||
# self.contract_accounts_ids = receivable_list
|
||||
def batch_create_by_contract_and_month(self):
|
||||
"""
|
||||
按“合同+年月”分组创建账单,创建时即设置contract_date为分组最早due_date
|
||||
"""
|
||||
all_receivables = self.env['property.accounts.receivable'].search([
|
||||
('contract_id', '!=', False),
|
||||
('due_date', '!=', False),
|
||||
('is_invalid', '=', False),
|
||||
('is_reconciliation', '=', True)
|
||||
])
|
||||
# 按“合同ID+年月”分组
|
||||
grouped_data = {}
|
||||
for receivable in all_receivables:
|
||||
year_month = receivable.due_date.strftime('%Y-%m')
|
||||
key = (receivable.contract_id.id, year_month)
|
||||
if key not in grouped_data:
|
||||
grouped_data[key] = self.env['property.accounts.receivable']
|
||||
grouped_data[key] += receivable
|
||||
|
||||
for (contract_id, year_month), receivables in grouped_data.items():
|
||||
if not contract_id:
|
||||
continue
|
||||
earliest_due_date = min(receivables.mapped('due_date'))
|
||||
start_date, end_date = self._get_month_date_range(year_month)
|
||||
existing_bill = self.search([
|
||||
('contract_id', '=', contract_id),
|
||||
('contract_date', '>=', start_date),
|
||||
('contract_date', '<=', end_date)
|
||||
], limit=1)
|
||||
if not existing_bill:
|
||||
existing_bill = self.create({
|
||||
'contract_id': contract_id,
|
||||
'contract_date': earliest_due_date,
|
||||
'is_print': False
|
||||
})
|
||||
accounts = self.env['property.accounts.receivable'].search([('contract_id', '=', contract_id),
|
||||
('due_date', '>=', start_date),
|
||||
('due_date', '<', end_date),
|
||||
('is_invalid', '=', False),
|
||||
('is_reconciliation', '=', True)
|
||||
])
|
||||
receivable_list = []
|
||||
for account in accounts:
|
||||
receivable_list.append([0, 0, {
|
||||
'contract_accounts_id': existing_bill.id,
|
||||
'management_type_id': account.management_type_id.id,
|
||||
'last_month_table': account.last_month_table,
|
||||
'this_month_table': account.this_month_table,
|
||||
'ratio': account.ratio,
|
||||
'billable_quantity': account.billable_quantity,
|
||||
'due_date': account.due_date,
|
||||
'due_date_end': account.due_date_end,
|
||||
'original_amount': account.original_amount,
|
||||
'pre_collection': account.pre_collection,
|
||||
'remark': account.remark,
|
||||
}])
|
||||
existing_bill.contract_accounts_ids = receivable_list
|
||||
|
||||
|
||||
def _get_month_date_range(self, year_month):
|
||||
"""获取年月对应的起止日期"""
|
||||
year, month = map(int, year_month.split('-'))
|
||||
start_date = fields.Date.from_string(f"{year}-{month}-01")
|
||||
next_month = f"{year + 1}-01-01" if month == 12 else f"{year}-{month + 1}-01"
|
||||
end_date = fields.Date.from_string(next_month) - timedelta(days=1)
|
||||
return start_date, end_date
|
||||
|
||||
@api.depends(
|
||||
'contract_accounts_ids.management_type_id',
|
||||
|
||||
@@ -623,6 +623,7 @@ class PropertyAccountsReceivable(models.Model):
|
||||
_rec_name = 'contract_id'
|
||||
|
||||
property_ids = fields.Many2many('yuthon.property', string='物业', compute='_compute_property_ids', store=True)
|
||||
lease_contract_id = fields.Many2one('property.lease.contract', string="关联租赁合同")
|
||||
contract_accounts_id = fields.Many2one('contract.accounts.receivable', string="合同")
|
||||
property_name = fields.Text(string='物业', compute="_compute_property_name")
|
||||
is_penalty = fields.Boolean(string='是否违约金', default=True, compute = '_compute_is_penalty', store=True)
|
||||
|
||||
@@ -107,6 +107,7 @@ class PropertyLeaseContract(models.Model):
|
||||
string="租赁合同文件"
|
||||
)
|
||||
title_address = fields.Char(string="产权地址")
|
||||
receivable_ids = fields.One2many('property.accounts.receivable', 'lease_contract_id', string="应收账单")
|
||||
handling_opinions = fields.Text(string="经办意见")
|
||||
lessor_id = fields.Many2one('yuthon.property.company', string="出租方公司")
|
||||
rent_company = fields.Char(related='lessor_id.name', string="收租公司名称")
|
||||
|
||||
@@ -143,4 +143,5 @@ class EarlyReceivablesLine(models.Model):
|
||||
receivable_id = fields.Many2one('property.accounts.receivable', string='应收账单')
|
||||
management_type_id = fields.Many2one(related='receivable_id.management_type_id', string='类型')
|
||||
due_date = fields.Date(related='receivable_id.due_date', string='应收日期')
|
||||
original_amount = fields.Float(related='receivable_id.original_amount', string='金额')
|
||||
original_amount = fields.Float(related='receivable_id.original_amount', string='金额')
|
||||
void = fields.Boolean(string='作废', default=False)
|
||||
@@ -47,6 +47,13 @@
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="batch_create_by_contract_and_month" model="ir.actions.server">
|
||||
<field name="name">更新</field>
|
||||
<field name="model_id" ref="yuthon_property_approval.model_contract_accounts_receivable"/>
|
||||
<field name="binding_model_id" ref="yuthon_property_approval.model_contract_accounts_receivable"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">action = model.batch_create_by_contract_and_month()</field>
|
||||
</record>
|
||||
<record id="view_contract_accounts_receivable_action" model="ir.actions.act_window">
|
||||
<field name="name">应收账单(合同)</field>
|
||||
|
||||
@@ -403,6 +403,10 @@
|
||||
<field name="lessee_id" options="{'no_create': True}" readonly="1"/>
|
||||
<field name="title_deed" readonly="1"/>
|
||||
<field name="company_id" column_invisible="1"/>
|
||||
<field name="last_month_table" column_invisible="1"/>
|
||||
<field name="this_month_table" column_invisible="1"/>
|
||||
<field name="ratio" column_invisible="1"/>
|
||||
<field name="billable_quantity" column_invisible="1"/>
|
||||
<!-- <field name="company_id1"/>-->
|
||||
<field name="contract_id" string="合同编号" options="{'no_create': True}"/>
|
||||
</xpath>
|
||||
|
||||
@@ -839,6 +839,24 @@
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
<page string="应收明细">
|
||||
<field name="receivable_ids" string=" ">
|
||||
<tree editable="bottom" create="false">
|
||||
<field name="lease_contract_id" column_invisible="1"/>
|
||||
<field name="management_type_id"/>
|
||||
<field name="last_month_table"/>
|
||||
<field name="this_month_table"/>
|
||||
<field name="ratio"/>
|
||||
<field name="billable_quantity"/>
|
||||
<field name="due_date"/>
|
||||
<field name="due_date_end"/>
|
||||
<field name="original_amount" string="应计金额"/>
|
||||
<field name="pre_collection"/>
|
||||
<field name="actual_coping"/>
|
||||
<field name="remark"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
</notebook>
|
||||
<group>
|
||||
<field name="handover_time"/>
|
||||
|
||||
@@ -99,6 +99,7 @@
|
||||
<field name="management_type_id"/>
|
||||
<field name="due_date"/>
|
||||
<field name="original_amount"/>
|
||||
<field name="void"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
||||
Reference in New Issue
Block a user