@@ -0,0 +1,38 @@
|
||||
from odoo import models, fields, api
|
||||
from odoo.exceptions import UserError
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
class ContractRentalWizard(models.Model):
|
||||
_name = 'property.contract.rental.wizard'
|
||||
_description = '指定合同租金生成向导'
|
||||
|
||||
select_month = fields.Selection(
|
||||
[('1', '一月'), ('2', '二月'), ('3', '三月'), ('4', '四月'),
|
||||
('5', '五月'), ('6', '六月'), ('7', '七月'), ('8', '八月'),
|
||||
('9', '九月'), ('10', '十月'), ('11', '十一月'), ('12', '十二月')],
|
||||
string='选择月份', default=lambda self: str(datetime.now().month))
|
||||
|
||||
select_year = fields.Selection(
|
||||
selection=[(str(i), str(i)) for i in range(2024, 2060)],
|
||||
string='选择年份', default=lambda self: str(datetime.now().year))
|
||||
|
||||
contract_ids = fields.Many2many('property.lease.contract', string='合同')
|
||||
|
||||
def confirm(self):
|
||||
"""对选中的合同生成选定年月的租金"""
|
||||
self.ensure_one()
|
||||
if not self.contract_ids:
|
||||
raise UserError('请选择至少一个合同')
|
||||
temp_wizard = self.env['property.rental.wizard'].new({
|
||||
'select_month': self.select_month,
|
||||
'select_year': self.select_year,
|
||||
})
|
||||
date_field = datetime(int(self.select_year), int(self.select_month), 1).date()
|
||||
date_field_year_month = date_field.strftime('%Y-%m')
|
||||
for contract in self.contract_ids:
|
||||
multiplier = temp_wizard.get_multiplier(contract.cycle_dict)
|
||||
for rent_id in contract.breakdown_ids:
|
||||
temp_wizard.process_rent_record(
|
||||
contract, rent_id, date_field_year_month, multiplier)
|
||||
temp_wizard.create_deposit_list(contract)
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="contract_rental_wizard_form" model="ir.ui.view">
|
||||
<field name="name">指定合同租金生成</field>
|
||||
<field name="model">property.contract.rental.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="生成租金">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="select_month"/>
|
||||
<field name="select_year"/>
|
||||
<field name="contract_ids" invisible="1"/>
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button name="confirm" string="确认生成" type="object" class="oe_highlight"/>
|
||||
<button string="取消" class="btn-secondary" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
<record id="action_contract_rental_wizard" model="ir.actions.act_window">
|
||||
<field name="name">生成租金</field>
|
||||
<field name="res_model">property.contract.rental.wizard</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user