Update rent_payment.py
This commit is contained in:
parent
067a21ecb6
commit
e2f3edd5de
|
|
@ -199,6 +199,32 @@ class RentPayment(models.Model):
|
|||
elif self.state == 'due':
|
||||
raise exceptions.ValidationError(_('Cannot Cancel This Payment Because it Due'))
|
||||
|
||||
def create_vendor_bill_for_payments(self):
|
||||
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)
|
||||
vendor_id = self.env['ir.config_parameter'].get_param('property_management.collecting_company_id')
|
||||
account_id = self.env['ir.config_parameter'].get_param('property_management.commission_account_id ')
|
||||
total_commission_amount = sum(payments_to_invoice.mapped('commission_amount'))
|
||||
today_date = datetime.today().strftime('%Y-%m-%d')
|
||||
name = (_('Commission for selected payments'))
|
||||
|
||||
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',
|
||||
'partner_id': vendor_id.id,
|
||||
'invoice_line_ids': [(0, 0, {
|
||||
'name': name+' - '+str(today_date),
|
||||
'quantity': 1,
|
||||
'price_unit': total_commission_amount,
|
||||
'account_id': account_id
|
||||
})],
|
||||
})
|
||||
|
||||
for payment in payments_to_invoice:
|
||||
payment.invoice_commission_id = vendor_bill.id
|
||||
|
||||
def action_validate2(self):
|
||||
for record in self:
|
||||
if record.contract_id.state == 'confirm':
|
||||
|
|
|
|||
Loading…
Reference in New Issue