Update rent_payment.py
This commit is contained in:
parent
dd2b1543f1
commit
158b1d6b2f
|
|
@ -29,7 +29,7 @@ class RentPayment(models.Model):
|
|||
user_id = fields.Many2one('res.users', string="Responsible")
|
||||
company_id = fields.Many2one('res.company', string="Company")
|
||||
due_date = fields.Date(string="Due Date")
|
||||
paid_date = fields.Date(string="Paid Date",related='invoice_id.payment_id.date')
|
||||
paid_date = fields.Date(string="Paid Date",)
|
||||
payment_method = fields.Selection([('check', 'Bank Check'),
|
||||
('cash', 'Cash'),
|
||||
('transfer', 'Transfer')], string="Payment Method", default='transfer')
|
||||
|
|
@ -57,7 +57,6 @@ class RentPayment(models.Model):
|
|||
for rec in self:
|
||||
if rec.invoice_id.payment_state in ['paid', 'in_payment']:
|
||||
rec.write({'state': 'paid'})
|
||||
|
||||
payment_obj = self.env['account.payment'].search([('ref','=',rec.invoice_id.name)],limit=1)
|
||||
rec.paid_date=payment_obj.date
|
||||
return res
|
||||
|
|
@ -77,46 +76,62 @@ 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
|
||||
line_invoice=[]
|
||||
line_journal = []
|
||||
|
||||
if payment.amount>0.00:
|
||||
print('go on....')
|
||||
line_invoice.append((0, 0, {
|
||||
'name':'قيمة الإيجار '+' - '+payment.contract_id.name+'- '+ self.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
|
||||
'price_unit': self.amount,
|
||||
'quantity': 1.0,
|
||||
'account_id': payment.contract_id.accrued_account_id.id,
|
||||
'account_id': payment.contract_id.revenue_account_id.id,
|
||||
}))
|
||||
if payment.water_cost>0.00:
|
||||
line_invoice.append((0, 0, {
|
||||
'name': 'تكلفة المياه'+' -'+self.name + ' - '+payment.contract_id.name +' - ' + payment.code + ' - ' + str(payment.due_date),
|
||||
'price_unit':self.water_cost,
|
||||
'quantity': 1.0,
|
||||
'account_id': payment.contract_id.accrued_account_id.id,
|
||||
'account_id': payment.contract_id.revenue_account_id.id,
|
||||
}),)
|
||||
if payment.service_cost>0.00:
|
||||
line_invoice.append((0, 0, {
|
||||
'name':'قيمة الخدمات'+' - '+ self.name+' - '+payment.contract_id.name + ' - ' + payment.code + ' - ' + str(payment.due_date),
|
||||
'price_unit': self.service_cost,
|
||||
'quantity': 1.0,
|
||||
'account_id': payment.contract_id.accrued_account_id.id,
|
||||
'account_id': payment.contract_id.revenue_account_id.id,
|
||||
}))
|
||||
if payment.amount==0.00 and payment.service_cost==0.00 and payment.water_cost==0.00:
|
||||
print('if 0000000')
|
||||
print(self.name)
|
||||
line_invoice.append((0, 0, {
|
||||
'name':self.name + ' - ' +payment.contract_id.name + ' - '+payment.code + ' - ' + str(payment.due_date),
|
||||
'price_unit':self.total_amount,
|
||||
'quantity': 1.0,
|
||||
'account_id': payment.contract_id.accrued_account_id.id,
|
||||
'account_id': payment.contract_id.revenue_account_id.id,
|
||||
}))
|
||||
|
||||
# line_journal.append((0, 0, {
|
||||
# 'account_id': payment.contract_id.revenue_account_id.id,
|
||||
# 'debit': 0.0,
|
||||
# 'credit': amount,
|
||||
# 'name': payment.contract_id.name + ' - ' + payment.contract_id.seq + ' - ' + str(payment.contract_id.date),
|
||||
# 'quantity': 1
|
||||
# }))
|
||||
# line_journal.append((0, 0, {
|
||||
# 'account_id': payment.contract_id.debit_account_id.id,
|
||||
# 'debit': amount,
|
||||
# 'credit': 0.0,
|
||||
# 'quantity': 1
|
||||
# }))
|
||||
|
||||
invoice_vals = {
|
||||
'ref': payment.name,
|
||||
'move_type': 'out_invoice',
|
||||
'invoice_origin': payment.code,
|
||||
'invoice_user_id': payment.user_id.id,
|
||||
'narration': payment.note,
|
||||
'partner_id': payment.contract_id.partner_id.id or payment.contract_id.renter_id.id,
|
||||
'partner_id': payment.contract_id.partner_id.id,
|
||||
'invoice_line_ids': line_invoice,
|
||||
|
||||
|
||||
|
|
@ -130,7 +145,6 @@ class RentPayment(models.Model):
|
|||
raise exceptions.ValidationError(_("Kindly, Contact Your Account Manager to set Income Account in contract account page"))
|
||||
invoice_vals = self._prepare_invoice_values(self, self.total_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)]
|
||||
|
|
|
|||
Loading…
Reference in New Issue