diff --git a/odex25_realstate/property_management/data/ir_sequence_data.xml b/odex25_realstate/property_management/data/ir_sequence_data.xml index ab6ae24ad..073f94823 100644 --- a/odex25_realstate/property_management/data/ir_sequence_data.xml +++ b/odex25_realstate/property_management/data/ir_sequence_data.xml @@ -84,7 +84,7 @@ - Due Date Server Action + Due Date list @@ -94,7 +94,7 @@ record.action_validate2() - + Create Commission Vendor Invoice @@ -105,6 +105,18 @@ record.create_vendor_bill_for_payments() + + + Create Commission Vendor Invoice + + + list + code + + for record in records: + record.action_invoice() + + diff --git a/odex25_realstate/property_management/models/end_rental_contract.py b/odex25_realstate/property_management/models/end_rental_contract.py index 02a8564b1..66ba4d6f7 100644 --- a/odex25_realstate/property_management/models/end_rental_contract.py +++ b/odex25_realstate/property_management/models/end_rental_contract.py @@ -42,6 +42,7 @@ class EndOfRent(models.Model): invoice_id = fields.Many2one('account.move', string="Invoice") def _prepare_out_refund_invoice_values(self, end, amount): + self.contract_id.partner_id.property_account_receivable_id = end.contract_id.debit_account_id.id invoice_vals = { 'ref': end.name, 'move_type': 'out_refund', @@ -54,12 +55,19 @@ class EndOfRent(models.Model): 'name': end.name + ' - ' + str(end.date), 'price_unit': amount, 'quantity': 1.0, + 'account_id': end.contract_id.accrued_account_id.id, })], + 'line_ids': [(0, 0, {'account_id': end.contract_id.accrued_account_id.id, 'debit': 0.0, 'credit': amount, + 'name': end.name + ' - ' + str(end.date), + 'quantity': 1}), + (0, 0, + {'account_id': end.contract_id.debit_account_id.id, 'debit': amount, 'credit': 0.0, 'quantity': 1})] } return invoice_vals def _prepare_invoice_values(self, end, amount): + self.contract_id.partner_id.property_account_receivable_id = end.contract_id.revenue_account_id.id invoice_vals = { 'ref': end.name, 'move_type': 'out_invoice', @@ -74,6 +82,11 @@ class EndOfRent(models.Model): 'quantity': 1.0, })], + 'line_ids': [(0, 0, {'account_id': end.contract_id.debit_account_id.id, 'debit': 0.0, 'credit': amount, + 'name': end.name + ' - ' + str(end.date), + 'quantity': 1}), + (0, 0, + {'account_id': end.contract_id.revenue_account_id.id, 'debit': amount, 'credit': 0.0, 'quantity': 1})] } return invoice_vals @@ -81,6 +94,9 @@ class EndOfRent(models.Model): def get_remain_amount(self): for rec in self: rec.remain_amount = rec.insurance_amount - rec.total_amount + + def action_draft (self): + self.write({'state': 'draft'}) def action_cancel(self): if self.state not in ['check', 'done']: @@ -88,14 +104,34 @@ class EndOfRent(models.Model): def action_done(self): for rec in self: - if rec.remain_amount > 0.0: + if (rec.remain_amount > 0.0) or (rec.remain_amount > 0.0 and rec.maintenance): invoice_vals = rec._prepare_out_refund_invoice_values(rec, rec.remain_amount) invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid) + # Get the ID of the second line + line_id = invoice.invoice_line_ids[1].id + commands = [(2, line_id, 0)] + invoice.write({'invoice_line_ids': commands}) rec.invoice_id = invoice.id rec.write({'state': 'done'}) - elif rec.remain_amount < 0.0: + elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and not rec.maintenance: + rec.write({'state': 'done'}) + elif (rec.insurance_amount == 0.0 or rec.remain_amount==0.0) and rec.maintenance: invoice_vals = rec._prepare_invoice_values(rec, abs(rec.remain_amount)) invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid) + # Get the ID of the second line + line_id = invoice.invoice_line_ids[1].id + commands = [(2, line_id, 0)] + invoice.write({'invoice_line_ids': commands}) + rec.invoice_id = invoice.id + rec.write({'state': 'done'}) + + elif (rec.remain_amount < 0.0) or (rec.remain_amount<0.0 and rec.maintenance): + invoice_vals = rec._prepare_invoice_values(rec, abs(rec.remain_amount)) + invoice = self.env['account.move'].sudo().create(invoice_vals).with_user(self.env.uid) + # Get the ID of the second line + line_id = invoice.invoice_line_ids[1].id + commands = [(2, line_id, 0)] + invoice.write({'invoice_line_ids': commands}) rec.invoice_id = invoice.id rec.write({'state': 'done'}) if rec.contract_state == 'before': @@ -194,7 +230,7 @@ class PropertyManagementMaintenance(models.Model): contract_id = fields.Many2one('rental.contract', string="Contract") property_id = fields.Many2one('internal.property', string="Property") partner_id = fields.Many2one('res.partner', string="Partner",domain=[('is_tenant', '=', True)]) - vendor_id = fields.Many2one('res.partner', string="Vendor",domain=[('is_tenant', '=', True)]) + vendor_id = fields.Many2one('res.partner', string="Vendor") unit_ids = fields.Many2many('re.unit', string="Unit/Units") maintenance_cost = fields.Float(string="Maintenance Cost", compute="_get_total_amount", store=True) total_amount = fields.Float(string="Total Amount", compute="_get_total_amount", store=True) @@ -211,6 +247,10 @@ class PropertyManagementMaintenance(models.Model): invoice_id = fields.Many2one('account.move', string="Invoice") request_id = fields.Many2one('sale.order', string="Request Item") + def action_rest_draft(self): + rec.write({'state': 'draft'}) + + @api.onchange('renter_invoice') def rest_values(self): if self.partner_id: diff --git a/odex25_realstate/property_management/models/property_management_conf.py b/odex25_realstate/property_management/models/property_management_conf.py index a47ea261f..511ed1d6e 100644 --- a/odex25_realstate/property_management/models/property_management_conf.py +++ b/odex25_realstate/property_management/models/property_management_conf.py @@ -3,14 +3,6 @@ from odoo import models, fields, api, exceptions, tools, _ -class Company(models.Model): - _inherit = 'res.company' - - commission_percentage = fields.Float(string='Commission Percentage', help="The commission percentage.") - commission_account_id = fields.Many2one('account.account', string='Commission Account', help="The account used to record commissions.") - collecting_company_id = fields.Many2one('res.partner', string='Collecting Company', help="The company responsible for collecting the commission.") - - class ResConfigSettings(models.TransientModel): _inherit = 'res.config.settings' diff --git a/odex25_realstate/property_management/models/rent_payment.py b/odex25_realstate/property_management/models/rent_payment.py index b783a7f64..5ae370a4b 100644 --- a/odex25_realstate/property_management/models/rent_payment.py +++ b/odex25_realstate/property_management/models/rent_payment.py @@ -107,13 +107,13 @@ class RentPayment(models.Model): def _prepare_invoice_values(self, payment, amount): self.renter_id.property_account_receivable_id = payment.contract_id.debit_account_id.id + unit_name = self.unit_ids[0].name if self.unit_ids else '' # Check if unit_ids is not empty line_invoice=[] line_journal = [] if payment.amount>0.00: line_invoice.append((0, 0, { - 'name':'قيمة الإيجار '+' - '+payment.contract_id.name+'- '+self.property_id.name+' - '+self.unit_ids[0].name+' - ' + self.name + ' - ' + payment.code + ' - ' + str(payment.due_date), - 'price_unit': self.amount, + 'name': 'قيمة الإيجار ' + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'quantity': 1.0, 'account_id': payment.contract_id.revenue_account_id.id, 'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False, @@ -121,7 +121,7 @@ class RentPayment(models.Model): })) if payment.water_cost>0.00: line_invoice.append((0, 0, { - 'name': 'تكلفة المياه'+' -'+self.name + ' - '+payment.contract_id.name +' - ' +self.property_id.name+' - '+self.unit_ids[0].name+' - ' + payment.code + ' - ' + str(payment.due_date), + 'name': 'قيمة الإيجار ' + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'price_unit':self.water_cost, 'quantity': 1.0, 'account_id': payment.contract_id.revenue_account_id.id, @@ -130,7 +130,7 @@ class RentPayment(models.Model): }),) if payment.service_cost>0.00: line_invoice.append((0, 0, { - 'name':'قيمة الخدمات'+' - '+ self.name+' - '+payment.contract_id.name + ' - '+self.property_id.name+' - '+self.unit_ids[0].name+' - ' + payment.code + ' - ' + str(payment.due_date), + 'name': 'قيمة الإيجار ' + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'price_unit': self.service_cost, 'quantity': 1.0, 'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False, @@ -139,7 +139,7 @@ class RentPayment(models.Model): })) if payment.amount==0.00 and payment.service_cost==0.00 and payment.water_cost==0.00: line_invoice.append((0, 0, { - 'name':self.name + ' - ' +payment.contract_id.name + ' - '+self.property_id.name+' - '+self.unit_ids[0].name+' - '+payment.code + ' - ' + str(payment.due_date), + 'name': 'قيمة الإيجار ' + ' - ' + str(payment.contract_id.name or '') + ' - ' + str(self.property_id.name or '') + ' - ' + unit_name + ' - ' + str(self.name or '') + ' - ' + str(payment.code or '') + ' - ' + str(payment.due_date or ''), 'price_unit':self.total_amount, 'quantity': 1.0, 'analytic_account_id': payment.property_id.account_analy_id.id if payment.property_id.account_analy_id else False, @@ -203,7 +203,6 @@ class RentPayment(models.Model): def create_vendor_bill_for_payments(self): active_ids = self._context.get('active_ids', []) # action = self.env['rent.payment'].browse(context.get('active_ids', [])) - # payments_to_invoice = action.filtered(lambda p: p.state == 'paid' and p.collected_from_company and not p.invoice_commission_id) payments_to_invoice = self.env['rent.payment'].browse(active_ids).filtered( lambda p: p.state == 'paid' and p.collected_from_company and not p.invoice_commission_id) vendor_id = int(self.env['ir.config_parameter'].sudo().get_param('property_management.collecting_company_id')) @@ -212,11 +211,16 @@ class RentPayment(models.Model): today_date = datetime.today().strftime('%Y-%m-%d') name = (_('Commission for selected payments')) + # Ensure vendor and account are valid + if not vendor_id or not account_id: + raise UserError(_("Vendor or Account not configured properly in settings.")) + if not payments_to_invoice: raise UserError(_("No eligible payments selected. there are payment not valid conditions")) vendor_bill = self.env['account.move'].create({ 'move_type': 'in_invoice', + 'invoice_date': today_date, # Set the invoice date, 'partner_id': vendor_id, 'invoice_line_ids': [(0, 0, { 'name': name+' - '+str(today_date), diff --git a/odex25_realstate/property_management/models/rental_contract.py b/odex25_realstate/property_management/models/rental_contract.py index ee22e338a..74700a161 100644 --- a/odex25_realstate/property_management/models/rental_contract.py +++ b/odex25_realstate/property_management/models/rental_contract.py @@ -239,8 +239,8 @@ class RentalContract(models.Model): 'rent_type': self.rent_type.id, 'rent_amount': self.rent_amount, 'water_cost': self.water_cost, - 'services_cost': self.service_amount, - 'service_cost': self.service_cost, + 'service_amount': self.service_amount, # Correct field for service amount + 'service_cost': self.service_cost, # Correct field for service cost 'previous_contract_id': self.id, 'insurance_cost': self.insurance_cost, 'insurance_amount': self.insurance_amount, @@ -403,6 +403,8 @@ class RentalContract(models.Model): self.insurance_amount = (self.insurance_cost / 100.0) * self.cal_rent_amount elif self.insurance and self.insurance == 'fixed': self.insurance_amount = self.insurance_cost + def action_draft(self): + self.write({'state': 'draft'}) def action_cancel(self): if self.rent_payment_ids: diff --git a/odex25_realstate/property_management/views/end_rent_views.xml b/odex25_realstate/property_management/views/end_rent_views.xml index 083694e1c..1b14110ed 100644 --- a/odex25_realstate/property_management/views/end_rent_views.xml +++ b/odex25_realstate/property_management/views/end_rent_views.xml @@ -12,10 +12,16 @@ type="object"/>