@@ -7,8 +7,8 @@ class ContractAccountsReceivable(models.Model):
|
||||
_description = '应收账单(合同)'
|
||||
|
||||
contract_id = fields.Many2one('property.lease.contract', string="合同")
|
||||
lessee_id = fields.Many2one('property.tenant.information', string='承租方')
|
||||
property_ids = fields.Many2many('yuthon.property', string='物业')
|
||||
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='关联应收账单')
|
||||
|
||||
json_display = fields.Char(
|
||||
@@ -17,6 +17,27 @@ 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
|
||||
|
||||
|
||||
@api.depends(
|
||||
'contract_accounts_ids.management_type_id',
|
||||
'contract_accounts_ids.last_month_table',
|
||||
|
||||
@@ -394,14 +394,55 @@ class PropertyAccountsReceivable(models.Model):
|
||||
billable_quantity = fields.Float(string="计费数量")
|
||||
pre_collection = fields.Float(string="预收金额")
|
||||
|
||||
actual_coping = fields.Float(string="实际应付")
|
||||
actual_coping = fields.Float(string="实际应付", compute='_compute_actual_coping', store=True)
|
||||
|
||||
@api.depends('original_amount', 'pre_collection')
|
||||
def _compute_actual_coping(self):
|
||||
for record in self:
|
||||
if record.original_amount:
|
||||
record.actual_coping = record.original_amount - record.pre_collection
|
||||
else:
|
||||
record.actual_coping = 0
|
||||
|
||||
def update_lessee_id(self):
|
||||
# 1. 获取选中的应收账单记录
|
||||
accounts_ids = self.env["property.accounts.receivable"].browse(
|
||||
self._context.get('active_ids', self._context.get('active_id')))
|
||||
for rec in accounts_ids:
|
||||
rec.lessee_id = rec.contract_id.lessee_id
|
||||
self._context.get('active_ids', self._context.get('active_id'))
|
||||
)
|
||||
if not accounts_ids:
|
||||
return
|
||||
unique_contracts = {
|
||||
account.contract_id for account in accounts_ids
|
||||
if account.contract_id
|
||||
}
|
||||
for contract in unique_contracts:
|
||||
contract_account = self.env['contract.accounts.receivable'].search([
|
||||
('contract_id', '=', contract.id)
|
||||
], limit=1)
|
||||
if not contract_account:
|
||||
contract_account = self.env['contract.accounts.receivable'].create({
|
||||
'contract_id': contract.id,
|
||||
})
|
||||
contract_account.onchange_contract_id()
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
contract_account_map = {}
|
||||
for vals in vals_list:
|
||||
if 'contract_id' in vals and vals['contract_id']:
|
||||
contract_id = vals['contract_id']
|
||||
if contract_id not in contract_account_map:
|
||||
contract_account = self.env['contract.accounts.receivable'].search([
|
||||
('contract_id', '=', contract_id)
|
||||
], limit=1)
|
||||
if not contract_account:
|
||||
contract_account = self.env['contract.accounts.receivable'].create({
|
||||
'contract_id': contract_id
|
||||
})
|
||||
else:
|
||||
contract_account.onchange_contract_id()
|
||||
|
||||
contract_account.onchange_contract_id()
|
||||
|
||||
@api.depends('management_type_id')
|
||||
def _compute_is_rent(self):
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<tree string="应收账单(合同)">
|
||||
<field name="contract_id"/>
|
||||
<field name="lessee_id"/>
|
||||
<field name="property_ids" widget="many2many_tags"/>
|
||||
<field name="property_name"/>
|
||||
<field name="json_display" widget="json_template"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -21,7 +21,7 @@
|
||||
<group>
|
||||
<field name="contract_id"/>
|
||||
<field name="lessee_id"/>
|
||||
<field name="property_ids" widget="many2many_tags"/>
|
||||
<field name="property_name"/>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="明细">
|
||||
@@ -37,6 +37,7 @@
|
||||
<field name="due_date_end"/>
|
||||
<field name="original_amount" string="应计金额"/>
|
||||
<field name="pre_collection"/>
|
||||
<field name="actual_coping"/>
|
||||
<field name="remark"/>
|
||||
</tree>
|
||||
</field>
|
||||
|
||||
@@ -285,7 +285,7 @@
|
||||
<xpath expr="//tree" position="inside">
|
||||
<header>
|
||||
<button name="all_red" string="红冲" type="object" class="btn btn-primary"/>
|
||||
<button name="update_lessee_id" string="更新承租方" type="object" class="btn btn-primary"/>
|
||||
<button name="update_lessee_id" string="更新" type="object" class="btn btn-primary"/>
|
||||
</header>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='is_suspend']" position="before">
|
||||
|
||||
Reference in New Issue
Block a user