Merge pull request #1032 from expsa/property_security
Property security
This commit is contained in:
commit
62455a41d1
|
|
@ -84,7 +84,7 @@
|
|||
|
||||
<!-- Add server action to check from due date -->
|
||||
<record id="custom_action_server" model="ir.actions.server">
|
||||
<field name="name">Due Date Server Action</field>
|
||||
<field name="name">Due Date</field>
|
||||
<field name="model_id" ref="property_management.model_rent_payment"/>
|
||||
<field name="binding_model_id" ref="property_management.model_rent_payment"/>
|
||||
<field name="binding_view_types">list</field>
|
||||
|
|
@ -94,7 +94,7 @@
|
|||
record.action_validate2()
|
||||
</field>
|
||||
</record>
|
||||
<record id="custom_invoice_action_server" model="ir.actions.server">
|
||||
<record id="custom_invoice_action_server" model="ir.actions.server">
|
||||
<field name="name">Create Commission Vendor Invoice</field>
|
||||
<field name="model_id" ref="property_management.model_rent_payment"/>
|
||||
<field name="binding_model_id" ref="property_management.model_rent_payment"/>
|
||||
|
|
@ -105,6 +105,18 @@
|
|||
record.create_vendor_bill_for_payments()
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="custom_create_invoice_action_server" model="ir.actions.server">
|
||||
<field name="name">Create Commission Vendor Invoice</field>
|
||||
<field name="model_id" ref="property_management.model_rent_payment"/>
|
||||
<field name="binding_model_id" ref="property_management.model_rent_payment"/>
|
||||
<field name="binding_view_types">list</field>
|
||||
<field name="state">code</field>
|
||||
<field name="code">
|
||||
for record in records:
|
||||
record.action_invoice()
|
||||
</field>
|
||||
</record>
|
||||
<!-- End -->
|
||||
</data>
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -12,10 +12,16 @@
|
|||
type="object"/>
|
||||
<button name="action_done" string="Done"
|
||||
states="check"
|
||||
groups="property_management.group_property_manager"
|
||||
type="object"/>
|
||||
<button name="action_cancel" string="Cancel"
|
||||
states="draft"
|
||||
type="object"/>
|
||||
type="object"
|
||||
groups="property_management.group_property_manager"/>
|
||||
<button name="action_draft" string="RE-set To Draft"
|
||||
states="check,cancel"
|
||||
type="object"
|
||||
groups="property_management.group_property_manager"/>
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<sheet>
|
||||
|
|
@ -154,10 +160,19 @@
|
|||
type="object"/>
|
||||
<button name="action_done" string="Done"
|
||||
states="submit"
|
||||
groups="property_management.group_property_manager"
|
||||
type="object"/>
|
||||
|
||||
<button name="action_cancel" string="Cancel"
|
||||
states="draft"
|
||||
groups="property_management.group_property_manager"
|
||||
states="draft,submit"
|
||||
type="object"/>
|
||||
|
||||
<button name="action_rest_draft" string="RE-SET To Draft"
|
||||
groups="property_management.group_property_manager"
|
||||
states="cancel,submit"
|
||||
type="object"/>
|
||||
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<sheet>
|
||||
|
|
@ -185,8 +200,8 @@
|
|||
<group>
|
||||
<field name="vendor_id" attrs="{'invisible':[('renter_invoice', '=', True)],
|
||||
'required':[('renter_invoice', '=', False)], 'readonly':[('state','!=','draft')]}"/>
|
||||
<field name="maintenance_cost" invisible="1" readonly="1"/>
|
||||
<field name="hand_cost" invisible="1" readonly="1"/>
|
||||
<field name="maintenance_cost" invisible="0" readonly="1"/>
|
||||
<field name="hand_cost" invisible="0" readonly="1"/>
|
||||
<field name="total_amount" readonly="1"/>
|
||||
<field name="company_id" readonly="1"/>
|
||||
<field name="user_id" readonly="1"/>
|
||||
|
|
|
|||
|
|
@ -16,8 +16,11 @@
|
|||
<span class="o_form_label">Property Commission Settings</span>
|
||||
<div class="text-muted">Commission Settings.</div>
|
||||
<div class="text-muted content-group mt16">
|
||||
<label for="commission_percentage">Commission Percentage:</label>
|
||||
<field class="text-left oe_inline" name="commission_percentage" widget="percentage"/><br/>
|
||||
<label for="commission_account_id">Commission Account:</label>
|
||||
<field class="text-left oe_inline" name="commission_account_id"/><br/>
|
||||
<label for="collecting_company_id">Collecting Company:</label>
|
||||
<field class="text-left oe_inline" name="collecting_company_id"/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -42,15 +42,22 @@
|
|||
type="object"/>
|
||||
<button name="action_confirm" string="Confirm"
|
||||
states="review"
|
||||
groups="property_management.group_property_manager"
|
||||
type="object"/>
|
||||
<button name="action_renew" string="Renew Contract" type="object"
|
||||
confirm="Are you sure to renew the contract? That is mean you will renew this contract and create new draft one"
|
||||
class="oe_highlight"
|
||||
states="confirm"
|
||||
groups="property_management.group_property_manager"
|
||||
/>
|
||||
<button name="action_cancel" string="Cancel"
|
||||
states="draft,submit"
|
||||
type="object"/>
|
||||
states="draft,submit,review"
|
||||
type="object" groups="property_management.group_property_manager"/>
|
||||
|
||||
<button name="action_draft" string="RE-set To Draft"
|
||||
states="submit,review,cancel"
|
||||
type="object" groups="property_management.group_property_manager"/>
|
||||
|
||||
<field name="state" widget="statusbar"
|
||||
statusbar_visible="draft,submit,confirm,review,close,cancel"/>
|
||||
</header>
|
||||
|
|
|
|||
|
|
@ -17,10 +17,10 @@
|
|||
/>
|
||||
|
||||
|
||||
<button name="action_reset" string="Set To Draft" type="object" states="submit,cancel"
|
||||
<button name="action_reset" groups="property_management.group_property_manager" string="Set To Draft" type="object" states="submit,review,cancel"
|
||||
/>
|
||||
|
||||
<button name="action_cancel" string="Cancel" type="object" states="submit,review,draft"
|
||||
<button name="action_cancel" groups="property_management.group_property_manager" string="Cancel" type="object" states="submit,review,draft"
|
||||
/>
|
||||
|
||||
<field name="state" widget="statusbar"/>
|
||||
|
|
@ -108,4 +108,4 @@
|
|||
|
||||
|
||||
|
||||
</odoo>
|
||||
</odoo>
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@
|
|||
<menuitem name="Configuration"
|
||||
id="property_management_conf"
|
||||
parent="property_management_main_menu"
|
||||
sequence="3"
|
||||
sequence="3"
|
||||
groups="property_management.group_property_manager"
|
||||
/>
|
||||
|
||||
<menuitem name="Report"
|
||||
|
|
|
|||
Loading…
Reference in New Issue